annotation to skip sonar analysis on a class

12.3k Views Asked by At

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.

2

There are 2 best solutions below

0
On

for those who use SonarLint plugin for IntelliJ Idea:

File > Settings > Tools > SonarLint > File Exclusions

1
On

Generally speaking you do have multiple options: (i assume you are using java, but there are equivalent solutions for other languages)

  1. 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 your sonar-project.properties or based on the scanner you are using. For details take a look here

  2. ignoring 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.

  3. 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/3708208

  4. Define 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