Checkstyle Check-ins configuration

Source: Internet
Author: User
Tags modifiers checkstyle

To define the Checkstyle configuration file according to your own needs, you need to understand the composition of the Checkstyle configuration file first. In the Code specification tool-checkstyle Manual, I mentioned the configuration files Sun_checks.xml and Sun_checks_eclipse.xml provided by two Checkstyle, so now look at the composition of these two files. The path to Sun_checks.xml and Sun_checks_eclipse.xml is: Unzip the Checkstyle installation package, and in the Extract directory, enter the plugins, Plugins directory has a net.sf.eclipsecs.core_5.5.0.201111092104 installation package, the installation package decompression, you can see Sun_checks.xml and Sun_checks_ Eclipse.xml these two configuration files. After opening these two profiles, we can probably see that they are virtually identical in structure, because sun_checks_eclipse.xml is equivalent to Sun_checks.xml's more restrictive version of spec, so we just need to look at Sun_ Checks.xml file can be.

1 Checkstyle Principle of inspection

Sun_checks.xml is composed of multiple module nodes, so you can see that the Checkstyle configuration is applied to the Java file by specifying modules. The modules is a tree structure with a module named checker as the root node, and the General Checker will include Treewalker child module. Distinguishing Module,module properties from the module's Name property in an XML configuration file controls how the module is executed, each property has a default value, and all check has a severity attribute. Use it to specify the level of the check.

Treewalker creates a syntax tree for each Java file and invokes submodules checks between nodes.

Some specific usages of the 2 standard checks

2.1 Javadoc Comments

L Javadocpackage

Check to see if there are any Java annotation files in each Java package, either by default to allow a Package-info.java, or by Allowlegacy property configuration to allow package.html.

L Javadoctype

Check the Javadoc for classes and interfaces. Default does not check author and version tags.

L Javadocmethod

Check the Javadoc of methods and constructors. The default does not check for unused exceptions thrown.

L javadocvariable

Check Javadoc for variables.

L Javadocstyle

Check the format of Javadoc. For example: Does the first line of Javadoc end with a period, Javadoc in addition to tags whether there is description, check Javadoc in the HTML format.

L Writetag

Outputs the tag in Javadoc.

2.2 Naming Conventions

L Abstractclassname

Check the abstract class name.

L Classtypeparametername

Check the parameter name of the class.

L Constantname

Check the constant name.

L Localfinalvariablename

Check the local final type variable name, including the catch parameters.

L Localvarablename

Check the local non final type variable names, including the catch parameters.

L MemberName

Check for non-static variables.

L MethodName

Check the method name.

L Methodtypeparametername

Check the parameter name of the method.

L PackageName

Check the package name.

L ParameterName

Check the name of the parameter.

L Staticvariablename

Check for static, non final type variable names.

L TypeName

Check the class name and interface name.

2.3 Imports

L Avoidstarimport

Check for import using *.

L Avoidstaticimport

Check for static import. For example, whether to import the contents of the Java.lang package.

L Illegalimport

Check to see if the illegal package has been import. Import all sun.* packages are rejected by default.

L Redundanimport

Check for duplicate import.

L Unusedimports

Check to see if there are any unused import.

L Importorder

Check the grouping and order of the import.

L Importcontrol

Controls the packages that can be import. In a larger project you can limit the use of too many Third-party packages, specified by a http://www.puppycrawl.com/dtds/import_control_1_0.dtd XML file.

2.4 Size violations

L Executablestatementcount

Limits the length of executable code fragments. The default is 30.

L Filelength

Check the length of the Java file. The default is 2000.

L LineLength

Check the length of the line of code. The default is 80.

L Methodlength

Check the length of methods and constructors. The default is 150.

L Anoninnerlength

Check the length of the anonymous inner class. The default is 20.

L Parameternumber

Check the number of arguments for methods and constructors. The default is 7.

2.5 whitespace

L Genericwhitespace

Check for gaps around < and >.

L Emptyforinitializerpad

Checks for whitespace in the null initialization location. For example, initialization in a for loop.

L Emptyforiteratorpad

Checks for whitespace in the empty iteration position.

L Methodparampad

Checks for white space before the method signature.

L Nowhitespaceafter

Check the whitespace after the separator.

L Nowhitespacebefore

Check the whitespace before the separator.

L Operatorwrap

Check the blank rule for the operator.

L Parenpad

Check for white-space rules for parentheses.

L Typecaseparenpad

Check for blank rules for forced-transition parentheses.

L Tabcharacter

Check for tab characters (' "T ').

L Whitespaceafter

Check that the separator is behind blank.

L Whitespacearound

Check for white space around the separator.

2.6 Modifierorder

L Modifierorder

Checks whether the modifiers are in the same order as the Java language specification.

L Redundantmodifier

Check that there are duplicate modifiers in the interface and annotation.

2.7 Block Checks

L Emptyblock

Check for empty code blocks.

L leftcurly

Check that the ' {' and left code blocks are on the same line.

L Needbraces

Check that curly braces are required. Mainly in the case of If,else.

L rightcurly

Check '} '.

L Avoidnestedblocks

Check for unwanted nesting ' {} '.

2.8 Coding

L Arraytrailingcomma

Checks whether array initialization ends with commas.

L Avoidinlineconditionals

Check the inline condition action.

L Covariantequals

Checks whether the class overrides Equals (Java.lang.Object).

L doublecheckedlocking

Check the DCL problem.

L Emptystatement

Check for empty code snippets.

L Equalsavoidnull

Checks whether a potentially null string is on the left side of the Equals () comparison.

L Equalshashcode

Checks whether the class overrides Equals () and hashcode ().

L finallocalvariable

Check whether the unchanged local variable is declared final.

L HiddenField

Checks whether a local variable or parameter hides a variable in the class.

L Illegalinstantiation

Check whether to use the factory method instantiation.

L Illegaltoken

Check for illegal separator characters.

L Illegaltokentext

Check the next character of the illegal separator.

L Innerassignment

Checks whether there is an assignment operation in the subexpression.

L MagicNumber

Check to see if there is a "magic numbers".

L Missingswitchdefault

Check to see if the switch statement has a default clause.

L modifiedcontrolvariable

Check whether the variable in the loop control is modified in the code block.

L Redundantthrows

Check for exceptions that have been repeatedly thrown.

L Simplifybooleanexpression

Check for overly complex Boolean expressions.

L

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.