41

I want to disable a rule from Sonar so it doesn't show the results in the web page. In my case I want to hide (or not capture) the results about trailing comments.

Is it posible to configure it somewhere?

Thanks.

maqjav
  • 2,310
  • 3
  • 23
  • 35

7 Answers7

47

The right way to do is to put something like this on sonar-project.properties file per project:

sonar.issue.ignore.multicriteria=e1,e2
# tab characters should not be used
sonar.issue.ignore.multicriteria.e1.ruleKey=squid:S00105
sonar.issue.ignore.multicriteria.e1.resourceKey=**/*.java
# right curly braces should be on a new line
sonar.issue.ignore.multicriteria.e2.ruleKey=squid:RightCurlyBraceStartLineCheck
sonar.issue.ignore.multicriteria.e2.resourceKey=**/*.java

There are docs here on how to ignore specific rules for specific files, which links to an example of how to search for specific rules, by language. This page on baeldung goes into additional detail better than the docs

Brad Parks
  • 66,836
  • 64
  • 257
  • 336
norbertas.gaulia
  • 2,033
  • 3
  • 18
  • 19
  • 3
    Where can you find documentation about this? – Jeremy Lindblom Jun 19 '17 at 20:29
  • 2
    In my project I had to add the configuration to `pom.xml` instead of creating a new `sonar-project.properties` file. Instructions here: https://stackoverflow.com/a/21825470/1079869 – Matias Kinnunen Jan 10 '18 at 19:09
  • What does e1,e2 refer to? I can't find anywhere in docs about what they are used for – Max Doung Apr 06 '19 at 05:27
  • @MaxDoung e1 and e2 don't refer to anything in the Sonar docs. They are keys used within the `sonar-project.properties` file to name the ignore rules. Any names can be chosen, as long as the file is consistent with itself. – mamacdon Sep 30 '19 at 11:51
  • 1
    Sonar discourages using this configuration btw, https://community.sonarsource.com/t/documentation-about-ignore-issues-seems-to-be-wrong-or-outdated/3353/2 "We recommend users to use the UI to configure this, for best experience. Consider the configuration via sonar-project.properties as an undocumented hack, not official supported that may or may not work reliably, use at your own risk." – Snowbldr Jul 20 '20 at 22:06
  • See the **Ignore Issues** section here: https://docs.sonarqube.org/latest/project-administration/narrowing-the-focus/#header-3 – jherax Jun 03 '21 at 02:01
  • Also here there is a good article about disabling rules: https://www.baeldung.com/sonar-exclude-violations#2-how-to-get-the-identifier – jherax Jun 03 '21 at 02:04
21

You have to remove this rule in the quality profile that you are using to analyse your project.

Please refer to the documentation that describes all this: Quality Profiles in Sonar.

Ryan
  • 3,127
  • 6
  • 32
  • 48
  • 2
    where is this quality profile?on localhost:9000,i am getting a profile and rules list but no option for disable a rule. – Ankit Gupta Dec 15 '14 at 11:48
  • @Ankit you need to login to see the Deactivation button – Derrick Oct 18 '16 at 07:49
  • how to disable those from .net project. I want to add that rule in dotsettings file. i have added rules which i dont want in dotsettings file. can you please help? – Sushil Mate Dec 15 '16 at 17:58
8

In web interface for particular rule just press Deactivate button:

enter image description here

cn007b
  • 16,596
  • 7
  • 59
  • 74
2

Adding to @Vladmir's answer in a new answer as I am not able to comment. You can not modify the built-in profiles. If you don't see the option of Deactivate, then copy the profile and set it as default. Now you will see the options to activate/deactivate. enter image description here

Danish
  • 73
  • 10
0

An additional note for people ending up on this thread. 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 it wont work. The language specific rules can be passed line arguments and thats why the "squid:S00105" 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

Here is the link to my answer: https://stackoverflow.com/a/60570763/1766402 on how to set it from UI.

Isaiah4110
  • 9,855
  • 1
  • 40
  • 56
0

You can't deactivate sonar way rules in a built-in profile. so you have to create your own profile by going to the Quality Profile section and choosing your desired language then click on the config icon the select copy with your favorite name and then you can change any rules in that

here

and then you can deactivate your considered rules

like this

Ali Ghafoori
  • 204
  • 1
  • 8
0

For Java, You can get sonarlint/sonarqube to ignore false-positives by just commenting //NOSONAR at the end of your code statement. As mentioned in my answer here

Sahil
  • 786
  • 5
  • 15