How to suppress warnings for code in class / method comments

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)

SonarQube : Enterprise Edition Version 7.9.1 (build 27448)
Scanner : sonar-scanner-cli-

  • what are you trying to achieve

The project I work on has pseudo code in class comments to show example usage.
Sonar reports “Remove the commented out code” issue for these.
What is the recommended way to suppress these issues?
The comment looks like this:

 *  @brief MyClass
 *  Usage is:
 *  @code
 *  Array<BaseClassObject> a;
 *  ... fill array with various derived class objs
 *  //  Removes the objects which satisfy equality operator
 *  DerivedClassObject *obj = getDerivedObj();
 *  a.removeIf(MyClass(obj))
 *  @endcode
class MyClass


either remove this rule - in Sonarqube 8.9 LTS it’s java:S125, in Sonarqube 7.9.1 it’s squid:Sxxx) -
from your quality profile or change it’s severity to have no impact through quality gate or use a SuppressWarnings annotation at class or method level.



note the curly braces when suppressing multiple rules.

If the “Track uses of “@SuppressWarnings” annotations” rule is activated in your
quality profile, the rule to suppress has to be part of the listOfWarnings whitelist.

Comma separated list of warnings that can be suppressed (example: unchecked, cast, boxing). An empty list means that no warning can be suppressed.

1 Like

Thanks for your reply. But the source code is C++.
So I will either use // NOSONAR or update the quality profile / quality gate.

OK, but allowing //NOSONAR ain’t no solution IMO , as it may / will be abused.
You should activate the “Track uses of “NOSONAR” comments” rule.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.