SonarLint for eclipse doesn't show tips for some rules of Java language

Hi there,

Our company decide to use SonarQube and SonarLint, so I did some test on my machine. Now I am confusing why some built-in rules rules on SonarQube server doesn’t show tips by SonarLint even I connect my project to SonarQube server in eclipse. Below is an example.

App versions

  1. SonarQube: community edition 8.5.1
  2. SonarLint: version 5.5.1.xxx
  3. Eclipse: 4.17

Rule: Public types, methods and fields (API) should be documented with Javadoc (java:S1176)

According to this rule, we expect to show below noncompliant tip by SonarLint. But actually it is not. I also confirmed that in eclipse -> Preferences -> SonarLint -> Rules Configuration, this rule is checked, my test class is in a package matches .api..

  1. public MyClass() { // Noncompliant - missing documentation
  2.  this.status = DEFAULT_STATUS;
    
  3. }

Note that many of the built-in rules can work as expect.

So what’s the problem is?

Thanks
Yongcheng

Hi @zjqzfyc

There is maybe a confusion in the way rules configuration works in SonarLint. You have two options:

  1. Use connected mode with your SonarQube server. In this case SonarLint will download (and cache) rules configuration from the server, and use it for all bound projects. The settings in eclipse -> Preferences -> SonarLint -> Rules Configuration are totally ignored
  2. Don’t use connected mode. Here you are on your own, you have to configure rules in Eclipse preferences.

(Note that in the same workspace, you can have a mix of projects that are bound or not bound).

So the first thing is to tell us in which mode you are doing your tests.

If you are in connected mode, another common cause of question is that the local storage (where SonarLint stores information from the SonarQube server, like rules configuration) is not automatically updated. Each time you change something on the server (activate a new rule, or change a rule parameter) you have to “update the binding”. Open the “SonarLint Bindings” view in Eclipse, right click on your connection, and click “Update all projects bindings”.

I know the root cause. It is because these rules are default not activated. I shoud copy the built-in profile and activate them, then Update All Project Bindings from SonarLint.

I have another question, how to enable the checkstyle rules from SonarLint?
I’ve added checkstyle plugin to SonarQube plugins folder and I saw the checkstyle rules appears from SonarQube website “Rules” page. After I ran mvn sonar:sonar command, I could saw checkstyle Code Smells from SonarQube website. I hope SonarLint could show these Code Smells from eclipse code editor.

:+1:

You can’t. SonarLint is made for SonarSource analyzers. If really needed, there is already an Eclipse plugin to run checkstyle rules. But our analyzer should already have rules that cover most checkstyle rules (and if not, we would be happy to receive the feedback about missing rules).

Thanks a lot for your support. Wish you a happy life. :smile:

2 Likes

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