1

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.

anurag1007
  • 107
  • 1
  • 10
  • 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 Answers2

2

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

Simon Schrottner
  • 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
0

for those who use SonarLint plugin for IntelliJ Idea:

File > Settings > Tools > SonarLint > File Exclusions

Line
  • 1,529
  • 3
  • 18
  • 42