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.
listOfWarnings
Comma separated list of warnings that can be suppressed (example: unchecked, cast, boxing). An empty list means that no warning can be suppressed.