SonarLint v1.19.0 for Visual Studio Code - Found 0 issue(s) even when they exist

I’m getting the SonarLint OUTPUT, it is Analyzing something, but the problem is that it only returns “Found 0 issue(s)” info.

It happens with every TS file, with some obvious problems, even with purposely written dirty code to test the SonarLint plugin.

I hope this is not a 100% duplicate, because I found some similar bug/not-working reports but non of the suggestions helped.

These are the program versions that I’m using:

  • OS: win32 x64 - Microsoft Windows 10 Pro (10.0.19042 Build 19042)
  • Visual Studio Code 1.52.1
  • Angular CLI: 11.0.7
  • Node: 14.15.4
  • JDK: jdk-15.0.1
  • JRE: jre1.8.0_271
  • SonarLint v1.19.0
  • typescript: “4.0.2”

Some solutions that I tried:

  • node executable in my $PATH
  • Update SonarLint binding to SonarQube/SonarCloud
  • explicitly set the path where the JRE is installed “sonarlint.ls.javaHome”: “C:\Program Files\Java\jre1.8.0_271” (it works because it detects the problem if I remove the folder even without this path)

I tried it on my work machine (similar settings) and it also reports Found 0 issue(s).

image

Here is the Output:

[Debug - 09:02:52.086] Queuing analysis of file 'file:///c:/Users/SKY/Documents/Angular/test-app/src/app/app.component.ts'
[Info  - 09:02:52.087] Analyzing file 'file:///c:/Users/SKY/Documents/Angular/test-app/src/app/app.component.ts'...
[Debug - 09:02:52.088] Analysis triggered on 'file:///c:/Users/SKY/Documents/Angular/test-app/src/app/app.component.ts' with configuration: 
[
    baseDir: c:\Users\SKY\Documents\Angular\test-app
    extraProperties: {}
    excludedRules: []
    includedRules: []
    ruleParameters: {}
    inputFiles: [
        file:///c:/Users/SKY/Documents/Angular/test-app/src/app/app.component.ts (UTF-8) [ts]
    ]
]
[Debug - 09:02:52.096] Start analysis
[Info  - 09:02:52.099] Index files 
[Debug - 09:02:52.099] Language of file 'file:///c:/Users/SKY/Documents/Angular/test-app/src/app/app.component.ts' is set to 'TypeScript'
[Info  - 09:02:52.100] 1 file indexed
[Debug - 09:02:52.110] 'JavaSquidSensor' skipped because there is no related file in current project
[Debug - 09:02:52.111] 'PHP sensor' skipped because there is no related file in current project
[Debug - 09:02:52.111] 'Analyzer for "php.ini" files' skipped because there is no related file 
[Debug - 09:02:52.111] 'Python Sensor' skipped because there is no related file in current project
[Debug - 09:02:52.111] Execute Sensor: JavaXmlSensor
[Debug - 09:02:52.112] Execute Sensor: HTML
[Debug - 09:02:52.112] Execute Sensor: TypeScript analysis
[Debug - 09:02:52.115] eslint-bridge server is up, no need to start.
[Debug - 09:02:52.119] initializing linter with sonar-no-fallthrough,new-operator-misuse,non-existent-operator,no-inverted-boolean-check,no-all-duplicated-branches,no-identical-conditions,no-small-switch,no-weak-cipher,file-uploads,xml-parser-xxe,default-param-last,no-global-this,no-delete-var,encryption-secure-mode,no-array-delete,no-alphabetical-sort,no-useless-intersection,no-unsafe-finally,prefer-while,no-sequences,no-unsafe-negation,max-switch-cases,no-octal,no-extra-semi,comma-or-logical-or-case,no-one-iteration-loop,label-position,no-multi-str,conditional-indentation,no-undefined-argument,function-inside-loop,no-use-of-empty-return-value,super-invocation,no-associative-arrays,use-isnan,no-weak-keys,no-try-promise,no-shadow,weak-ssl,no-duplicate-in-composite,generator-without-yield,no-useless-increment,no-same-line-conditional,no-ignored-return,no-duplicated-branches,no-redundant-parentheses,no-redundant-optional,call-argument-line,no-unenclosed-multiline-block,no-element-overwrite,no-equals-in-for-termination,no-sparse-arrays,post-message,bitwise-operators,no-identical-expressions,no-unreachable,no-useless-catch,no-redeclare,no-unthrown-error,no-globals-shadowing,unverified-hostname,unused-import,no-collection-size-mischeck,unverified-certificate,no-empty-collection,for-loop-increment-sign,no-accessor-field-mismatch,index-of-compare-to-positive-number,no-unused-collection,file-name-differ-from-class,no-primitive-wrappers,no-invariant-returns,no-case-label-in-switch,prefer-default-last,no-unnecessary-type-assertion,no-empty-pattern,no-gratuitous-expressions,insecure-jwt-token,no-dead-store,no-self-assign,no-misused-new,no-invalid-await,no-misleading-array-reverse,no-redundant-assignments,no-empty,no-unused-expressions
[Info  - 09:02:52.701] Found 2 tsconfig.json file(s): [c:\Users\SKY\Documents\Angular\test-app\e2e\tsconfig.json, c:\Users\SKY\Documents\Angular\test-app\tsconfig.json]
[Debug - 09:02:52.719] c:/Users/SKY/Documents/Angular/test-app/src/app/app.component.ts matched c:\Users\SKY\Documents\Angular\test-app\tsconfig.json
[Info  - 09:02:52.719] 1 source files to be analyzed
[Info  - 09:02:52.719] Analyzing 1 files using tsconfig: c:\Users\SKY\Documents\Angular\test-app\tsconfig.json
[Debug - 09:02:55.429] Initializing metadata of file file:///c:/Users/SKY/Documents/Angular/test-app/src/app/app.component.ts
[Info  - 09:02:55.432] 1/1 source files have been analyzed
[Info  - 09:02:55.441] Found 0 issue(s)

Hello, welcome to the community! And thank you for your report.

I don’t see anything obvious in the log you posted either :thinking:.

You mentioned that you updated the server bindings, are you using SonarLint in connected mode? With SonarCloud or a SonarQube server? If so, which rules are enabled in your quality profile?

Also, would it be possible for you to share some code / a sample project that reproduces the issue? I am suspecting that maybe something in the tsconfig.json is throwing the TypeScript analyzer off course.

Thank you for the response.

No, I’m not using SonarLint in connected mode I updated the server bindings just to try it as an option.

I’m trying to run the plugin over a project in my company. I can’t share that code, but it is a large project with million lines of code. The plugin is working, it is printing the output but it always returns Found 0 issue(s).

I created a new fresh Angular project and in that project, I copied some code from the SONARLINT RULES - TypeScript section (Noncompliant) code. The code is on stackblitz (app.component.ts):

Please check that code in an environment where you think that SonarLint will find the existing problems.

If there is a simple example of code that I can try in my VSCode please provide it and put a comment on what should be found as a problem by SonarLint so that I can test it.

Something that I noticed is the difference between the typescript versions, but these are all by default:

  • package.json “typescript”: “~4.0.2”
  • VSCode TypeScript: 4.1.2
  • SonarLint: TypeScript 3.8.3 OUTPUT Log from
    [Info - 11:20:06.389] Version of TypeScript used during analysis: 3.8.3

This is the tsconfig.json in my project:

/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"module": "es2020",
"lib": [
  "es2018",
  "dom"
]
  },
"angularCompilerOptions": {
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}

Hello, thank you for the very detailed reproducer!

I managed to download it and open it in the latest VSCode (1.52.1) + SonarLint (1.19).

I had a look at app.component.ts and found a lot of Non compliant samples from our TS rule descriptions :slight_smile: so my guess is that you expect those to be flagged as such.

However, I see that the rules you are trying to trigger are not enabled by default in SonarLint, e.g:

  • Uses of == should be flagged by typescript:S1440
  • Uses of console.log should be flagged by typescript:S106
  • Uses of implicit arguments should be flagged by typescript:S3513
  • Uses of arguments.caller and arguments.callee should be flagged by typescript:S2685
  • Redundant use of await should be flagged by typescript:S4326

You can enable additional rules (and disable those that you don’t think are relevant to you) in the “SonarLint Rules” view in the explorer:

Alternatively, you can edit the sonarlint.rules user-level settings property. To enable the 5 rules mentioned above, you’d need the following:

{
  "sonarlint.rules": {
    "typescript:S1440": {
      "level": "on"
    },
    "typescript:S3513": {
      "level": "on"
    },
    "typescript:S2685": {
      "level": "on"
    },
    "typescript:S4326": {
      "level": "on"
    },
    "typescript:S106": {
      "level": "on"
    }
  }
}

Please note that this also allows you to pass parameters to some rules, e.g configure the maximum line length.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.