基于华为java编程规范的checkstyle.xml以及格式化模版,注释模版

checkstyle.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.2//EN" "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
 
<!-- Generated by RHY @will_awoke -->
 
<module name="Checker">	
	
	<property name="charset" value="UTF-8"/>   
	<property name="severity" value="warning"/>
	
	<!-- Checks for Size Violations.  --> 
	<!-- 检查文件的长度(行) default max=2000 --> 
	<module name="FileLength">         
     <property name="max" value="2500"/>        
  </module>  
  
  <!-- Checks that property files contain the same keys. --> 
  <!-- 检查**.properties配置文件 是否有相同的key
  <module name="Translation">         
  </module>   
  --> 
	
  <module name="TreeWalker">
    
    <!-- Checks for imports    -->               
    <!-- 必须导入类的完整路径,即不能使用*导入所需的类 -->  
    <module name="AvoidStarImport"/>  
    
    <!-- 检查是否从非法的包中导入了类 illegalPkgs: 定义非法的包名称-->  
    <module name="IllegalImport"/> <!-- defaults to sun.* packages -->  
    
    <!-- 检查是否导入了不必显示导入的类-->  
    <module name="RedundantImport"/>  
    
    <!-- 检查是否导入的包没有使用-->  
    <module name="UnusedImports"/>
    
    <!-- Checks for whitespace           
    <module name="EmptyForIteratorPad"/>
    <module name="MethodParamPad"/>
    <module name="NoWhitespaceAfter"/>
    <module name="NoWhitespaceBefore"/>
    <module name="OperatorWrap"/>
    <module name="ParenPad"/>
    <module name="TypecastParenPad"/>
    <module name="WhitespaceAfter"/>
    <module name="WhitespaceAround"/>
    -->
    
    <!-- 检查类和接口的javadoc 默认不检查author 和version tags       
      authorFormat: 检查author标签的格式
			versionFormat: 检查version标签的格式
			scope: 可以检查的类的范围,例如:public只能检查public修饰的类,private可以检查所有的类
			excludeScope: 不能检查的类的范围,例如:public,public的类将不被检查,但访问权限小于public的类仍然会检查,其他的权限以此类推
			tokens: 该属性适用的类型,例如:CLASS_DEF,INTERFACE_DEF -->
    <module name="JavadocType">  
    	<property name="authorFormat" value="\S"/>  
      <property name="scope" value="protected"/>        
      <property name="tokens" value="CLASS_DEF,INTERFACE_DEF"/>  
    </module>
    
    <!-- 检查方法的javadoc的注释
			scope: 可以检查的方法的范围,例如:public只能检查public修饰的方法,private可以检查所有的方法
			allowMissingParamTags: 是否忽略对参数注释的检查
			allowMissingThrowsTags: 是否忽略对throws注释的检查
			allowMissingReturnTag: 是否忽略对return注释的检查 -->
    <module name="JavadocMethod">  
    	<property name="scope" value="private"/>  
      <property name="allowMissingParamTags" value="false"/>  
      <property name="allowMissingThrowsTags" value="false"/>  
      <property name="allowMissingReturnTag" value="false"/>  
      <property name="tokens" value="METHOD_DEF"/>  
      <property name="allowUndeclaredRTE" value="true"/>  
      <property name="allowThrowsTagsForSubclasses" value="true"/>  
      <!--允许get set 方法没有注释-->
 	    <property name="allowMissingPropertyJavadoc" value="true"/>
    </module>  
        
    <!-- 检查类变量的注释
			scope: 检查变量的范围,例如:public只能检查public修饰的变量,private可以检查所有的变量 -->    
    <module name="JavadocVariable">  
      <property name="scope" value="private"/>  
    </module>  
        
    <!--option: 定义左大括号'{'显示位置,eol在同一行显示,nl在下一行显示  
      maxLineLength: 大括号'{'所在行行最多容纳的字符数  
      tokens: 该属性适用的类型,例:CLASS_DEF,INTERFACE_DEF,METHOD_DEF,CTOR_DEF -->  
    <module name="LeftCurly"> 
    	<property name="option" value="nl"/>
    </module>
     
    <!-- NeedBraces 检查是否应该使用括号的地方没有加括号  
      tokens: 定义检查的类型 -->  
    <module name="NeedBraces"/>  
    
    <!-- Checks the placement of right curly braces ('}') for  else, try, and catch tokens. The policy to verify is specified using property  option.   
      option: 右大括号是否单独一行显示  
      tokens: 定义检查的类型  -->  
    <module name="RightCurly">    
    	<property name="option" value="alone"/> 	
    </module>
        
    <!-- 检查在重写了equals方法后是否重写了hashCode方法 --> 
    <module name="EqualsHashCode"/>
        
    <!--  Checks for illegal instantiations where a factory method is preferred.  
      Rationale: Depending on the project, for some classes it might be preferable to create instances through factory methods rather than calling the constructor.  
      A simple example is the java.lang.Boolean class. In order to save memory and CPU cycles, it is preferable to use the predefined constants TRUE and FALSE. Constructor invocations should be replaced by calls to Boolean.valueOf().  
      Some extremely performance sensitive projects may require the use of factory methods for other classes as well, to enforce the usage of number caches or object pools. -->  
    <module name="IllegalInstantiation">  
    	<property name="classes" value="java.lang.Boolean"/>  
    </module>
    
    <!-- Checks for Naming Conventions.   命名规范   -->
    <!-- local, final variables, including catch parameters -->
    <module name="LocalFinalVariableName"/>
    
    <!-- local, non-final variables, including catch parameters--> 
    <module name="LocalVariableName"/>
    
    <!-- static, non-final fields -->
    <module name="StaticVariableName">
    	<property name="format" value="(^[A-Z0-9_]{0,19}$)"/>    
    </module>  
    
    <!-- packages -->
    <module name="PackageName" >
    	<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
    </module> 
     
    <!-- classes and interfaces -->
    <module name="TypeName">  
    	<property name="format" value="(^[A-Z][a-zA-Z0-9]{0,19}$)"/> 	
    </module>
    
    <!-- methods -->  
    <module name="MethodName">          
      <property name="format" value="(^[a-z][a-zA-Z0-9]{0,19}$)"/>         
    </module> 
    
    <!-- non-static fields -->
    <module name="MemberName">  
    	<property name="format" value="(^[a-z][a-z0-9][a-zA-Z0-9]{0,19}$)"/>         
    </module>
    
    <!-- parameters -->
    <module name="ParameterName">
    	<property name="format" value="(^[a-z][a-zA-Z0-9_]{0,19}$)"/>         
    </module>
    
    <!-- constants (static,  final fields) -->
    <module name="ConstantName"> 
    	<property name="format" value="(^[A-Z0-9_]{0,19}$)"/>      
    </module>
    
    <!-- 代码缩进   -->
    <module name="Indentation">        
    </module>
    
    <!-- Checks for redundant exceptions declared in throws clause such as duplicates, unchecked exceptions or subclasses of another declared exception. 
      检查是否抛出了多余的异常  
    <module name="RedundantThrows">
    	<property name="logLoadErrors" value="true"/>
    	<property name="suppressLoadErrors" value="true"/> 
    </module>
    --> 
    
     <!--  Checks for overly complicated boolean expressions. Currently finds code like  if (b == true), b || true, !false, etc.   
       检查boolean值是否冗余的地方  
       Rationale: Complex boolean logic makes code hard to understand and maintain. -->  
    <module name="SimplifyBooleanExpression"/>
    
    <!--  Checks for overly complicated boolean return statements. For example the following code  
       检查是否存在过度复杂的boolean返回值  
       if (valid())  
          return false;  
       else  
          return true;  
       could be written as  
          return !valid();  
       The Idea for this Check has been shamelessly stolen from the equivalent PMD rule. -->  
    <module name="SimplifyBooleanReturn"/>  
    
    <!-- Checks that a class which has only private constructors is declared as final.只有私有构造器的类必须声明为final-->  
    <module name="FinalClass"/>
    
     <!--  Make sure that utility classes (classes that contain only static methods or fields in their API) do not have a public constructor.  
       确保Utils类(只提供static方法和属性的类)没有public构造器。  
       Rationale: Instantiating utility classes does not make sense. Hence the constructors should either be private or (if you want to allow subclassing) protected. A common mistake is forgetting to hide the default constructor.  
       If you make the constructor protected you may want to consider the following constructor implementation technique to disallow instantiating subclasses:  
       public class StringUtils // not final to allow subclassing  
       {  
           protected StringUtils() {  
               throw new UnsupportedOperationException(); // prevents calls from subclass  
           }  
           public static int count(char c, String s) {  
               // ...  
           }  
       } 
    <module name="HideUtilityClassConstructor"/> 
    --> 
    
    <!--  Chec
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值