sonarqubesonarlintsonarlint-eclipse

SonarLint synchronization with SonarQube


I have read all of the threads about SonarLint not being in synch with SonarQube, but it's just not clicking.

I created a simple Maven project to test SonarLint & SonarQube. I added the sonar-maven-plugin to the project and then ran mvn sonar:sonar.

The project was uploaded to SonarQube. When I looked in SonarQube, I see that it shows squid:S2699 (junit test doesn't have an assertion) as a blocker.

However, in eclipse, there is no such issue shown by SonarLint.

I purposely chose this one as it's not a PMD/FindBugs/Checkstyle issue.

I have verified that squid:S2699 is active on the server. Obviously it is, because SonarQube displayed it.

There is only 1 Quality Profile: SonarWay.

Edit: I am in connected mode.

Does anyone have any idea why?

I am using:

Here are the screenshots as proof.

SonarLint screenshot

SonarQube screenshot


Solution

  • It seems your test file is not treated as a test file, but as a source file. I say this based on the kind of errors that are reported (remove unused variable) and the kind of errors that are not reported (no assertions). As you might know, different rules are applied to sources and tests.

    SonarLint decides whether a file is a test file or not based on the Test file regular expressions preference, which you can find in Window / Preferences / SonarLint. The default value is **/*Test.*,**/test/**/*, this seems to work well in a wide range of cases, and looking at your screenshot, it should work for yours too. So first of all verify this setting. If the value is different from the default, I suggest to change it back to the default as a sanity check. Then you can tweak the value according to your needs.

    It's also good to verify that my theory is correct about SonarLint treating the file as test instead of source, by inspecting the SonarLint Console:

    You should see output like this:

    [
      baseDir: ...
      workDir: ...
      extraProperties: ...
      inputFiles: [
        /path/to/your/test/SonarProofTest.java [test]
      ]
    ]
    

    The [test] at the end of the filename indicates the file is treated as a test file. If it's not there, then the file is treated as a source file.