How to disable sonar rules for specific files?

I have a project I'm working on, and some files violate some rules, but are not real problems and thus distract the noise. However, I do not want to disable these rules all over the world, and I would prefer not to mark them as false positives one after another.

Is there a way to disable sonar rules for specific files, and if so, how?

+14
source share
4 answers

Since SonarQube 4.0, you can define an exception exclusion pattern based on the rule pattern and file path pattern.

In previous versions, you can rely on the disconnect shutdown plugin .

+5
source

Based on Mithfindel's answer and dpk comment, this fixes the warning

System.out and System.err should not be used as registrars

of all classes in packages named log (or any subpackage of them), adding an ignore pattern for the squid:S106 rule:

enter image description here

A list of keys to all your rules go to your profile in the Quality Profiles section and select Download to get a CSV file containing all the rule keys.

I am using SonarQube version 4.1.1.

+5
source

You can annotate a class or method with SuppressWarnings.

Here is an example:

@ java.lang.SuppressWarnings ("Squid: S00111") squid: S00111 in this case is the identifier of the sonar problem. You can find this problem identifier from the Sonar ui website.

+2
source

Yes it is possible.

+1
source

All Articles