7

Possible Duplicate:
How to disable a particular checkstyle rule for a particular line of code?

In turning off Checkstyle for a segment of code, is there a syntax that would suppress only specific checks.

So rather than just

// CHECKSTYLE:OFF
code
// CHECKSTYLE:ON

you could have something like

// CHECKSTYLE:OFF:RequireThis,
code
// CHECKSTYLE:ON

In cases where we are purposely making an exception to the style, it would be nice to be clearer what the exception case is.

CalvT
  • 3,123
  • 6
  • 37
  • 54
Daniel Holmes
  • 342
  • 1
  • 2
  • 13
  • Does marking a question as a duplicate not allow for posting a link to the supposed duplicate question? I would think that would be valuable information to the existing question asker who didn't find that other question when searching and to anyone else which finds this version and has the same problem. – Daniel Holmes Jun 16 '17 at 18:30

1 Answers1

8

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
stkent
  • 19,772
  • 14
  • 85
  • 111
Oliver
  • 639
  • 5
  • 9