am having a class, which is giving me sonar issues. That is just a temporary class and I would ignore it in future sprints. How can I mark that particular class to be ignored from sonar analysis, as we have guidelines to commit code only if no sonar issues found.
-
doesn't seem like a good idea. if you shouldn't commit code with Sonar issues, you probably also shouldn't go around them and suppress – Line Oct 22 '20 at 10:38
2 Answers
Generally speaking you do have multiple options: (i assume you are using java, but there are equivalent solutions for other languages)
ignoring the whole class
There is a property called
sonar.exclusion
which you can set to ignore that specific class. This needs to be set either yoursonar-project.properties
or based on the scanner you are using. For details take a look hereignoring just some lines with issues
In the java world you can use line comments with
//NOSONAR <reason>
to exclude lines from detection. There are equivalents in other languages too.ignoring just some issues on the class/method
In Java you can use the
@SuppressWarnings("<rule id>")
to exclude issues from classes and methods for detection. see https://stackoverflow.com/a/30383335/3708208Define multiple ignore criteria for wildcard and rules
you can also define special settings in sonarqube, to ignore special files and folders via wildcard input, and which rules should be ignored. see https://stackoverflow.com/a/53639382/3708208

- 4,146
- 1
- 24
- 36
-
I would like to add that you can also include that in the `build.gradle` by doing `sonarqube { properties { property 'sonar.exclusions', '**/file_to_exclude.java' } }` – acarlstein Aug 04 '22 at 14:46
for those who use SonarLint plugin for IntelliJ Idea:
File > Settings > Tools > SonarLint > File Exclusions

- 1,529
- 3
- 18
- 42