Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to ignore Sonar issue "common-java:InsufficientCommentDensity" for whole project?

Tags:

sonarqube

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

like image 711
Oleksandr Tarasenko Avatar asked Oct 19 '18 15:10

Oleksandr Tarasenko


People also ask

How do I ignore SonarQube rule?

The SonarQube JAVA Analyzer allows you to use the "@SuppressWarnings" annotation to disable a specific rule locally. It will allows you to disable issues on a single line, by placing the annotation directly above an instruction, or in an entire block, by placing it above a class or a method for instance.

How do you change rules in Sonar?

There are three ways to add coding rules to SonarQube: Writing a SonarQube plugin in Java that uses SonarQube APIs to add new rules. Adding XPath rules directly through the SonarQube web interface. Importing Generic Issue Reports generated by an independently run tool.


1 Answers

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.

like image 131
Isaiah4110 Avatar answered Jan 01 '23 09:01

Isaiah4110