# How to suppress warnings for code in class / method comments

**URL:** <https://community.sonarsource.com/t/how-to-suppress-warnings-for-code-in-class-method-comments/52678>\
**Category:** SonarQube Server / Community Build\
**Tags:** cfamily\
**Created:** [November 5, 2021, 10:27am UTC](https://community.sonarsource.com/t/how-to-suppress-warnings-for-code-in-class-method-comments/52678 "2021-11-05T10:27:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![asuzith](https://avatars.discourse-cdn.com/v4/letter/a/ac91a4/32.png) [@asuzith](https://community.sonarsource.com/u/asuzith)\
**Post date:** [November 5, 2021, 10:27am UTC](https://community.sonarsource.com/t/how-to-suppress-warnings-for-code-in-class-method-comments/52678/1 "2021-11-05T10:27:33Z")

</div>

Must-share information (formatted with [Markdown](https://commonmark.org/help/)):

- 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-4.2.0.1873-linux**

- 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:

```auto
/**
 * @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
{
}

```

---

<div class="post-metadata">

**Author:** ![anon67236913](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@anon67236913](https://community.sonarsource.com/u/anon67236913)\
**Post date:** [November 5, 2021, 11:40am UTC](https://community.sonarsource.com/t/how-to-suppress-warnings-for-code-in-class-method-comments/52678/2 "2021-11-05T11:40:50Z")

</div>

Hi,

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.

Syntax

```auto
@SuppressWarnings("squid:UnusedPrivateMethod")
@SuppressWarnings({"squid:UnusedPrivateMethod","squid:Sxxx"})

```

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.

---

<div class="post-metadata">

**Author:** ![asuzith](https://avatars.discourse-cdn.com/v4/letter/a/ac91a4/32.png) [@asuzith](https://community.sonarsource.com/u/asuzith)\
**Post date:** [November 5, 2021, 11:53am UTC](https://community.sonarsource.com/t/how-to-suppress-warnings-for-code-in-class-method-comments/52678/3 "2021-11-05T11:53:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anon67236913](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@anon67236913](https://community.sonarsource.com/u/anon67236913)\
**Post date:** [November 5, 2021, 11:56am UTC](https://community.sonarsource.com/t/how-to-suppress-warnings-for-code-in-class-method-comments/52678/4 "2021-11-05T11:56:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/system/32/78532_2.png) [@system](https://community.sonarsource.com/u/system)\
**Post date:** [November 12, 2021, 11:57am UTC](https://community.sonarsource.com/t/how-to-suppress-warnings-for-code-in-class-method-comments/52678/5 "2021-11-12T11:57:18Z")

</div>

Closed on November 12, 2021, 11:57am UTC

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