How can you suppress checkstyle checks within a block of code only for specific rules? [duplicate]
Asked Answered
R

1

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.

Riendeau answered 14/4, 2010 at 18:44 Comment(1)
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.Riendeau
P
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
Promise answered 15/2, 2011 at 11:18 Comment(1)
That's the piece I couldn't grasp from the docs. ThanksRiendeau

© 2022 - 2024 — McMap. All rights reserved.