gradle Checkstyle不工作:SuppressionCommentFilter不允许作为Checker中的子级

gijlo24d  于 2023-08-06  发布在  其他
关注(0)|答案(1)|浏览(137)

嘿,尝试使用checkstyle,我尝试使用下面的checkstyle配置:

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
        "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
        "https://www.puppycrawl.com/dtds/configuration_1_2.dtd">

<module name="Checker">
    <property name="basedir" value="${basedir}"/>
    <!-- Checks that a package.html file exists for each package.     -->
    <!-- See http://checkstyle.sf.net/config_javadoc.html#JavadocPackage -->
    <module name="JavadocPackage">
        <property name="allowLegacy" value="${checkstyle.legacypackagedocs}"
                  default="true" />
    </module>

    <!-- Checks whether files end with a new line.                        -->
    <!-- See http://checkstyle.sf.net/config_misc.html#NewlineAtEndOfFile -->
    <module name="NewlineAtEndOfFile"/>

    <!-- Allows the suppression of checkstyle event violations within a block. -->
    <!--  More here  http://checkstyle.sourceforge.net/config_filters.html#SuppressionCommentFilter -->
    <module name="SuppressionCommentFilter"/>

    <!-- Checks that property files contain the same keys.         -->
    <!-- See http://checkstyle.sf.net/config_misc.html#Translation -->
    <module name="Translation"/>

    <!-- Checks for Size Violations.                    -->
    <!-- See http://checkstyle.sf.net/config_sizes.html -->
    <module name="FileLength"/>

    <!-- Checks for whitespace                               -->
    <!-- See http://checkstyle.sf.net/config_whitespace.html -->
    <module name="FileTabCharacter"/>
    <module name="RegexpSingleline">
        <property name="format" value="\s+$"/>
        <property name="message" value="Line has trailing spaces."/>
    </module>

    <module name="SuppressionFilter">
        <property name="file" value="${checkstyle.suppression.filter}" />
    </module>

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

    <module name="SuppressWarningsFilter" />
    <module name="TreeWalker">
        <!-- Make comments available for the suppression comment filter. -->
        <module name="FileContentsHolder"/>
        <module name="SuppressWarningsHolder" />

        <!-- Checks for Javadoc comments.                     -->
        <!-- See http://checkstyle.sf.net/config_javadoc.html -->
        <module name="JavadocMethod">
            <property name="allowUndeclaredRTE" value="true" />
            <property name="scope" value="package" />
        </module>
        <module name="JavadocType">
            <property name="scope" value="package" />
        </module>
        <module name="JavadocStyle">
            <property name="checkFirstSentence" value="true" />
            <property name="checkEmptyJavadoc" value="true" />
        </module>

        <!-- Checks for Naming Conventions.                  -->
        <!-- See http://checkstyle.sf.net/config_naming.html -->
        <module name="ConstantName">
            <property name="format" value="^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$|^log$" />
        </module>
        <module name="LocalFinalVariableName"/>
        <module name="LocalVariableName"/>
        <module name="MemberName"/>
        <module name="MethodName"/>
        <module name="PackageName"/>
        <module name="ParameterName"/>
        <module name="StaticVariableName"/>
        <module name="TypeName"/>

        <!-- Checks for imports                              -->
        <!-- See http://checkstyle.sf.net/config_import.html -->
        <module name="AvoidStarImport"/>
        <module name="IllegalImport"/> <!-- defaults to sun.* packages -->
        <module name="RedundantImport"/>
        <module name="UnusedImports"/>

        <!-- Checks for Size Violations.                    -->
        <!-- See http://checkstyle.sf.net/config_sizes.html -->
        <module name="LineLength">
            <property name="max" value="${checkstyle.linelength}" default="150"/>
            <property name="ignorePattern" value="(^ *\** *\$Id\:)|(^(package|import) .*)"/>
        </module>
        <module name="MethodLength"/>
        <module name="ParameterNumber">
            <property name="max" value="9" />
        </module>
        <module name="ReturnCount">
            <property name="max" value="3" />
        </module>

        <!-- Checks for whitespace                               -->
        <!-- See http://checkstyle.sf.net/config_whitespace.html -->
        <module name="EmptyForIteratorPad"/>
        <module name="GenericWhitespace"/>
        <module name="MethodParamPad"/>
        <module name="NoWhitespaceAfter"/>
        <module name="NoWhitespaceBefore"/>
        <module name="OperatorWrap"/>
        <module name="ParenPad"/>
        <module name="TypecastParenPad"/>
        <module name="WhitespaceAfter">
            <property name="tokens" value="COMMA, SEMI" />
        </module>
        <!-- Enforce WhitespaceAround the usual tokens, except GENERIC_*. -->
        <module name="WhitespaceAround">
            <property
                    name="tokens"
                    value="ASSIGN, BAND, BAND_ASSIGN, BOR, BOR_ASSIGN, BSR,
                     BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN,
                     EQUAL, GE, GT, LAND, LCURLY, LE, LITERAL_ASSERT,
                     LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY,
                     LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
                     LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR,
                     LT, MINUS, MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL,
                     PLUS, PLUS_ASSIGN, QUESTION, RCURLY, SL, SLIST, SL_ASSIGN,
                     SR, SR_ASSIGN, STAR, STAR_ASSIGN, TYPE_EXTENSION_AND"/>
        </module>

        <!-- Modifier Checks                                    -->
        <!-- See http://checkstyle.sf.net/config_modifiers.html -->
        <module name="ModifierOrder"/>
        <module name="RedundantModifier"/>

        <!-- Checks for blocks. You know, those {}'s         -->
        <!-- See http://checkstyle.sf.net/config_blocks.html -->
        <module name="EmptyBlock"/>
        <module name="LeftCurly"/>
        <module name="NeedBraces"/>
        <module name="RightCurly"/>

        <!-- Checks for common coding problems               -->
        <!-- See http://checkstyle.sf.net/config_coding.html -->
        <module name="EmptyStatement"/>
        <module name="EqualsHashCode"/>
        <module name="HiddenField">
            <property name="ignoreSetter" value="true"/>
            <property name="ignoreConstructorParameter" value="true"/>
        </module>
        
        <module name="IllegalImport">
            <property name="illegalPkgs"
                      value="edu.emory.mathcs.backport,
         org.joda,
         sun, com.sun"/>
        </module>

        <module name="IllegalInstantiation"/>
        <module name="InnerAssignment"/>
        <module name="MagicNumber"/>
        <module name="MissingSwitchDefault"/>
        <module name="SimplifyBooleanExpression"/>
        <module name="SimplifyBooleanReturn"/>

        <!-- Checks for class design                         -->
        <!-- See http://checkstyle.sf.net/config_design.html -->
        <module name="FinalClass"/>
        <module name="HideUtilityClassConstructor"/>
        <module name="InterfaceIsType"/>
        <module name="VisibilityModifier">
            <property name="protectedAllowed" value="true" />
        </module>

        <!-- Miscellaneous other checks.                   -->
        <!-- See http://checkstyle.sf.net/config_misc.html -->
        <module name="ArrayTypeStyle"/>
        <module name="FinalParameters"/>
        <module name="TodoComment">
            <property name="severity" value="info"/>
        </module>
        <module name="UpperEll"/>

    </module>

</module>

字符串
我一直得到错误:Unable to create Root Module: config {MY_PATH}。当我使用./gradlew checkstyleMain -s时,我得到了异常:

Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: SuppressionCommentFilter is not allowed as a child in Checker
        at com.puppycrawl.tools.checkstyle.Checker.setupChild(Checker.java:496)
        at com.puppycrawl.tools.checkstyle.api.AutomaticBean.configure(AutomaticBean.java:201)
        at com.puppycrawl.tools.checkstyle.ant.CheckstyleAntTask.createRootModule(CheckstyleAntTask.java:424)
        ... 39 more


我检查了其他的答案,但总有什么东西坏了。我需要帮助

Gradle: 7.6.1
Kotlin: 1.7.10
Groovy: 3.0.13
Checkstyle: 8.45.1


下面是我的checkstyle插件定义:

checkstyle {
    toolVersion = "8.45.1"
    isIgnoreFailures = false
    sourceSets = listOf(the<SourceSetContainer>()["main"])
    configFile = file("checkstyle/checkstyle-rules.xml")

    val suppressionFile = file("checkstyle/checkstyle-suppressions.xml")
    configProperties["checkstyle.suppression.filter"] = suppressionFile
}

s8vozzvw

s8vozzvw1#

checkstyle 8.1版本之后的SuppressionCommentFilter不再是Checker的子项,而是TreeWalker
8.1的release notes中描述了这一重大更改
Here是更改的PR,以及如何使用example在较新版本中迁移SuppressionCommentFilter的建议:
SuppressWithNearbyCommentFilter -只需将配置部分移动到TreeWalker下(从Checker)。SuppressCommentFilter -不幸的是,我们通过此修复程序导致了SuppressCommentFilter 8.6版本的回归,升级是使用新的过滤器http://checkstyle.sourceforge.net/config_filters.html#SuppressWithPlainTextCommentFilter-只需重命名模块名称。SuppressCommentFilter变得有点不同Filter by functionality -变得只与java代码相关(不能再抑制注解中的违规)。

相关问题