checkstyle/docs/config_misc.html

702 lines
25 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Miscellaneous Checks</title>
<link rel="stylesheet" type="text/css" href="mystyle.css"/>
</head>
<body>
<!-- The header -->
<table border="0" width="100%" summary="header layout">
<tr>
<td><h1>Miscellaneous Checks</h1></td>
<td align="right"><img src="logo.png" alt="Checkstyle Logo"/></td>
</tr>
</table>
<!-- content -->
<table border="0" width="100%" cellpadding="5" summary="body layout">
<tr>
<!--Left menu-->
<td class="menu" valign="top">
<ul>
<li>
<a href="#ArrayTypeStyle">ArrayTypeStyle</a>
</li>
<li>
<a href="#DescendantToken">DescendantToken</a>
</li>
<li>
<a href="#FinalParameters">FinalParameters</a>
</li>
<li>
<a href="#GenericIllegalRegexp">GenericIllegalRegexp</a>
</li>
<li>
<a href="#NewlineAtEndOfFile">NewlineAtEndOfFile</a>
</li>
<li>
<a href="#TodoComment">TodoComment</a>
</li>
<li>
<a href="#Translation">Translation</a>
</li>
<li>
<a href="#UncommentedMain">UncommentedMain</a>
</li>
<li>
<a href="#UpperEll">UpperEll</a>
</li>
</ul>
</td>
<!--Content-->
<td class="content" valign="top" align="left">
<!-- --> <a name="GenericIllegalRegexp"></a> <h2>GenericIllegalRegexp</h2> <h4>Description</h4>
<p class="body">
A 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.
</p>
<p class="body">
Rationale: This check can be used to prototype checks and to find common bad
practice such as calling <span class="code">ex.printStacktrace()</span>, <span class="code">
System.out.println()</span>, <span class="code">System.exit()</span>, etc.
</p>
<h4>Properties</h4>
<table width="100%" border="1" cellpadding="5" class="body">
<tr class="header">
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
</tr>
<tr>
<td>format</td>
<td>illegal pattern</td>
<td><a href="property_types.html#regexp">regular expression</a></td>
<td><span class="default">^$</span> (empty)</td>
</tr>
<tr>
<td>ignoreCase</td>
<td>Controls whether to ignore case when searching.</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><span class="default">false</span></td>
</tr>
<tr>
<td>message</td>
<td>message which is used to notify about violations,
if empty then default(hard-coded) message is used.</td>
<td><a href="property_types.html#String">String</a></td>
<td><span class="default">&quot;&quot;</span>(empty)</td>
</tr>
</table>
<h4>Examples</h4>
<p class="body">
To configure the check for calls to <span class="code">System.out.println</span>:
</p>
<pre class="body">
&lt;module name=&quot;GenericIllegalRegexp&quot;&gt;
&lt;!-- . matches any character, so we need to
escape it and use \. to match dots. --&gt;
&lt;property name=&quot;format&quot; value=&quot;System\.out\.println&quot;/&gt;
&lt;/module&gt;
</pre>
<p class="body">
To configure the check to find trailing whitespace at the end of a line:
</p>
<pre class="body">
&lt;module name=&quot;GenericIllegalRegexp&quot;&gt;
&lt;!-- \s matches whitespace character, $ matches end of line. --&gt;
&lt;property name=&quot;format&quot; value=&quot;\s$&quot;/&gt;
&lt;/module&gt;
</pre>
<p class="body">
To configure the check to find case-insensitive occurrences of &quot;debug&quot;:
</p>
<pre class="body">
&lt;module name=&quot;GenericIllegalRegexp&quot;&gt;
&lt;property name=&quot;format&quot; value=&quot;debug&quot;/&gt;
&lt;property name=&quot;ignoreCase&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
</pre>
<h4>Package</h4>
<p class="body">
com.puppycrawl.tools.checkstyle.checks
</p>
<h4>Parent Module</h4>
<p class="body">
<a href="config.html#treewalker">TreeWalker</a>
</p>
<!-- --> <a name="NewlineAtEndOfFile"></a> <h2>NewlineAtEndOfFile</h2> <h4>Description</h4>
<p class="body">
Checks whether files end with a new line.
</p>
<p class="body">
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.
</p>
<h4>Properties</h4>
<table width="100%" border="1" cellpadding="5" class="body">
<tr class="header">
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
</tr>
<tr>
<td>lineSeparator</td>
<td>type of line separator</td>
<td>One of &quot;system&quot; (system default), &quot;crlf&quot; (Windows-style), &quot;cr&quot; (Mac-style) and &quot;lf&quot; (Unix-style)</td>
<td>system default</td>
</tr>
</table>
<h4>Examples</h4>
<p class="body">
To configure the check:
</p>
<pre class="body">
&lt;module name=&quot;NewlineAtEndOfFile&quot;/&gt;
</pre>
<p class="body">
To configure the check to always use Unix-style line separators:
</p>
<pre class="body">
&lt;module name=&quot;NewlineAtEndOfFile&quot;&gt;
&lt;property name=&quot;lineSeparator&quot; value=&quot;lf&quot;/&gt;
&lt;/module&gt;
</pre>
<h4>Package</h4>
<p class="body">
com.puppycrawl.tools.checkstyle.checks
</p>
<h4>Parent Module</h4>
<p class="body">
<a href="config.html#checker">Checker</a>
</p>
<!-- --> <a name="TodoComment"></a> <h2>TodoComment</h2> <h4>Description</h4>
<p class="body">
A check for <span class="code">TODO:</span> comments. Actually it is a generic <a href="http://jakarta.apache.org/regexp/apidocs/org/apache/regexp/RE.html">regular
expression</a> matcher on Java comments. To check for other patterns in Java
comments, set property format.
</p>
<h4>Properties</h4>
<table width="100%" border="1" cellpadding="5" class="body">
<tr class="header">
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
</tr>
<tr>
<td>format</td>
<td>pattern to check</td>
<td><a href="property_types.html#regexp">regular expression</a></td>
<td><span class="default">TODO:</span></td>
</tr>
</table>
<h4>Notes</h4>
<p class="body">
Using <span class="code">TODO:</span> 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.
</p>
<h4>Examples</h4>
<p class="body">
To configure the check:
</p>
<pre class="body">
&lt;module name=&quot;TodoComment&quot;/&gt;
</pre>
<p class="body">
To configure the check for comments that contain <span class="code">WARNING</span>:
</p>
<pre class="body">
&lt;module name=&quot;TodoComment&quot;&gt;
&lt;property name=&quot;format&quot; value=&quot;WARNING&quot;/&gt;
&lt;/module&gt;
</pre>
<h4>Package</h4>
<p class="body">
com.puppycrawl.tools.checkstyle.checks
</p>
<h4>Parent Module</h4>
<p class="body">
<a href="config.html#treewalker">TreeWalker</a>
</p>
<!-- --> <a name="Translation"></a> <h2>Translation</h2> <h4>Description</h4>
<p class="body">
A <a href="config.html#overview">FileSetCheck</a> 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.
</p>
<p class="body">
Consider the following properties file in the same directory:
</p>
<pre>
#messages.properties
hello=Hello
cancel=Cancel
#messages_de.properties
hell=Hallo
ok=OK
</pre>
<p class="body">
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:
</p>
<pre>
messages_de.properties: Key 'hello' missing.
messages_de.properties: Key 'cancel' missing.
messages.properties: Key 'hell' missing.
messages.properties: Key 'ok' missing.
</pre>
<h4>Properties</h4>
<table width="100%" border="1" cellpadding="5" class="body">
<tr class="header">
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
</tr>
<tr>
<td>fileExtensions</td>
<td>file type extension to identify translation files. Setting this property
is typically only required if your translation files are preprocessed
and the original files do not have the extension
<span class="code">.properties</span></td>
<td><a href="property_types.html#stringSet">String Set</a></td>
<td><span class="default">properties</span></td>
</tr>
</table>
<h4>Example</h4>
<p class="body">
To configure the check:
</p>
<pre class="body">
&lt;module name=&quot;Translation&quot;/&gt;
</pre>
<h4>Package</h4>
<p class="body">
com.puppycrawl.tools.checkstyle.checks
</p>
<h4>Parent Module</h4>
<p class="body">
<a href="config.html#checker">Checker</a>
</p>
<!-- --> <a name="UncommentedMain"></a> <h2>UncommentedMain</h2> <h4>Description</h4>
<p class="body">
Checks for uncommented main() methods (debugging leftovers).
</p>
<p class="body"> Rationale: main() method can be often used for
debug puposes. Thus most of main() method should be
removed/commented out of the sources.
</p>
<h4>Properties</h4>
<table width="100%" border="1" cellpadding="5" class="body">
<tr class="header">
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
</tr>
<tr>
<td>excludedClasses</td>
<td>pattern for qualified names of classes which ar allowed
to have main method.</td>
<td><a href="property_types.html#regexp">regular expression</a></td>
<td><span class="default">^$</span></td>
</tr>
</table>
<h4>Examples</h4>
<p class="body">
To configure the check:
</p>
<pre class="body">
&lt;module name=&quot;UncommentedMain&quot;/&gt;
</pre>
<p class="body">
To configure the check to allow main method for all classes with
&quot;Main&quot; name:
</p>
<pre class="body">
&lt;module name=&quot;UncommentedMain&quot;&gt;
&lt;property name=&quot;excludedClasses&quot; value=&quot;\.Main$&quot;/&gt;
&lt;/module&gt;
</pre>
<h4>Package</h4>
<p class="body">
com.puppycrawl.tools.checkstyle.checks
</p>
<h4>Parent Module</h4>
<p class="body">
<a href="config.html#treewalker">TreeWalker</a>
</p>
<!-- --> <a name="UpperEll"></a> <h2>UpperEll</h2> <h4>Description</h4>
<p class="body">
Checks that long constants are defined with an upper ell. That is <span class="code">'
L'</span> and
not <span class="code">'l'</span>. This is in accordance to the Java Language
Specification, <a href="http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#48282">
Section
3.10.1</a>.
</p>
<p class="body"> Rationale: The letter <span class="code">l</span> looks a lot
like <span class="code">1</span>.
</p>
<h4>Examples</h4>
<p class="body">
To configure the check:
</p>
<pre class="body">
&lt;module name=&quot;UpperEll&quot;/&gt;
</pre>
<h4>Package</h4>
<p class="body">
com.puppycrawl.tools.checkstyle.checks
</p>
<h4>Parent Module</h4>
<p class="body">
<a href="config.html#treewalker">TreeWalker</a>
</p>
<!-- --> <a name="ArrayTypeStyle"></a> <h2>ArrayTypeStyle</h2> <h4>Description</h4>
<p class="body">
Checks the style of array type definitions.
Some like Java-style: <code>public static void main(String[] args)</code>
and some like C-style: public static void main(String args[])
</p>
<h4>Properties</h4>
<table width="100%" border="1" cellpadding="5" class="body">
<tr class="header">
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
</tr>
<tr>
<td>javaStyle</td>
<td>Controls whether to enforce Java style (true) or C style (false).</td>
<td><a href="property_types.html#boolean">Boolean</a></td>
<td><span class="default">true</span></td>
</tr>
</table>
<h4>Examples</h4>
<p class="body">
To configure the check to enforce Java style:
</p>
<pre class="body">
&lt;module name=&quot;ArrayTypeStyle&quot;/&gt;
</pre>
<p class="body">
To configure the check to enforce C style:
</p>
<pre class="body">
&lt;module name=&quot;ArrayTypeStyle&quot;&gt;
&lt;property name=&quot;javaStyle&quot; value=&quot;false&quot;/&gt;
&lt;/module&gt;
</pre>
<h4>Package</h4>
<p class="body">
com.puppycrawl.tools.checkstyle.checks
</p>
<h4>Parent Module</h4>
<p class="body">
<a href="config.html#treewalker">TreeWalker</a>
</p>
<!-- --> <a name="FinalParameters"></a> <h2>FinalParameters</h2> <h4>Description</h4>
<p class="body">
Check 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.
</p>
<p class="body">
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.
</p>
<h4>Properties</h4>
<table width="100%" border="1" cellpadding="5" class="body">
<tr class="header">
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
</tr>
<tr>
<td>tokens</td>
<td>blocks to check</td>
<td>subset of tokens <a
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">METHOD_DEF</a>,
<a
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">CTOR_DEF</a></td>
<td><a
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#METHOD_DEF">METHOD_DEF</a>,
<a
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#CTOR_DEF">CTOR_DEF</a></td>
</tr>
</table>
<h4>Examples</h4>
<p class="body">
To configure the check to enforce final parameters for methods and constructors:
</p>
<pre class="body">
&lt;module name=&quot;FinalParameters&quot;/&gt;
</pre>
<p class="body">
To configure the check to enforce final parameters only for constructors:
</p>
<pre class="body">
&lt;module name=&quot;FinalParameters&quot;&gt;
&lt;property name=&quot;tokens&quot; value=&quot;CTOR_DEF&quot;/&gt;
&lt;/module&gt;
</pre>
<h4>Package</h4>
<p class="body">
com.puppycrawl.tools.checkstyle.checks
</p>
<h4>Parent Module</h4>
<p class="body">
<a href="config.html#treewalker">TreeWalker</a>
</p>
<!-- --> <a name="DescendantToken"></a> <h2>DescendantToken</h2> <h4>Description</h4>
<p class="body">
Checks for restricted tokens beneath other tokens.
</p>
<p class="body">
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.
</p>
<h4>Properties</h4>
<table width="100%" border="1" cellpadding="5" class="body">
<tr class="header">
<th>name</th>
<th>description</th>
<th>type</th>
<th>default value</th>
</tr>
<tr>
<td>tokens</td>
<td>token types to check</td>
<td>subset of tokens declared in <a
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html">TokenTypes</a></td>
<td>empty set</td>
</tr>
<tr>
<td>limitedTokens</td>
<td>set of tokens with limited occurances as descendants</td>
<td>subset of tokens declared in <a
href="api/com/puppycrawl/tools/checkstyle/api/TokenTypes.html">TokenTypes</a></td>
<td>empty set</td>
<tr>
<td>minimumDepth</td>
<td>the mimimum depth for descendant counts</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td>0</td>
</tr>
<tr>
<td>maximumDepth</td>
<td>the maximum depth for descendant counts</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td>java.lang.Integer.MAX_VALUE</td>
</tr>
<tr>
<td>minimumNumber</td>
<td>a minimum count for descendants</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td>0</td>
</tr>
<tr>
<td>maximumNumber</td>
<td>a maximum count for descendants</td>
<td><a href="property_types.html#integer">Integer</a></td>
<td>java.lang.Integer.MAX_VALUE</td>
</tr>
<tr>
<td>minimumMessage</td>
<td>error message when minimum count not reached</td>
<td><a href="property_types.html#String">String</a></td>
<td>&quot;descendant.token.min&quot;</td>
</tr>
<tr>
<td>maximumMessage</td>
<td>error message when maximum count exceeded</td>
<td><a href="property_types.html#String">String</a></td>
<td>&quot;descendant.token.max&quot;</td>
</tr>
</table>
<h4>Examples</h4>
<pre>
String literal equality check:
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="EQUAL,NOT_EQUAL"/&gt;
&lt;property name="limitedTokens" value="STRING_LITERAL"/&gt;
&lt;property name="maximumNumber" value="0"/&gt;
&lt;property name="maximumDepth" value="1"/&gt;
&lt;/module&gt;
Switch with no default:
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="LITERAL_SWITCH"/&gt;
&lt;property name="maximumDepth" value="2"/&gt;
&lt;property name="limitedTokens" value="LITERAL_DEFAULT"/&gt;
&lt;property name="minimumNumber" value="1"/&gt;
&lt;/module&gt;
Assert statement may have side effects (formatted for browser display):
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="LITERAL_ASSERT"/&gt;
&lt;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"/&gt;
&lt;property name="maximumNumber" value="0"/&gt;
&lt;/module&gt;
Initialiser in for performs no setup (use while instead?):
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="FOR_INIT"/&gt;
&lt;property name="limitedTokens" value="EXPR"/&gt;
&lt;property name="minimumNumber" value="1"/&gt;
&lt;/module&gt;
Condition in for performs no check:
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="FOR_CONDITION"/&gt;
&lt;property name="limitedTokens" value="EXPR"/&gt;
&lt;property name="minimumNumber" value="1"/&gt;
&lt;/module&gt;
Switch within switch:
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="LITERAL_SWITCH"/&gt;
&lt;property name="limitedTokens" value="LITERAL_SWITCH"/&gt;
&lt;property name="maximumNumber" value="0"/&gt;
&lt;property name="minimumDepth" value="1"/&gt;
&lt;/module&gt;
Return from within a catch or finally block:
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="LITERAL_FINALLY,LITERAL_CATCH"/&gt;
&lt;property name="limitedTokens" value="LITERAL_RETURN"/&gt;
&lt;property name="maximumNumber" value="0"/&gt;
&lt;/module&gt;
Try within catch or finally block:
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="LITERAL_CATCH,LITERAL_FINALLY"/&gt;
&lt;property name="limitedTokens" value="LITERAL_TRY"/&gt;
&lt;property name="maximumNumber" value="0"/&gt;
&lt;/module&gt;
Too many cases within a switch:
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="LITERAL_SWITCH"/&gt;
&lt;property name="limitedTokens" value="LITERAL_CASE"/&gt;
&lt;property name="maximumDepth" value="2"/&gt;
&lt;property name="maximumNumber" value="10"/&gt;
&lt;/module&gt;
Too many local variables within a method:
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="METHOD_DEF"/&gt;
&lt;property name="limitedTokens" value="VARIABLE_DEF"/&gt;
&lt;property name="maximumDepth" value="2"/&gt;
&lt;property name="maximumNumber" value="10"/&gt;
&lt;/module&gt;
Too many returns from within a method:
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="METHOD_DEF"/&gt;
&lt;property name="limitedTokens" value="LITERAL_RETURN"/&gt;
&lt;property name="maximumNumber" value="3"/&gt;
&lt;/module&gt;
Too many fields within an interface:
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="INTERFACE_DEF"/&gt;
&lt;property name="limitedTokens" value="VARIABLE_DEF"/&gt;
&lt;property name="maximumDepth" value="2"/&gt;
&lt;property name="maximumNumber" value="0"/&gt;
&lt;/module&gt;
Limit the number of exceptions a method can throw:
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="LITERAL_THROWS"/&gt;
&lt;property name="limitedTokens" value="IDENT"/&gt;
&lt;property name="maximumNumber" value="1"/&gt;
&lt;/module&gt;
Limit the number of expressions in a method:
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="METHOD_DEF"/&gt;
&lt;property name="limitedTokens" value="EXPR"/&gt;
&lt;property name="maximumNumber" value="200"/&gt;
&lt;/module&gt;
Disallow empty statements:
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="EMPTY_STAT"/&gt;
&lt;property name="limitedTokens" value="EMPTY_STAT"/&gt;
&lt;property name="maximumNumber" value="0"/&gt;
&lt;property name="maximumDepth" value="0"/&gt;
&lt;property name="maximumMessage"
value="Empty statement is not allowed."/&gt;
&lt;/module&gt;
Too many fields within a class:
&lt;module name="DescendantToken"&gt;
&lt;property name="tokens" value="CLASS_DEF"/&gt;
&lt;property name="limitedTokens" value="VARIABLE_DEF"/&gt;
&lt;property name="maximumDepth" value="2"/&gt;
&lt;property name="maximumNumber" value="10"/&gt;
&lt;/module&gt;
<h4>Package</h4>
<p class="body">
com.puppycrawl.tools.checkstyle.checks
</p>
<h4>Parent Module</h4>
<p class="body">
<a href="config.html#treewalker">TreeWalker</a>
</p>
</td>
</tr>
</table>
<hr />
<div><a href="index.html">Back to the Checkstyle Home Page</a></div>
<p class="copyright">
Copyright &copy; 2002-2003 Oliver Burn. All rights Reserved.
</p>
</body>
</html>