Frequently asked questions

SonarLint FAQ

Common

How to ask for help?

Please describe your issue with a maximum of details. We will likely ask you for:

  • your IDE flavor/version/OS. Exemple: Eclipse 2018-12 on MacOSX
  • SonarLint version
  • Are you using connected mode?
  • If you are using connected mode, what is the SonarQube server version (or say if it is SonarCloud)
  • If you are using connected mode, what are the installed analyzers. You can easily get a list by opening https://<SQ server>/api/plugins/installed in a Web browser.
  • The full stacktrace of the error, and logs with Verbose output and Analysis logs enabled. See IDE specific section to find how to get SonarLint logs.

Why are issues reported in SonarQube, but not in SonarLint connected mode?

  1. Third party analyzers are not executed in SonarLint
    Some issues may be reported in SonarQube by a third party analyzer (PMD, Checkstyle, ESLint, PyLint, …). SonarLint will only run rules from SonarSource analyzers including custom rules extending SonarSource analyzers. Third party analyzers usually have their own IDE integration.
  2. SonarSource analyzers usually don’t report issues on test files
    Each SonarLint flavor has its own way of detecting which file is considered as a test source (like unit test). Most rules are not executed on test sources. See IDE specific section to know how SonarLint decides if a file is a test or not.
  3. “Second level” issues are not reported in SonarLint (rule keys starting by common-xxx)
    Issues depending on computation of code coverage or duplications are not reported by SonarLint. They are not compatible with “on the fly” analysis. Finding duplications requires to analyze the entire project (including sibling modules). Collecting coverage requires to execute all tests with proper coverage engine configuration. This is currently outside SonarLint scope.

I have configured some SonarScanner properties. Are they applied to SonarLint?

No. Scanner properties you may have defined in sonar-project.properties, pom.xml, … (like sonar.sources, sonar.projectBasedir, …) only make sense in command line SonarScanner context. SonarLint tries to use IDE metadata to avoid other configuration. If you want to share some configuration between SonarScanners and SonarLint, like exclusions, or some analyzer properties, the best way is to use connected mode and to set the configuration in the SonarQube or SonarCloud UI.


SonarLint for Eclipse

How to get SonarLint for Eclipse logs?

  1. Open Eclipse Console view
  2. Open the SonarLint Console image
  3. Enable Verbose output and Analysis logs image
  4. Reproduce the issue (e.g. reopen the offending file)

Sometimes errors are not in the SonarLint console, but could be directly in Eclipse error logs.

  1. Open Eclipse Error Log view
  2. Look for an error event related to SonarLint
  3. Open event details to get the stacktrace image

How SonarLint for Eclipse decides if a file is a test?

There is a regular expression you can configure in SonarLint settings to specify which files should be considered as tests.image
Recent Eclipse versions added the concept of test sources (only for Java projects). When available, SonarLint will also rely on it (see the green icon for test folders).
image

In the end, if you want to know how a file was effectively classified by SonarLint, look at the SonarLint Console with Verbose output, and search for something like:

Starting analysis with configuration:
[
  baseDir: [...]
  workDir: [...]
  extraProperties: {sonar.java.target=1.8, [...]}
  inputFiles: [
    file:/home/julien/Prog/Projects/sonarlint-core/core/src/test/java/org/sonar/api/utils/log/SonarLintLoggerTest.java (UTF-8) [test]
  ]
]

and notice the [test] qualifier after the filename, to indicate SonarLint classified the file as test.


SonarLint for IntelliJ

How to get SonarLint for IntelliJ logs?

  1. Open the SonarLint tool window (View > Tool Windows > Sonarlint)
  2. Enable Verbose output and Analysis logs
  3. Reproduce the issue (e.g. reopen the offending file)

SonarLint for VS Code

How to get SonarLint for VSCode logs?

  1. Open the Output view
  2. Select the SonarLint output SonarLintVSCode-Console
  3. Reproduce the issue (e.g. reopen the offending file)

How SonarLint for VSCode decides if a file is a test?

This is based on the file path + name. There is a regexp that can be changed in SonarLint settings. Default value is {**/test/**,**/*test*,**/*Test*}

5 Likes