在某些文件上禁止特定checkstyle规则的正确语法是什么?

cri*_*nge 8 java checkstyle

我在我的java项目中使用Maven 3Checkstyle 2.9.1,我有一个常见的checkstyle配置,我们也在其他几个项目中使用它.为了避免将该配置文件复制和编辑到我自己的项目中,我使用了一个抑制文件来禁用某些包中的所有检查(生成的代码).

现在我想在所有文件中禁止特定规则.

这是我的抑制文件:

<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC "-//Puppy Crawl//DTD Suppressions 1.1//EN" "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
    <suppress files="my[\\/]generated[\\/]code[\\/]package" checks="."/>
    <suppress files=".*\\.java$" checks="IndentationCheck"/>
    <suppress files=".*\\.java$" checks="LineLengthCheck"/>
    <suppress files=".*\\.java$" checks="ExplicitInitializationCheck"/>
    <suppress files=".*\\.java$" checks="MemberNameCheck"/>
</suppressions>
Run Code Online (Sandbox Code Playgroud)

这是我的POM:

...
<build>
    ...
    <plugins>
    ...
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-checkstyle-plugin</artifactId>
            <version>2.9.1</version>
            <configuration>
                <configLocation>${checkstyle.ruleset}</configLocation>
                <suppressionsLocation>${checkstyle.suppressions}</suppressionsLocation>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

我正在打电话

mvn checkstyle:checkstyle
Run Code Online (Sandbox Code Playgroud)

生成报告,但被抑制的警告仍在那里.

我在这做错了什么?

cri*_*nge 12

好吧,我终于设法为我的checkstyle配置构建一个工作的抑制文件.

最初的问题是正则表达式,所以files=".*\\.java$"我现在files="."用来抑制对所有文件的特殊检查.我还禁止对某些文件进行所有检查.

以下是我的抑制文件中的一些示例:

<?xml version="1.0"?> suppressions PUBLIC "-//Puppy Crawl//DTD Suppressions 1.1//EN" "http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
<suppressions>
    <!-- suppress certain checks on all files in a package -->
    <suppress files="my[\\/]super[\\/]package[\\/]name" checks="ModifierOrderCheck|NeedBracesCheck|MagicNumberCheck"/>
    <!-- suppress all checks on all files in a package -->
    <suppress files="another[\\/]super[\\/]package[\\/]of[\\/]mine" checks=".*"/>
    <!-- suppress certain checks on all files -->
    <suppress files="." checks="IndentationCheck"/>
    <suppress files="." checks="LineLengthCheck"/>
    <suppress files="." checks="ExplicitInitializationCheck"/>
    <suppress files="." checks="MemberNameCheck"/>
    <suppress files="." checks="FinalClassCheck"/>
</suppressions>
Run Code Online (Sandbox Code Playgroud)

如果您需要有关配置的Maven部分的帮助,请参阅@Mawia 的答案.