Checkstyle custom rule

1、找到本地eclipse所在工作目录{WorkSpace}

2、checkstyle rule的目录:{WorkSpace}\.metadata\.plugins\net.sf.eclipsecs.core

3、internal_config_xxxxx.xml  替换其中的内容如下(最好先新增一个自定义规则再替换,不要覆盖默认的规则)

Sample:

<?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”>

<!–
This configuration file was written by the eclipse-cs plugin configuration editor
–>
<!–
Checkstyle-Configuration: Cpus
Description: none
–>
<module name=”Checker”>
<property name=”severity” value=”warning”/>
<module name=”TreeWalker”>
<module name=”CyclomaticComplexity”>
<property name=”max” value=”20″/>
</module>
<module name=”MethodLength”>
<property name=”max” value=”100″/>
</module>
<module name=”TypeName”>
<message key=”name.invalidPattern” value=”Type name ”{0}” must match pattern ”{1}”.”/>
</module>
<module name=”ClassTypeParameterName”>
<property name=”format” value=”(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)”/>
<message key=”name.invalidPattern” value=”Class type name ”{0}” must match pattern ”{1}”.”/>
</module>
<module name=”MethodTypeParameterName”>
<property name=”format” value=”(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)”/>
<message key=”name.invalidPattern” value=”Method type name ”{0}” must match pattern ”{1}”.”/>
</module>
<module name=”AnnotationLocation”>
<property name=”tokens” value=”VARIABLE_DEF”/>
<property name=”allowSamelineMultipleAnnotations” value=”true”/>
</module>
<module name=”JavadocMethod”>
<property name=”allowMissingParamTags” value=”true”/>
<property name=”allowMissingThrowsTags” value=”true”/>
<property name=”allowMissingReturnTag” value=”true”/>
<property name=”suppressLoadErrors” value=”true”/>
</module>
<module name=”BooleanExpressionComplexity”>
<property name=”max” value=”4″/>
</module>
<module name=”JavaNCSS”/>
<module name=”LineLength”>
<property name=”max” value=”100″/>
<property name=”tabWidth” value=”4″/>
</module>
<module name=”Indentation”>
<property name=”severity” value=”ignore”/>
<metadata name=”net.sf.eclipsecs.core.lastEnabledSeverity” value=”inherit”/>
</module>
<module name=”LeftCurly”/>
<module name=”NoWhitespaceBefore”/>
<module name=”PackageName”>
<property name=”format” value=”^[a-z]+(\.[a-z_][a-z0-9_]*)*$”/>
</module>
<module name=”ConstantName”/>
<module name=”LocalVariableName”/>
<module name=”MemberName”/>
<module name=”MethodName”/>
<module name=”PackageDeclaration”/>
<module name=”OneStatementPerLine”/>
<module name=”AvoidStarImport”/>
<module name=”ArrayTypeStyle”/>
<module name=”FallThrough”/>
<module name=”JavadocType”/>
<module name=”WhitespaceAround”>
<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,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,RCURLY,SL,SLIST,SL_ASSIGN,SR,SR_ASSIGN,STAR,STAR_ASSIGN,TYPE_EXTENSION_AND,WILDCARD_TYPE”/>
<property name=”allowEmptyConstructors” value=”true”/>
<property name=”allowEmptyMethods” value=”true”/>
<property name=”allowEmptyTypes” value=”true”/>
<property name=”allowEmptyLoops” value=”true”/>
</module>
</module>
<module name=”FileLength”>
<property name=”max” value=”1000″/>
</module>
</module>

发表评论

电子邮件地址不会被公开。 必填项已用*标注