How to permanently ignore a false positive in SonarQube rule violation
Asked Answered
N

1

6

How does a developer ( or for that matter any authorized user ) ignore a specific coding rule violation when Sonar throws it? Say a rule “Does not follow file naming convention ” pops up , is there a way I can declare it a false positive and click on some button which ensures that further instances of that coding rule violation are not displayed ?

If this is not possible, is there a document which explains how SonarQube applies rules to the code , so that I can manipulate the way it works to permanently dismiss a false positive . Thanks !

This question maybe an extension of the below question

In Sonar, how to prevent checking some rules in some packages?

Nicole answered 29/9, 2014 at 21:0 Comment(0)
R
9

There are 2 points in your question:

  • You detect that a rule has generated a false positive issue on your code?

    • You can flag this issue as "false positive" in the Web UI, it will then be ignored in the next analyses

    • If this is a real false positive, then it is even a good idea to come on the SonarQube user mailling list to discuss this so that we can create a JIRA ticket to fix this

  • You find that a rule always generates issues that are not relevant in your context?

    • Those issues are not false positive at all, they are just irrelevant on your project

    • To fix this, you just have to deactivate the rule in the quality profile that is used for your project

Robledo answered 30/9, 2014 at 8:38 Comment(5)
The second answer you gave answers my question . But can only the administrator do this ? Also , can I know how the software makes a comparison of the rules with the given code ? Is this encapsulated from the user , or is there a way the user can modify it in the installation files?Nicole
The user needs to have the "Administer Quality Profiles and Gates" permission, not necessarily the "System Admin" permission. And the rules are coded in Java, there's no way for you to modify this.Robledo
One last question , I imported my own rules for C and C ++ code into Sonar Runner. I want to provide a Web interface for a user to cancel a rule , if it is irrelevant to the project I am just double checking with you if you ve got what I am trying to ask. I want to know how my C code rules applies to the code ( or how the Sonar rule configuration system works) and is there a way I can manipulate it ?Nicole
I don't get your question, sorry. Please head to the user mailing list and write a comprehensive and detailed mail explaining your use case and your question. Thanks.Robledo
The first option works only for code at that branch, the moment I pull another branch from that I start getting the same issue. This is very annoying and SonarQube community should fix this.Hardfavored

© 2022 - 2024 — McMap. All rights reserved.