如何仅针对特定规则抑制代码块中的checkstyle检查? [英] How can you suppress checkstyle checks within a block of code only for specific rules?

查看:153
本文介绍了如何仅针对特定规则抑制代码块中的checkstyle检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

在关闭一段代码的Checkstyle时,是否存在仅抑制特定检查的语法。

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

所以不只是

// CHECKSTYLE:OFF

code

// CHECKSTYLE:ON

// CHECKSTYLE:OFF
code
// CHECKSTYLE:ON

您可能会遇到类似的情况

you could have something like

// CHECKSTYLE:OFF:RequireThis,

代码

// CHECKSTYLE:ON

// 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.

推荐答案

建议阅读 SuppressionCommentFilter (隐藏在位)中有很多示例。

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>

然后您可以使用以下命令关闭RequireThis检查代码块:

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

// CSOFF: RequireThis
... code
// CSON: RequireThis

这篇关于如何仅针对特定规则抑制代码块中的checkstyle检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆