I\'ve got a project I\'m working on and some of the files violate some of the rules, but in ways that are not real issues, and are thus distracting noise. However, I don\'t
Yes, it is possible.
1.Goto Administration tab->Analysis Scope->Issues
2.There , you will find "Ignore Issues on Multiple Criteria".
3.Provide Rule ID in "Rule Key pattern" textbox [Rule ID can be found by clicking on the particular rule and find it in top right corner]
4.Provide Filepath for which you need to ignore rule in "File Path Pattern" textbox
5.Click on Save Issues settings
You can set specific files and rules under sonar-project.properties with following contents:
# Ignore Issues
sonar.issue.ignore.multicriteria=e1,e2
# Skip Bold Check
sonar.issue.ignore.multicriteria.e1.ruleKey=Web:BoldCheck
sonar.issue.ignore.multicriteria.e1.resourceKey=**/*.html
# Skip Tag Check
sonar.issue.ignore.multicriteria.e2.ruleKey=Web:S1234
sonar.issue.ignore.multicriteria.e2.resourceKey=**/*.html
Change the ruleKey and resourceKey based on your specific need.
Since SonarQube 4.0, you can define issue exclusion patterns based on rule key and file path pattern.
On previous versions, you can rely upon the Switch Off Violations plugin.
Building on Mithfindel's answer and dpk's comment, this removes the warning
System.out and System.err should not be used as loggers
from all classes in packages named log
(or any subpackage thereof) by adding an ignore pattern for the rule squid:S106
:
For a list of the keys to all your rules go to your profile under Quality Profiles and select Download to get a .csv file containing all the rules' keys.
I'm using SonarQube version 4.1.1.
You can annotate a class or a method with SuppressWarnings.
Here is an example:
@java.lang.SuppressWarnings("squid:S00111") squid:S00111 in this case is a Sonar issue ID. You can find this issue id from the Sonar web ui.
Using below annotation we can ignore the rule from the specific files
For one rule
@java.lang.SuppressWarnings("squid:S2696")
@Slf4j
@Service
public class PaymentServiceImpl implements PaymentService {....
For more than one rule
@java.lang.SuppressWarnings({"squid:S2696", "squid:S1172", "squid:CommentedOutCodeLine"})
@Slf4j
@Service
public class PaymentServiceImpl implements PaymentService {...