0

I'm trying to suppress specific checkstyle warnings in my code. The default way seems to be to wrap code in comments eg: // CHECKSTYLE:OFF ... // CHECKSTYLE:ON. At the very least I'd like to give a reason for which I found the follow post. I don't know where the configuration file would be when using sonar, can anyone help?

How can you suppress checkstyle checks within a block of code only for specific rules?

Recommend reading the documentation on SuppressionCommentFilter (it is buried at bit) for lots of examples.

An example of how to do configure the filter is:

<module name="SuppressionCommentFilter">
 <property name="offCommentFormat" value="CSOFF: ([w|]+)"/>
 <property name="onCommentFormat" value="CSON: ([w|]+)"/>
 <property name="checkFormat" value="$1"/>
</module>

You can then use the following to turn off the RequireThis check for a block of code:

// CSOFF: RequireThis
... code
// CSON: RequireThis
Community
  • 1
  • 1
Andrew Sumner
  • 793
  • 2
  • 12
  • 29

1 Answers1

0

Login to Sonar as admin, then go to "Settings" (link at top-right, next to your username), select the "Java" category, then the "CheckStyle" tab.

After that, enter the <module> section from your post above into the "Filters" textarea.

Luke Hutteman
  • 1,921
  • 13
  • 11