如何仅针对特定规则抑制代码块内的检查样式检查?

发布于 2024-08-29 02:09:41 字数 452 浏览 3 评论 0原文

可能的重复:
如何禁用特定的检查样式特定代码行的规则?

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

所以不仅仅是

// CHECKSTYLE:OFF
代码
// CHECKSTYLE:ON

你可以有类似的东西

// CHECKSTYLE:OFF:RequireThis,
代码
// CHECKSTYLE:ON

如果我们故意对样式进行例外处理,最好更清楚例外情况是什么。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小嗷兮 2024-09-05 02:09:41

建议阅读 SuppressionCommentFilter 上的文档(它被隐藏在位)以获取大量示例。

如何配置过滤器的示例如下:

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

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

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文