Skip to content

Commit

Permalink
Remove type-checking for Vue also on SL
Browse files Browse the repository at this point in the history
  • Loading branch information
vdiez committed Mar 18, 2024
1 parent 1d02d85 commit 58820cb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ void should_analyze_js_with_typed_rules_except_vue() throws IOException {
fileName = "file.vue";
content = Files.readString(TestUtils.projectDir("js-sonarlint-project").resolve(fileName));
issues = analyze(fileName, content);
assertThat(issues).extracting(Issue::getRuleKey).contains("javascript:S3504");
assertThat(issues).extracting(Issue::getRuleKey).containsExactly("javascript:S3504");
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion packages/jsts/src/builders/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export function buildSourceCode(input: JsTsAnalysisInput, language: JsTsLanguage
parser: vueFile ? parsers.typescript.parser : undefined,
};
const parser = vueFile ? parsers.vuejs : parsers.typescript;
if (getContext()?.sonarlint || !vueFile) {
if (!vueFile) {
options.programs = input.programId && [getProgramById(input.programId)];
options.project = input.tsConfigs;
}
Expand Down
40 changes: 13 additions & 27 deletions packages/jsts/tests/analysis/analyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,33 +123,7 @@ describe('analyzeJSTS', () => {
);
});

it('should analyze Vue.js code with type checks in SL', async () => {
setContext({
workDir: '/tmp/dir',
shouldUseTypeScriptParserForJS: true,
sonarlint: true,
bundles: [],
});

const rules = [
{ key: 'strings-comparison', configurations: [], fileTypeTarget: ['MAIN'] },
] as RuleConfig[];
initializeLinter(rules);
const filePath = path.join(__dirname, 'fixtures', 'vue_ts', 'file.vue');
const tsConfigs = [path.join(__dirname, 'fixtures', 'vue_ts', 'tsconfig.json')];
const language = 'ts';

const {
issues: [issue1],
} = analyzeJSTS(await jsTsInput({ filePath, tsConfigs }), language) as JsTsAnalysisOutput;
expect(issue1).toEqual(
expect.objectContaining({
ruleId: 'strings-comparison',
}),
);
});

it('should not analyze Vue.js with type checks in SQ/SC', async () => {
it('should not analyze Vue.js with type checks in SQ/SC nor SL', async () => {
const rules = [
{ key: 'strings-comparison', configurations: [], fileTypeTarget: ['MAIN'] },
] as RuleConfig[];
Expand All @@ -164,6 +138,18 @@ describe('analyzeJSTS', () => {
language,
) as JsTsAnalysisOutput;
expect(issues).toHaveLength(0);
setContext({
workDir: '/tmp/dir',
shouldUseTypeScriptParserForJS: true,
sonarlint: true,
bundles: [],
});

const { issues: issues_sl } = analyzeJSTS(
await jsTsInput({ filePath, tsConfigs }),
language,
) as JsTsAnalysisOutput;
expect(issues_sl).toHaveLength(0);
});

it('should analyze main files', async () => {
Expand Down

0 comments on commit 58820cb

Please sign in to comment.