Miscellaneous Checks |
![]() |
GenericIllegalRegexpDescriptionA generic check for code problems - the user can search for any pattern. This is similar to a recursive grep, only that it's integrated in checkstyle. Rationale: This check can be used to prototype checks and to find common bad practice such as calling ex.printStacktrace(), System.out.println(), System.exit(), etc. Properties
ExamplesTo configure the check for calls to System.out.println: <module name="GenericIllegalRegexp"> <!-- . matches any character, so we need to escape it and use \. to match dots. --> <property name="format" value="System\.out\.println"/> </module> To configure the check to find trailing whitespace at the end of a line: <module name="GenericIllegalRegexp"> <!-- \s matches whitespace character, $ matches end of line. --> <property name="format" value="\s$"/> </module> To configure the check to find case-insensitive occurrences of "debug": <module name="GenericIllegalRegexp"> <property name="format" value="debug"/> <property name="ignoreCase" value="true"/> </module> Packagecom.puppycrawl.tools.checkstyle.checks Parent ModuleNewlineAtEndOfFileDescriptionChecks whether files end with a new line. Rationale: Any source files and text files in general should end with a newline character, especially when using SCM systems such as CVS. CVS will even print a warning when it encounters a file that doesn't end with a newline. Properties
ExamplesTo configure the check: <module name="NewlineAtEndOfFile"/> To configure the check to always use Unix-style line separators: <module name="NewlineAtEndOfFile"> <property name="lineSeparator" value="lf"/> </module> Packagecom.puppycrawl.tools.checkstyle.checks Parent ModuleTodoCommentDescriptionA check for TODO: comments. Actually it is a generic regular expression matcher on Java comments. To check for other patterns in Java comments, set property format. Properties
NotesUsing TODO: comments is a great way to keep track of tasks that need to be done. Having them reported by Checkstyle makes it very hard to forget about them. ExamplesTo configure the check: <module name="TodoComment"/> To configure the check for comments that contain WARNING: <module name="TodoComment"> <property name="format" value="WARNING"/> </module> Packagecom.puppycrawl.tools.checkstyle.checks Parent ModuleTranslationDescriptionA FileSetCheck that ensures the correct translation of code by checking property files for consistency regarding their keys. Two property files describing one and the same context are consistent if they contain the same keys. Consider the following properties file in the same directory: #messages.properties hello=Hello cancel=Cancel #messages_de.properties hell=Hallo ok=OK The Translation check will find the typo in the german hello key, the missing ok key in the default resource file and the missing cancel key in the german resource file: messages_de.properties: Key 'hello' missing. messages_de.properties: Key 'cancel' missing. messages.properties: Key 'hell' missing. messages.properties: Key 'ok' missing. Properties
ExampleTo configure the check: <module name="Translation"/> Packagecom.puppycrawl.tools.checkstyle.checks Parent ModuleUncommentedMainDescriptionChecks for uncommented main() methods (debugging leftovers). Rationale: main() method can be often used for debug puposes. Thus most of main() method should be removed/commented out of the sources. Properties
ExamplesTo configure the check: <module name="UncommentedMain"/> To configure the check to allow main method for all classes with "Main" name: <module name="UncommentedMain"> <property name="excludedClasses" value="\.Main$"/> </module> Packagecom.puppycrawl.tools.checkstyle.checks Parent ModuleUpperEllDescriptionChecks that long constants are defined with an upper ell. That is ' L' and not 'l'. This is in accordance to the Java Language Specification, Section 3.10.1. Rationale: The letter l looks a lot like 1. ExamplesTo configure the check: <module name="UpperEll"/> Packagecom.puppycrawl.tools.checkstyle.checks Parent ModuleArrayTypeStyleDescription
Checks the style of array type definitions.
Some like Java-style: Properties
ExamplesTo configure the check to enforce Java style: <module name="ArrayTypeStyle"/> To configure the check to enforce C style: <module name="ArrayTypeStyle"> <property name="javaStyle" value="false"/> </module> Packagecom.puppycrawl.tools.checkstyle.checks Parent ModuleFinalParametersDescriptionCheck that method/constructor parameters are final. Interface methods are not checked - the final keyword does not make sense for interface method parameters as there is no code that could modify the parameter. Rationale: Changing the value of parameters during the execution of the method's algorithm can be confusing and should be avoided. A great way to let the Java compiler prevent this coding style is to declare parameters final. Properties
ExamplesTo configure the check to enforce final parameters for methods and constructors: <module name="FinalParameters"/> To configure the check to enforce final parameters only for constructors: <module name="FinalParameters"> <property name="tokens" value="CTOR_DEF"/> </module> Packagecom.puppycrawl.tools.checkstyle.checks Parent ModuleDescendantTokenDescriptionChecks for restricted tokens beneath other tokens. WARNING: This is a very powerful and flexible check, but, at the same time, it is low level and very implementation dependent because its results depend on the grammar we use to build abstract syntax trees. Thus we recomend using other checks when they provide the desired funcionality. All in all, this check just works on the level of an abstract tree and knows nothing about language structures. Properties
ExamplesString literal equality check: <module name="DescendantToken"> <property name="tokens" value="EQUAL,NOT_EQUAL"/> <property name="limitedTokens" value="STRING_LITERAL"/> <property name="maximumNumber" value="0"/> <property name="maximumDepth" value="1"/> </module> Switch with no default: <module name="DescendantToken"> <property name="tokens" value="LITERAL_SWITCH"/> <property name="maximumDepth" value="2"/> <property name="limitedTokens" value="LITERAL_DEFAULT"/> <property name="minimumNumber" value="1"/> </module> Assert statement may have side effects (formatted for browser display): <module name="DescendantToken"> <property name="tokens" value="LITERAL_ASSERT"/> <property name="limitedTokens" value="ASSIGN,DEC,INC,POST_DEC, POST_INC,PLUS_ASSIGN,MINUS_ASSIGN,STAR_ASSIGN,DIV_ASSIGN,MOD_ASSIGN, BSR_ASSIGN,SR_ASSIGN,SL_ASSIGN,BAND_ASSIGN,BXOR_ASSIGN,BOR_ASSIGN, METHOD_CALL"/> <property name="maximumNumber" value="0"/> </module> Initialiser in for performs no setup (use while instead?): <module name="DescendantToken"> <property name="tokens" value="FOR_INIT"/> <property name="limitedTokens" value="EXPR"/> <property name="minimumNumber" value="1"/> </module> Condition in for performs no check: <module name="DescendantToken"> <property name="tokens" value="FOR_CONDITION"/> <property name="limitedTokens" value="EXPR"/> <property name="minimumNumber" value="1"/> </module> Switch within switch: <module name="DescendantToken"> <property name="tokens" value="LITERAL_SWITCH"/> <property name="limitedTokens" value="LITERAL_SWITCH"/> <property name="maximumNumber" value="0"/> <property name="minimumDepth" value="1"/> </module> Return from within a catch or finally block: <module name="DescendantToken"> <property name="tokens" value="LITERAL_FINALLY,LITERAL_CATCH"/> <property name="limitedTokens" value="LITERAL_RETURN"/> <property name="maximumNumber" value="0"/> </module> Try within catch or finally block: <module name="DescendantToken"> <property name="tokens" value="LITERAL_CATCH,LITERAL_FINALLY"/> <property name="limitedTokens" value="LITERAL_TRY"/> <property name="maximumNumber" value="0"/> </module> Too many cases within a switch: <module name="DescendantToken"> <property name="tokens" value="LITERAL_SWITCH"/> <property name="limitedTokens" value="LITERAL_CASE"/> <property name="maximumDepth" value="2"/> <property name="maximumNumber" value="10"/> </module> Too many local variables within a method: <module name="DescendantToken"> <property name="tokens" value="METHOD_DEF"/> <property name="limitedTokens" value="VARIABLE_DEF"/> <property name="maximumDepth" value="2"/> <property name="maximumNumber" value="10"/> </module> Too many returns from within a method: <module name="DescendantToken"> <property name="tokens" value="METHOD_DEF"/> <property name="limitedTokens" value="LITERAL_RETURN"/> <property name="maximumNumber" value="3"/> </module> Too many fields within an interface: <module name="DescendantToken"> <property name="tokens" value="INTERFACE_DEF"/> <property name="limitedTokens" value="VARIABLE_DEF"/> <property name="maximumDepth" value="2"/> <property name="maximumNumber" value="0"/> </module> Limit the number of exceptions a method can throw: <module name="DescendantToken"> <property name="tokens" value="LITERAL_THROWS"/> <property name="limitedTokens" value="IDENT"/> <property name="maximumNumber" value="1"/> </module> Limit the number of expressions in a method: <module name="DescendantToken"> <property name="tokens" value="METHOD_DEF"/> <property name="limitedTokens" value="EXPR"/> <property name="maximumNumber" value="200"/> </module> Disallow empty statements: <module name="DescendantToken"> <property name="tokens" value="EMPTY_STAT"/> <property name="limitedTokens" value="EMPTY_STAT"/> <property name="maximumNumber" value="0"/> <property name="maximumDepth" value="0"/> <property name="maximumMessage" value="Empty statement is not allowed."/> </module> Too many fields within a class: <module name="DescendantToken"> <property name="tokens" value="CLASS_DEF"/> <property name="limitedTokens" value="VARIABLE_DEF"/> <property name="maximumDepth" value="2"/> <property name="maximumNumber" value="10"/> </module> Packagecom.puppycrawl.tools.checkstyle.checks Parent ModuleIndentationIndentationDescriptionChecks correct indentation of Java Code. The basic idea behind this is that while pretty printers are sometimes convienent for bulk reformats of legacy code, they often either aren't configurable enough or just can't anticipate how format should be done. Sometimes this is personal preference, other times it is practical experience. In any case, this check should just ensure that a minimal set of indentation rules are followed. Properties
ExamplesTo configure the check: <module name="Indentation"/> To configure the check to enforce indentation style recommended by Sun: <module name="Indentation"> <property name="caseIndent" value="0"/> </module> Packagecom.puppycrawl.tools.checkstyle.checks.indentation Parent Module |
Copyright © 2002-2003 Oliver Burn. All rights Reserved.