6

I'm working on the project, where the developers are trying to write understandable code, so there is no sense to use comments in a lot of places. We have a SonarQube, which is used in other projects and we cannot configure it. All we can do is configuring Sonar in our project's POM file. SonarQube is complaining, that there are not comments in our code with the rule "common-java:InsufficientCommentDensity". I know, that we can ignore some rules using sonar.issue.ignore.multicriteria properties like

<sonar.issue.ignore.multicriteria>junit.assertions.include.messages</sonar.issue.ignore.multicriteria>
<sonar.issue.ignore.multicriteria.junit.assertions.include.messages.ruleKey>squid:S2698</sonar.issue.ignore.multicriteria.junit.assertions.include.messages.ruleKey>
<sonar.issue.ignore.multicriteria.junit.assertions.include.messages.resourceKey>**/*.java</sonar.issue.ignore.multicriteria.junit.assertions.include.messages.resourceKey>

but it's not working with "common-java:InsufficientCommentDensity" rule. Why? And is there a way to ignore this rule in our case?

SonarQube version is 6.7 (build 33306)

Sonar Maven Plugin version is 3.4.0.905

Oleksandr Tarasenko
  • 587
  • 1
  • 8
  • 16

1 Answers1

6

I tested this quite a lot and finally found that setting common rules (anything that starts with "common-xxxx") from scanner side (pom, command line etc) will be ignored and wont work. The language specific rules can be passed as command line arguments and thats why the "squid:S2698" rule is getting ignored correctly. Here is the issue link on the SonarQube JIRA board and it says that it "wont be fixed".

https://jira.sonarsource.com/browse/SONAR-8230

The only option for you is to set the issue exclusion from UI. Here are the steps to set it from U.

If this is a common rule that you want to ignore, then make sure you have admin rights to your project. On the project Dashboard you should see the administration tab:

enter image description here

  1. Click on Administration → General Settings

  2. Click on Analysis Scope on the left hand side

  3. Now set the below property:

enter image description here

Save and run the scan again.

Isaiah4110
  • 9,855
  • 1
  • 40
  • 56
  • For android project you can do this from the sonar.gradle file as well. https://stackoverflow.com/a/71553489/6209105 – Shaikh Mohib Mar 21 '22 at 06:33