我想排除路径中带有软件包example
的java文件,例如:
com.mystuff.myapp.example.res.Account.java
和
com.mystuff.myapp.example.Account.java
除外,但
com.mystuff.myapp.some.other.package.Account.java
不是。
我尝试了很多变化
例如,我发现了
<suppress files="[\\/]example[\\/].*\.java$" checks=".*" />
不起作用,因为它只会排除example
的直接后代,而不是所有后代。
那么,如何排除所有后代呢?
答案 0 :(得分:0)
对于使用maven的情况-您还可以使用以下配置排除文件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<excludes>**/.java</excludes>
</configuration>
</plugin>
但是对于(如您在评论中提到的)正则表达式有效且只有大量checkstyle错误是您的问题的情况,那么请注意,您应该首先创建自己的checkstyle配置!
这将需要一些时间来阅读和理解每个选项,并根据自己的要求进行配置!
例如my(!)个人checkstyle-config.xml看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN" "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="severity" value="warning"/>
<module name="TreeWalker">
<module name="AnnotationLocation"/>
<!-- <module name="AnnotationOnSameLine"/> -->
<module name="AnnotationUseStyle"/>
<module name="MissingDeprecated"/>
<module name="MissingOverride"/>
<module name="PackageAnnotation"/>
<module name="SuppressWarnings"/>
<module name="SuppressWarningsHolder"/>
<!-- Block Checks -->
<module name="AvoidNestedBlocks">
<property name="severity" value="warning"/>
</module>
<module name="EmptyBlock">
<property name="severity" value="warning"/>
<property name="option" value="text"/>
</module>
<module name="EmptyCatchBlock"/>
<module name="LeftCurly">
<property name="severity" value="warning"/>
<property name="option" value="nl"/>
<property name="tokens" value="CLASS_DEF, CTOR_DEF, INTERFACE_DEF, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE, LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, METHOD_DEF"/>
</module>
<module name="NeedBraces">
<property name="severity" value="warning"/>
</module>
<module name="RightCurly">
<property name="severity" value="warning"/>
<property name="option" value="alone"/>
<property name="tokens" value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO"/>
</module>
<!-- Class Design -->
<module name="DesignForExtension"/>
<module name="FinalClass">
<property name="severity" value="warning"/>
</module>
<module name="HideUtilityClassConstructor">
<property name="severity" value="warning"/>
</module>
<module name="InnerTypeLast"/>
<module name="InterfaceIsType">
<property name="severity" value="warning"/>
</module>
<module name="MutableException"/>
<module name="OneTopLevelClass"/>
<module name="ThrowsCount"/>
<module name="VisibilityModifier">
<property name="severity" value="warning"/>
</module>
<!-- Coding -->
<!-- <module name="ArrayTrailingComma"/> -->
<!-- <module name="AvoidInlineConditionals"/> -->
<module name="CovariantEquals"/>
<module name="DeclarationOrder"/>
<module name="DefaultComesLast"/>
<module name="EmptyStatement">
<property name="severity" value="warning"/>
</module>
<module name="EqualsAvoidNull"/>
<module name="EqualsHashCode">
<property name="severity" value="warning"/>
</module>
<module name="ExplicitInitialization"/>
<module name="FallThrough"/>
<module name="FinalLocalVariable"/>
<module name="HiddenField">
<property name="severity" value="warning"/>
<property name="ignoreConstructorParameter" value="true"/>
<property name="ignoreSetter" value="true"/>
<property name="setterCanReturnItsClass" value="true"/>
</module>
<!-- TODO Enable later
<module name="IllegalCatch"/>
-->
<module name="IllegalInstantiation">
<property name="classes" value="java.lang.Boolean"/>
</module>
<module name="IllegalThrows"/>
<module name="IllegalToken"/>
<module name="IllegalTokenText"/>
<module name="IllegalType"/>
<module name="InnerAssignment">
<property name="severity" value="warning"/>
</module>
<!-- TODO Enable later
<module name="MagicNumber">
<property name="severity" value="warning"/>
</module>
-->
<!-- <module name="MissingCtor"/> -->
<module name="MissingSwitchDefault">
<property name="severity" value="warning"/>
</module>
<module name="ModifiedControlVariable"/>
<!-- TODO Enable later
<module name="MultipleStringLiterals"/>
-->
<module name="MultipleVariableDeclarations"/>
<module name="NestedForDepth">
<property name="max" value="3"/>
</module>
<module name="NestedIfDepth">
<property name="max" value="4"/>
</module>
<module name="NestedTryDepth">
<property name="max" value="2"/>
</module>
<module name="NoClone"/>
<module name="NoFinalizer"/>
<module name="OneStatementPerLine"/>
<module name="OverloadMethodsDeclarationOrder"/>
<module name="PackageDeclaration"/>
<module name="ParameterAssignment"/>
<!-- <module name="RequireThis"/> -->
<module name="ReturnCount">
<property name="max" value="7"/>
<!-- <property name="maxForVoid" value="2"/> -->
</module>
<module name="SimplifyBooleanExpression">
<property name="severity" value="warning"/>
</module>
<module name="SimplifyBooleanReturn">
<property name="severity" value="warning"/>
</module>
<module name="StringLiteralEquality"/>
<module name="SuperClone"/>
<module name="SuperFinalize"/>
<!-- <module name="UnnecessaryParentheses"/> -->
<module name="VariableDeclarationUsageDistance"/>
<!-- Imports -->
<module name="AvoidStarImport">
<property name="severity" value="warning"/>
</module>
<!-- <module name="AvoidStaticImport"/> -->
<!-- <module name="CustomImportOrder"/> -->
<module name="IllegalImport">
<property name="severity" value="warning"/>
</module>
<!-- <module name="ImportControl"/> -->
<!-- <module name="ImportOrder"/> -->
<module name="RedundantImport">
<property name="severity" value="warning"/>
</module>
<module name="UnusedImports">
<property name="severity" value="warning"/>
</module>
<!-- Javadoc Comments -->
<module name="AtclauseOrder"/>
<module name="JavadocMethod">
<property name="severity" value="warning"/>
</module>
<!-- <module name="JavadocParagraph"/> -->
<!-- <module name="JavadocStyle"/> -->
<!-- <module name="JavadocTagContinuationIndentation"/> -->
<module name="JavadocType">
<property name="severity" value="warning"/>
</module>
<module name="JavadocVariable">
<property name="severity" value="warning"/>
</module>
<module name="NonEmptyAtclauseDescription"/>
<module name="SingleLineJavadoc"/>
<module name="SummaryJavadocCheck"/>
<!-- <module name="WriteTag"/> -->
<!-- Metrics -->
<!-- <module name="BooleanExpressionComplexity"/> -->
<!-- <module name="ClassDataAbstractionCoupling"/> -->
<!-- <module name="ClassFanOutComplexity"/> -->
<!-- <module name="CyclomaticComplexity"/> -->
<!-- <module name="JavaNCSS"/> -->
<!-- <module name="NPathComplexity"/> -->
<!-- Miscellaneous -->
<module name="ArrayTypeStyle">
<property name="severity" value="warning"/>
</module>
<module name="AvoidEscapedUnicodeCharacters"/>
<module name="CommentsIndentation"/>
<!-- <module name="DescendantToken"/> -->
<module name="FinalParameters">
<property name="tokens" value="METHOD_DEF,CTOR_DEF,LITERAL_CATCH"/>
</module>
<!-- TODO
<module name="Indentation">
<property name="basicOffset" value="2"/>
<property name="braceAdjustment" value="1"/>
<property name="caseIndent" value="2"/>
<property name="throwsIndent" value="2"/>
<property name="arrayInitIndent" value="2"/>
<property name="lineWrappingIndentation" value="2"/>
</module>
-->
<module name="OuterTypeFilename"/>
<!--
<module name="TodoComment">
<property name="severity" value="warning"/>
</module>
-->
<!--
<module name="TrailingComment"/>
-->
<module name="UncommentedMain"/>
<module name="UpperEll">
<property name="severity" value="warning"/>
</module>
<!-- Modifiers -->
<module name="ModifierOrder">
<property name="severity" value="warning"/>
</module>
<module name="RedundantModifier">
<property name="severity" value="warning"/>
</module>
<!-- Naming Conventions -->
<!-- <module name="AbbreviationAsWordInName"/> -->
<module name="AbstractClassName"/>
<module name="CatchParameterName"/>
<module name="ClassTypeParameterName"/>
<module name="ConstantName">
<property name="severity" value="warning"/>
</module>
<module name="InterfaceTypeParameterName"/>
<module name="LocalFinalVariableName">
<property name="severity" value="warning"/>
</module>
<module name="LocalVariableName">
<property name="severity" value="warning"/>
</module>
<module name="MemberName">
<property name="severity" value="warning"/>
</module>
<module name="MethodName">
<property name="severity" value="warning"/>
</module>
<module name="MethodTypeParameterName"/>
<module name="PackageName">
<property name="severity" value="warning"/>
</module>
<module name="ParameterName">
<property name="severity" value="warning"/>
</module>
<module name="StaticVariableName">
<property name="severity" value="warning"/>
</module>
<module name="TypeName">
<property name="severity" value="warning"/>
</module>
<!-- Regexp -->
<!-- <module name="Regexp"/> -->
<!-- <module name="RegexpSinglelineJava"/> -->
<!-- Size Violations -->
<module name="AnonInnerLength">
<property name="max" value="100"/>
</module>
<!-- <module name="ExecutableStatementCount"/> -->
<module name="LineLength">
<property name="severity" value="warning"/>
<property name="max" value="999"/>
</module>
<module name="MethodCount">
<property name="maxTotal" value="110"/>
<property name="maxPublic" value="110"/>
</module>
<module name="MethodLength">
<property name="severity" value="warning"/>
<property name="max" value="260"/>
</module>
<module name="OuterTypeNumber"/>
<module name="ParameterNumber">
<property name="severity" value="warning"/>
<property name="max" value="9"/>
</module>
<!-- Whitespace -->
<module name="EmptyForInitializerPad"/>
<module name="EmptyForIteratorPad">
<property name="severity" value="warning"/>
</module>
<module name="EmptyLineSeparator">
<property name="allowMultipleEmptyLinesInsideClassMembers" value="false"/>
<property name="tokens" value="IMPORT, CLASS_DEF, INTERFACE_DEF, ENUM_DEF, STATIC_INIT, INSTANCE_INIT, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
</module>
<module name="GenericWhitespace"/>
<module name="MethodParamPad"/>
<module name="NoLineWrap">
<property name="tokens" value="IMPORT, PACKAGE_DEF"/> <!-- TODO , STATIC_IMPORT -->
</module>
<module name="NoWhitespaceAfter">
<property name="severity" value="warning"/>
<property name="tokens" value="ARRAY_INIT, INC, DEC, UNARY_MINUS, UNARY_PLUS, BNOT, LNOT, DOT, TYPECAST, ARRAY_DECLARATOR, INDEX_OP"/> <!-- TODO , AT, METHOD_REF -->
</module>
<module name="NoWhitespaceBefore">
<property name="severity" value="warning"/>
<property name="tokens" value="COMMA, SEMI, POST_INC, POST_DEC, DOT, GENERIC_START, GENERIC_END"/> <!-- TODO , ELLIPSIS, METHOD_REF -->
</module>
<module name="OperatorWrap">
<property name="severity" value="warning"/>
<property name="tokens" value=""/>
</module>
<module name="ParenPad">
<property name="severity" value="warning"/>
<property name="tokens" value="ANNOTATION, ANNOTATION_FIELD_DEF, CTOR_CALL, CTOR_DEF, ENUM_CONSTANT_DEF, EXPR, LITERAL_CATCH, LITERAL_DO, LITERAL_FOR, LITERAL_IF, LITERAL_NEW, LITERAL_SWITCH, LITERAL_SYNCHRONIZED, LITERAL_WHILE, METHOD_CALL, METHOD_DEF, QUESTION, RESOURCE_SPECIFICATION, SUPER_CTOR_CALL"/> <!-- TODO , LAMBDA, DOT -->
</module>
<module name="SeparatorWrap">
<property name="option" value="eol"/>
<property name="tokens" value=""/>
</module>
<!-- TODO
<module name="SingleSpaceSeparator"/>
-->
<module name="TypecastParenPad"/>
<module name="WhitespaceAfter">
<property name="severity" value="warning"/>
</module>
<module name="WhitespaceAround">
<property name="severity" value="warning"/>
<property name="tokens" value="ASSIGN,BAND,BAND_ASSIGN,BOR,BOR_ASSIGN,BSR,BSR_ASSIGN,BXOR,BXOR_ASSIGN,COLON,DIV,DIV_ASSIGN,DO_WHILE,EQUAL,GE,GT,LAMBDA,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>
</module>
<!-- Headers -->
<!--
<module name="Header">
<property name="header" value=" * Copyright (C) 2018 Tec Media Services GmbH. All rights reserved!"/>
<property name="fileExtensions" value="java"/>
</module>
-->
<module name="RegexpHeader">
<property name="header" value="^/\*\n \* Copyright \(C\) (\d\d\d\d)(-(\d\d\d\d))? Tec Media Services GmbH. All rights reserved!\n \*/$"/>
<property name="fileExtensions" value="java"/>
</module>
<!-- Javadocs -->
<!-- <module name="JavadocPackage"/> -->
<!-- Misc -->
<module name="NewlineAtEndOfFile">
<property name="lineSeparator" value="lf"/>
<property name="fileExtensions" value="java,xml,dtd,properties,txt"/>
</module>
<module name="Translation"/>
<module name="UniqueProperties"/>
<!-- Regexp -->
<!-- <module name="RegexpMultiline"/> -->
<!-- <module name="RegexpOnFilename"/> -->
<!-- <module name="RegexpSingleline"/> -->
<!-- Size violations -->
<module name="FileLength">
<property name="severity" value="warning"/>
<property name="max" value="20000"/>
</module>
<!-- Whitespace -->
<module name="FileTabCharacter">
<property name="severity" value="warning"/>
<property name="fileExtensions" value="java,xml,dtd"/>
</module>
</module>
最后但并非最不重要的一点是,不要忘记在IDE(例如Eclipse)中也使用您的个人配置-这样就不会在所有标准错误/警告中使用标准配置;-)