【问题标题】:Checkstyle SuppressionCommentFilter not ignoring specified ruleCheckstyle SuppressionCommentFilter 不忽略指定规则
【发布时间】:2011-08-11 07:07:47
【问题描述】:

我有一个看起来像这样的 checkstyle.xml:

<module name="Checker">
    ....

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

    <module name="TreeWalker">
        <module name="LineLength">
            <property name="max" value="200"/>
        </module>
        ....
    </module>
</module>

在我的一堂课中,我有一行超过 200 个字符,并在其周围加上以下内容:

// CSOFF: LineLength
...
// CSON: LineLength

但是,作为 checkstyle 的一部分,有问题的行不会被忽略。

我在 pom.xml 中指定了以下内容:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <configLocation>checkstyle.xml</configLocation>
            </configuration>
        </plugin>
    </plugins>
</build>

并执行:

mvn checkstyle:checkstyle

【问题讨论】:

  • 执行 mvn checkstyle:check checkstyle:checkstyle 会发生什么?

标签: java maven checkstyle


【解决方案1】:

您是否将 FileContentsHolder 配置为 documented

<module name="TreeWalker">
    ...
    <module name="FileContentsHolder"/>
    ...
</module>

【讨论】:

  • “记录的”链接不再(如果有的话)对“FileContentsHolder”有任何引用。
【解决方案2】:

这对我最近也不起作用,但自checkstyle 8.2以来接受的答案已经过时:

删除 FileContentsHolder 模块,因为 FileContents 对象可用于 TreeWalkerAudit 事件中 TreeWalker 上的过滤器。

但是version 8.6 添加了SuppressWithPlainTextCommentFilter

新的 Checker 过滤器 SuppressWithPlainTextCommentFilter 类似于 Treewalker 的 SuppressionCommentFilter。

我没有使用SuppressionCommentFilter,而是使用了上面的SuppressWithPlainTextCommentFilter,一切都开始工作了。

例子:

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

现在我可以了

public static final int lowerCaseConstant; // CSOFF: ConstantNameCheck
public final static int MultipleERRORS;; // CSOFF: ALL

【讨论】:

    猜你喜欢
    • 2010-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-03
    • 1970-01-01
    • 1970-01-01
    • 2020-10-27
    • 1970-01-01
    相关资源
    最近更新 更多