开发者

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

开发者 https://www.devze.com 2022-12-27 10:43 出处:网络
This question already has answers here: Closed 10 years ago. Possible Duplicate: How to disable a particular checkstyle rule for a particular line of code?
This question already has answers here: Closed 10 years ago.

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 wha开发者_如何学运维t the exception case is.


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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号