checkstyle/docs/config_misc.html

423 lines
14 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="#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="#UpperEll">UpperEll</a>
</li>
<li>
<a href="#ArrayTypeStyle">ArrayTypeStyle</a>
</li>
<li>
<a href="#FinalParameters">FinalParameters</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>message</td>
<td>message which is used to notify about violations,
if empty then default(hard-codded) 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>
<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="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 mathod 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>
</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>