代码检查-checkstyle
<?xml version="1.0"?> <!DOCTYPE module PUBLIC "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN" "https://checkstyle.org/dtds/configuration_1_3.dtd"> <module name="Checker"> <property name="charset" value="UTF-8"/> <property name="severity" value="error"/> <property name="fileExtensions" value="java, properties, xml"/> <!-- 排除所有的'module-info.java'文件 --> <module name="BeforeExecutionExclusionFileFilter"> <property name="fileNamePattern" value="module\-info\.java$"/> </module> <!-- 检查文件是否以一个空行结束 --> <module name="NewlineAtEndOfFile"/> <!-- 检查文件是否有'TAB'字符 --> <module name="FileTabCharacter"> <property name="eachLine" value="true"/> </module> <!-- 检查每一行结尾是否有空格 --> <module name="RegexpSingleline"> <property name="format" value="\s+$"/> <property name="minimum" value="0"/> <property name="maximum" value="0"/> <property name="message" value="Line has trailing spaces."/> </module> <module name="LineLength"> <property name="fileExtensions" value="java"/> <property name="max" value="120"/> <property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/> </module> <!-- 检查单个Java源文件 --> <module name="TreeWalker"> <property name="tabWidth" value="4"/> <!-- Annotations --> <module name="AnnotationLocation"> <property name="id" value="AnnotationLocationMostCases"/> <property name="tokens" value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/> </module> <module name="AnnotationLocation"> <property name="id" value="AnnotationLocationVariables"/> <property name="tokens" value="VARIABLE_DEF"/> <property name="allowSamelineMultipleAnnotations" value="true"/> </module> <!-- Block Checks --> <!-- 检查是否有嵌套代码块 --> <module name="AvoidNestedBlocks"/> <!-- 检查是否有空代码块 --> <module name="EmptyBlock"/> <module name="EmptyCatchBlock"/> <!-- 检查左大括号位置 --> <module name="LeftCurly"/> <!-- 检查代码块是否缺失{} --> <module name="NeedBraces"/> <!-- 检查右大括号位置 --> <module name="RightCurly"/> <!-- Class Design --> <module name="FinalClass"/> <module name="InterfaceIsType"/> <module name="OneTopLevelClass"/> <module name="VisibilityModifier"/> <!-- Coding --> <module name="DeclarationOrder"/> <module name="DefaultComesLast"/> <module name="EmptyStatement"/> <module name="EqualsAvoidNull"/> <module name="FallThrough"/> <module name="MagicNumber"/> <module name="MissingSwitchDefault"/> <module name="MultipleVariableDeclarations"/> <module name="NoClone"/> <module name="NoFinalizer"/> <module name="OneStatementPerLine"/> <module name="OverloadMethodsDeclarationOrder"/> <module name="SimplifyBooleanExpression"/> <module name="SimplifyBooleanReturn"/> <!-- Imports --> <module name="AvoidStarImport"/> <module name="RedundantImport"/> <module name="UnusedImports"/> <!-- Javadoc Comments --> <!-- Metrics --> <!-- Misc --> <module name="ArrayTypeStyle"/> <module name="CommentsIndentation"/> <module name="Indentation"> <property name="lineWrappingIndentation" value="8"/> </module> <module name="OuterTypeFilename"/> <module name="TodoComment"> <property name="format" value="(TODO)|(FIXME)"/> </module> <module name="TrailingComment"/> <module name="UpperEll"/> <!-- Modifiers --> <module name="ModifierOrder"/> <module name="RedundantModifier"/> <!-- Naming Conventions --> <module name="AbstractClassName"/> <module name="CatchParameterName"/> <module name="ClassTypeParameterName"/> <module name="ConstantName"/> <module name="InterfaceTypeParameterName"/> <module name="LambdaParameterName"/> <module name="LocalFinalVariableName"/> <module name="LocalVariableName"/> <module name="MemberName"/> <module name="MethodName"> <property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/> </module> <module name="MethodTypeParameterName"/> <module name="PackageName"/> <module name="ParameterName"/> <module name="StaticVariableName"/> <module name="TypeName"/> <!-- Regexp --> <!-- Size Violations --> <!-- Whitespace --> <module name="EmptyLineSeparator"> <property name="allowNoEmptyLineBetweenFields" value="true"/> <property name="allowMultipleEmptyLinesInsideClassMembers" value="false"/> </module> <module name="GenericWhitespace"/> <module name="MethodParamPad"/> <module name="NoLineWrap"/> <module name="NoWhitespaceAfter"/> <module name="NoWhitespaceBefore"/> <module name="OperatorWrap"/> <module name="ParenPad"/> <module name="SeparatorWrap"> <property name="tokens" value="DOT"/> <property name="tokens" value="METHOD_REF"/> <property name="option" value="nl"/> </module> <module name="SeparatorWrap"> <property name="tokens" value="COMMA"/> <property name="tokens" value="ARRAY_DECLARATOR"/> <property name="tokens" value="ELLIPSIS"/> <property name="option" value="EOL"/> </module> <module name="SingleSpaceSeparator"/> <module name="TypecastParenPad"/> <module name="WhitespaceAfter"/> <module name="WhitespaceAround"/> </module> </module>