1066 lines
42 KiB
XML
1066 lines
42 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<document xmlns="http://maven.apache.org/XDOC/2.0"
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
xsi:schemaLocation="http://maven.apache.org/XDOC/2.0 http://maven.apache.org/xsd/xdoc-2.0.xsd">
|
|
|
|
<head>
|
|
<title>Regexp</title>
|
|
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"/>
|
|
<script type="text/javascript" src="js/anchors.js"/>
|
|
<script type="text/javascript" src="js/google-analytics.js"/>
|
|
<link rel="icon" href="images/favicon.png" type="image/x-icon" />
|
|
<link rel="shortcut icon" href="images/favicon.ico" type="image/ico" />
|
|
</head>
|
|
|
|
<body>
|
|
<section name="Content">
|
|
<macro name="toc">
|
|
<param name="fromDepth" value="1"/>
|
|
<param name="toDepth" value="1"/>
|
|
</macro>
|
|
</section>
|
|
|
|
<section name="Regexp">
|
|
<subsection name="Description">
|
|
<p>
|
|
A check that makes sure that a specified pattern exists, exists less
|
|
than a set number of times, or does not exist in the file.
|
|
</p>
|
|
<p>
|
|
This check combines all the functionality provided by
|
|
<a href="config_header.html#RegexpHeader">RegexpHeader</a>
|
|
except supplying the regular expression from a file.
|
|
</p>
|
|
<p>
|
|
It differs from them in that it works in multiline mode.
|
|
Its regular expression can span multiple lines and it checks this
|
|
against the whole file at once.
|
|
The others work in singleline mode.
|
|
Their single or multiple regular expressions can only span one line.
|
|
They check each of these against each line in the file in turn.
|
|
</p>
|
|
<p>
|
|
<b>Note:</b> Because of the different mode of operation there may be
|
|
some changes in the regular expressions used to achieve a particular end.
|
|
</p>
|
|
<p>In multiline mode...</p>
|
|
<ul>
|
|
<li> <code>^</code> means the beginning of a line, as opposed to beginning of the input.</li>
|
|
<li> For beginning of the input use <code>\A</code>.</li>
|
|
<li> <code>$</code> means the end of a line, as opposed to the end of the input.</li>
|
|
<li> For end of input use <code>\Z</code>.</li>
|
|
<li> Each line in the file is terminated with a line feed character.</li>
|
|
</ul>
|
|
<p>
|
|
<b>Note:</b> Not all regular expression engines are created equal. Some provide extra
|
|
functions that others do not and some elements of the syntax may vary.
|
|
This check makes use of the <a
|
|
href="https://docs.oracle.com/javase/7/docs/api/java/util/regex/package-summary.html">
|
|
java.util.regex package</a>; please check its documentation for
|
|
details of how to construct a regular expression to achieve a particular
|
|
goal.
|
|
</p>
|
|
<p>
|
|
<b>Note:</b> When entering a regular expression as a parameter in the
|
|
XML config file you must also take into account the XML rules. e.g. if
|
|
you want to match a < symbol you need to enter &lt;. The regular
|
|
expression should be entered on one line.
|
|
</p>
|
|
</subsection>
|
|
|
|
<subsection name="Properties">
|
|
<table>
|
|
<tr>
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>format</td>
|
|
<td>pattern</td>
|
|
<td><a href="property_types.html#regexp">regular expression</a></td>
|
|
<td><code>$^</code> (empty)</td>
|
|
</tr>
|
|
<tr>
|
|
<td>message</td>
|
|
<td>message which is used to notify about violations,
|
|
if empty then the default (hard-coded) message is used.</td>
|
|
<td><a href="property_types.html#string">String</a></td>
|
|
<td><code>""</code>(empty)</td>
|
|
</tr>
|
|
<tr>
|
|
<td>illegalPattern</td>
|
|
<td>Controls whether the pattern is required or illegal.</td>
|
|
<td><a href="property_types.html#boolean">Boolean</a></td>
|
|
<td><code>false</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>duplicateLimit</td>
|
|
<td>Controls whether to check for duplicates of a required pattern,
|
|
any negative value means no checking for duplicates, any positive
|
|
value is used as the maximum number of allowed duplicates, if the
|
|
limit is exceeded errors will be logged.</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td><code>-1</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>errorLimit</td>
|
|
<td>Controls the maximum number of errors before the check will abort.</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td><code>100</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>ignoreComments</td>
|
|
<td>Controls whether to ignore matches found within comments.</td>
|
|
<td><a href="property_types.html#boolean">Boolean</a></td>
|
|
<td><code>false</code></td>
|
|
</tr>
|
|
</table>
|
|
</subsection>
|
|
|
|
<subsection name="Examples">
|
|
<p>
|
|
The following examples are mainly copied from the other 3 checks
|
|
mentioned above, to show how the same results can be achieved using
|
|
this check in place of them.
|
|
</p>
|
|
<p>
|
|
<b>To use like Required Regexp check:</b>
|
|
</p>
|
|
<p>
|
|
An example of how to configure the check to make sure a copyright
|
|
statement is included in the file:
|
|
</p>
|
|
<p> The statement. </p>
|
|
<source>
|
|
// This code is copyrighted
|
|
</source>
|
|
<p> The check. </p>
|
|
<source>
|
|
<module name="Regexp">
|
|
<property name="format" value="// This code is copyrighted"/>
|
|
</module>
|
|
</source>
|
|
<p> Your statement may be multiline. </p>
|
|
<source>
|
|
// This code is copyrighted
|
|
// (c) MyCompany
|
|
</source>
|
|
<p> Then the check would be. </p>
|
|
<source>
|
|
<module name="Regexp">
|
|
<property name="format" value="// This code is copyrighted\n// \(c\) MyCompany"/>
|
|
</module>
|
|
</source>
|
|
<p><b>Note:</b> To search for parentheses () in a regular expression
|
|
you must escape them like \(\). This is required by the regexp engine,
|
|
otherwise it will think they are special instruction characters.
|
|
</p>
|
|
<p>
|
|
And to make sure it appears only once:
|
|
</p>
|
|
<source>
|
|
<module name="Regexp">
|
|
<property name="format" value="// This code is copyrighted\n// \(c\) MyCompany"/>
|
|
<property name="duplicateLimit" value="0"/>
|
|
</module>
|
|
</source>
|
|
<p>
|
|
It can also be useful to attach a meaningful message to the check:
|
|
</p>
|
|
<source>
|
|
<module name="Regexp">
|
|
<property name="format" value="// This code is copyrighted\n// \(c\) MyCompany"/>
|
|
<property name="message" value="Copyright"/>
|
|
</module>
|
|
</source>
|
|
<p>
|
|
<b>To use like illegal regexp check:</b>
|
|
</p>
|
|
<p>
|
|
An example of how to configure the check to make sure there are no
|
|
calls to <code>System.out.println</code>:
|
|
</p>
|
|
<source>
|
|
<module name="Regexp">
|
|
<!-- . matches any character, so we need to escape it and use \. to match dots. -->
|
|
<property name="format" value="System\.out\.println"/>
|
|
<property name="illegalPattern" value="true"/>
|
|
</module>
|
|
</source>
|
|
<p>
|
|
You may want to make the above check ignore comments, like this:
|
|
</p>
|
|
<source>
|
|
<module name="Regexp">
|
|
<property name="format" value="System\.out\.println"/>
|
|
<property name="illegalPattern" value="true"/>
|
|
<property name="ignoreComments" value="true"/>
|
|
</module>
|
|
</source>
|
|
<p>
|
|
An example of how to configure the check to find trailing whitespace
|
|
at the end of a line:
|
|
</p>
|
|
<source>
|
|
<module name="Regexp">
|
|
<property name="format" value="[ \t]+$"/>
|
|
<property name="illegalPattern" value="true"/>
|
|
<property name="message" value="Trailing whitespace"/>
|
|
</module>
|
|
</source>
|
|
<p>
|
|
An example of how to configure the check to find case-insensitive
|
|
occurrences of "debug":
|
|
</p>
|
|
<source>
|
|
<module name="Regexp">
|
|
<property name="format" value="(?i)debug"/>
|
|
<property name="illegalPattern" value="true"/>
|
|
</module>
|
|
</source>
|
|
<p>
|
|
<b>Note:</b> The (?i) at the beginning of the regular expression
|
|
tells the regexp engine to ignore the case.
|
|
</p>
|
|
<p>
|
|
There is also a feature to limit the number of errors reported.
|
|
When the limit is reached the check aborts with a message
|
|
reporting that the limit has been reached.
|
|
The default limit setting is 100, but this can be change as shown in
|
|
the following example.
|
|
</p>
|
|
<source>
|
|
<module name="Regexp">
|
|
<property name="format" value="(?i)debug"/>
|
|
<property name="illegalPattern" value="true"/>
|
|
<property name="errorLimit" value="1000"/>
|
|
</module>
|
|
</source>
|
|
<p>
|
|
<b>To use like <a
|
|
href="config_header.html#RegexpHeader">RegexpHeader
|
|
</a>:</b>
|
|
</p>
|
|
<p>
|
|
To configure the check to verify that each file starts with the
|
|
following multiline header.
|
|
</p>
|
|
<p>Note the following:</p>
|
|
<ul>
|
|
<li>\A means the start of the file.</li>
|
|
<li>The date can be any 4 digit number.</li>
|
|
</ul>
|
|
|
|
<source>
|
|
// Copyright (C) 2004 MyCompany
|
|
// All rights reserved
|
|
</source>
|
|
<source>
|
|
<module name="Regexp">
|
|
<property
|
|
name="format"
|
|
value="\A// Copyright \(C\) \d\d\d\d MyCompany\n// All rights reserved"/>
|
|
</module>
|
|
</source>
|
|
<p>
|
|
A more complex example. Note how the import and javadoc multilines are
|
|
handled, there can be any number of them.
|
|
</p>
|
|
<source>
|
|
///////////////////////////////////////////////////////////////////////
|
|
// checkstyle:
|
|
// Checks Java source code for adherence to a set of rules.
|
|
// Copyright (C) 2004 Oliver Burn
|
|
// Last modification by $Author A.N.Other$
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
package com.puppycrawl.checkstyle;
|
|
|
|
import java.util.thing1;
|
|
import java.util.thing2;
|
|
import java.util.thing3;
|
|
|
|
/**
|
|
* javadoc line 1
|
|
* javadoc line 2
|
|
* javadoc line 3
|
|
*/
|
|
</source>
|
|
<source>
|
|
<module name="Regexp">
|
|
<property
|
|
name="format"
|
|
value="\A/{71}\n// checkstyle:\n// Checks Java source code for
|
|
adherence to a set of rules\.\n// Copyright \(C\) \d\d\d\d Oliver Burn\n
|
|
// Last modification by \$Author.*\$\n/{71}\n\npackage [\w\.]*;\n\n
|
|
(import [\w\.]*;\n)*\n/\*\*\n( \*[^/]*\n)* \*/"/>
|
|
</module>
|
|
</source>
|
|
<p>
|
|
<b>More examples:</b>
|
|
</p>
|
|
<p>
|
|
The next 2 examples deal with the following example Java source file:
|
|
</p>
|
|
<source>
|
|
/*
|
|
* PID.java
|
|
*
|
|
* Copyright (c) 2001 ACME
|
|
* 123 Some St.
|
|
* Somewhere.
|
|
*
|
|
* This software is the confidential and proprietary information of ACME.
|
|
* ("Confidential Information"). You shall not disclose such
|
|
* Confidential Information and shall use it only in accordance with
|
|
* the terms of the license agreement you entered into with ACME.
|
|
*
|
|
* $Log: config_misc.xml,v $
|
|
* Revision 1.7 2007/01/16 12:16:35 oburn
|
|
* Removing all reference to mailing lists
|
|
*
|
|
* Revision 1.6 2005/12/25 16:13:10 o_sukhodolsky
|
|
* Fix for rfe 1248106 (TYPECAST is now accepted by NoWhitespaceAfter)
|
|
*
|
|
* Fix for rfe 953266 (thanks to Paul Guyot (pguyot) for submitting patch)
|
|
* IllegalType can be configured to accept some abstract classes which
|
|
* matches to regexp of illegal type names (property legalAbstractClassNames)
|
|
*
|
|
* TrailingComment now can be configured to accept some trailing comments
|
|
* (such as NOI18N) (property legalComment, rfe 1385344).
|
|
*
|
|
* Revision 1.5 2005/11/06 11:54:12 oburn
|
|
* Incorporate excellent patch [ 1344344 ] Consolidation of regexp checks.
|
|
*
|
|
* Revision 1.3.8.1 2005/10/11 14:26:32 someone
|
|
* Fix for bug 251. The broken bit is fixed
|
|
*/
|
|
|
|
package com.acme.tools;
|
|
|
|
import com.acme.thing1;
|
|
import com.acme.thing2;
|
|
import com.acme.thing3;
|
|
|
|
/**
|
|
*
|
|
* <P>
|
|
* <I>This software is the confidential and proprietary information of
|
|
* ACME (<B>"Confidential Information"</B>). You shall not
|
|
* disclose such Confidential Information and shall use it only in
|
|
* accordance with the terms of the license agreement you entered into
|
|
* with ACME.</I>
|
|
* </P>
|
|
*
|
|
* &#169; copyright 2002 ACME
|
|
*
|
|
* @author Some Body
|
|
*/
|
|
public class PID extends StateMachine implements WebObject.Constants {
|
|
|
|
/** javadoc. */
|
|
public static final int A_SETPOINT = 1;
|
|
.
|
|
.
|
|
.
|
|
} // class PID
|
|
</source>
|
|
<p>
|
|
This checks for the presence of the header, the first 16 lines.
|
|
</p>
|
|
<p>Note the following:</p>
|
|
<ul>
|
|
<li>Line 2 and 13 contain the file name. These are checked to
|
|
make sure they are the same, and that they match the class name.</li>
|
|
<li>The date can be any 4 digit number.</li>
|
|
</ul>
|
|
|
|
<source>
|
|
<module name="Regexp">
|
|
<property
|
|
name="format"
|
|
value="\A/\*\n \* (\w*)\.java\n \*\n \* Copyright \(c\)
|
|
\d\d\d\d ACME\n \* 123 Some St\.\n \* Somewhere\.\n \*\n
|
|
\* This software is the confidential and proprietary information
|
|
of ACME\.\n \* \(&quot;Confidential Information&quot;\)\. You
|
|
shall not disclose such\n \* Confidential Information and shall
|
|
use it only in accordance with\n \* the terms of the license
|
|
agreement you entered into with ACME\.\n \*\n
|
|
\* \$Log: config_misc\.xml,v $
|
|
\* Revision 1\.7 2007/01/16 12:16:35 oburn
|
|
\* Removing all reference to mailing lists
|
|
\* \
|
|
\* Revision 1.6 2005/12/25 16:13:10 o_sukhodolsky
|
|
\* Fix for rfe 1248106 \(TYPECAST is now accepted by NoWhitespaceAfter\)
|
|
\* \
|
|
\* Fix for rfe 953266 \(thanks to Paul Guyot \(pguyot\) for submitting patch\)
|
|
\* IllegalType can be configured to accept some abstract classes which
|
|
\* matches to regexp of illegal type names \(property legalAbstractClassNames\)
|
|
\*
|
|
\* TrailingComment now can be configured to accept some trailing comments
|
|
\* \(such as NOI18N\) \(property legalComment, rfe 1385344\).
|
|
\*
|
|
\* Revision 1.5 2005/11/06 11:54:12 oburn
|
|
\* Incorporate excellent patch \[ 1344344 \] Consolidation of regexp checks.
|
|
\* \\n(.*\n)*([\w|\s]*( class | interface )\1)"/>
|
|
<property name="message" value="Correct header not found"/>
|
|
</module>
|
|
</source>
|
|
<p>
|
|
This checks for the presence of a copyright notice within the class
|
|
javadoc, lines 24 to 37.
|
|
</p>
|
|
<source>
|
|
<module name="Regexp">
|
|
<property
|
|
name="format"
|
|
value="(/\*\*\n)( \*.*\n)*( \* &lt;P&gt;\n \* &lt;I&gt;
|
|
This software is the confidential and proprietary information of\n
|
|
\* ACME \(&lt;B&gt;&quot;Confidential Information&quot;&lt;/B&gt;
|
|
\)\. You shall not\n \* disclose such Confidential Information
|
|
and shall use it only in\n \* accordance with the terms of the
|
|
license agreement you entered into\n \* with ACME\.&lt;/I&gt;\n
|
|
\* &lt;/P&gt;\n \*\n \* &#169; copyright \d\d\d\d ACME\n
|
|
\*\n \* @author .*)(\n\s\*.*)*/\n[\w|\s]*( class | interface )"/>
|
|
<property name="message" value="Copyright in class/interface Javadoc"/>
|
|
<property name="duplicateLimit" value="0"/>
|
|
</module>
|
|
</source>
|
|
<p>
|
|
<b>Note:</b> To search for things that mean something in XML, like
|
|
< you need to escape them like &lt;. This is required so the
|
|
XML parser does not act on them, but instead passes the correct
|
|
character to the regexp engine.
|
|
</p>
|
|
</subsection>
|
|
|
|
<subsection name="Example of Usage">
|
|
<ul>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+Regexp">
|
|
Checkstyle Style</a>
|
|
</li>
|
|
</ul>
|
|
</subsection>
|
|
|
|
<subsection name="Error Messages">
|
|
<ul>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fregexp+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22duplicate.regexp%22">
|
|
duplicate.regexp</a>
|
|
</li>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fregexp+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22illegal.regexp%22">
|
|
illegal.regexp</a>
|
|
</li>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fregexp+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22required.regexp%22">
|
|
required.regexp</a>
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
All messages can be customized if the default message doesn't suite you.
|
|
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
|
|
</p>
|
|
</subsection>
|
|
|
|
<subsection name="Package">
|
|
<p>
|
|
com.puppycrawl.tools.checkstyle.checks.regexp
|
|
</p>
|
|
</subsection>
|
|
|
|
<subsection name="Parent Module">
|
|
<p>
|
|
<a href="config.html#TreeWalker">TreeWalker</a>
|
|
</p>
|
|
</subsection>
|
|
</section>
|
|
|
|
<section name="RegexpMultiline">
|
|
<subsection name="Description">
|
|
<p>
|
|
A check for detecting that matches across multiple lines.
|
|
Works with any file type.
|
|
</p>
|
|
|
|
<p>
|
|
Rationale: This check can be used to when the regular
|
|
expression can be span multiple lines.
|
|
</p>
|
|
</subsection>
|
|
|
|
<subsection name="Properties">
|
|
<table>
|
|
<tr>
|
|
<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><code>^$</code> (empty)</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><code>""</code>(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><code>false</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>minimum</td>
|
|
<td>The minimum number of matches required in each file.</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td><code>0</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>maximum</td>
|
|
<td>The maximum number of matches required in each file.</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td><code>0</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>fileExtensions</td>
|
|
<td>file type extension of files to process</td>
|
|
<td><a href="property_types.html#stringSet">String Set</a></td>
|
|
<td><code>{}</code></td>
|
|
</tr>
|
|
</table>
|
|
</subsection>
|
|
|
|
<subsection name="Examples">
|
|
<p>
|
|
To configure the check to find calls to print to the console:
|
|
</p>
|
|
<source>
|
|
<module name="RegexpMultiline">
|
|
<property name="format"
|
|
value="System\.(out)|(err)\.print(ln)?\("/>
|
|
</module>
|
|
</source>
|
|
</subsection>
|
|
|
|
<subsection name="Example of Usage">
|
|
<ul>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+RegexpMultiline">
|
|
Checkstyle Style</a>
|
|
</li>
|
|
</ul>
|
|
</subsection>
|
|
|
|
<subsection name="Error Messages">
|
|
<ul>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fregexp+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22regexp.StackOverflowError%22">
|
|
regexp.StackOverflowError</a>
|
|
</li>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fregexp+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22regexp.empty%22">
|
|
regexp.empty</a>
|
|
</li>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fregexp+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22regexp.exceeded%22">
|
|
regexp.exceeded</a>
|
|
</li>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fregexp+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22regexp.minimum%22">
|
|
regexp.minimum</a>
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
All messages can be customized if the default message doesn't suite you.
|
|
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
|
|
</p>
|
|
</subsection>
|
|
|
|
<subsection name="Package">
|
|
<p>
|
|
com.puppycrawl.tools.checkstyle.checks.regexp
|
|
</p>
|
|
</subsection>
|
|
|
|
<subsection name="Parent Module">
|
|
<p>
|
|
<a href="config.html#Checker">Checker</a>
|
|
</p>
|
|
</subsection>
|
|
</section>
|
|
|
|
<section name="RegexpOnFilename">
|
|
<subsection name="Description">
|
|
<p>
|
|
Implementation of a check that looks for a file name and/or path match (or mis-match)
|
|
against specified patterns. It can also be used to verify files match specific naming
|
|
patterns not covered by other checks (Ex: properties, xml, etc.).
|
|
</p>
|
|
<p>
|
|
When customizing the check, the properties are applied in a specific order.
|
|
The fileExtensions property first picks only files that match any of the
|
|
specific extensions supplied.
|
|
Once files are matched against the fileExtensions, the match property is then
|
|
used in conjuction with the patterns to determine if the check is looking
|
|
for a match or mis-match on those files. If the fileNamePattern is
|
|
supplied, the matching is only applied to the fileNamePattern and not the
|
|
folderPattern. If no fileNamePattern is supplied, then matching is applied
|
|
to the folderPattern only and will result in all files in a folder to be
|
|
reported on violations. If no folderPattern is supplied, then all folders
|
|
that checkstyle finds are examined for violations.
|
|
The ignoreFileNameExtensions property drops the file extension and applies
|
|
the fileNamePattern only to the rest of file name. For example, if the file is
|
|
named 'test.java' and this property is turned on, the pattern is only applied
|
|
to 'test'.
|
|
</p>
|
|
<p>
|
|
If this check is configured with no properties, then the default behavior
|
|
of this check is to report file names with spaces in them.
|
|
When at least one pattern property is supplied, the entire check is under
|
|
the user's control to allow them to fully customize the behavior.
|
|
</p>
|
|
<p>
|
|
It is recommended that if you create your own pattern, to also
|
|
specify a custom error message. This allows the error message printed
|
|
to be clear what the violation is, especially if multiple RegexpOnFilename
|
|
checks are used.
|
|
Argument 0 for the message populates the check's folderPattern.
|
|
Argument 1 for the message populates the check's fileNamePattern.
|
|
The file name is not passed as an argument since it is part of CheckStyle's
|
|
default error messages.
|
|
</p>
|
|
</subsection>
|
|
|
|
<subsection name="Properties">
|
|
<table>
|
|
<tr>
|
|
<th>name</th>
|
|
<th>description</th>
|
|
<th>type</th>
|
|
<th>default value</th>
|
|
</tr>
|
|
<tr>
|
|
<td>folderPattern</td>
|
|
<td>Regular expression to match the folder path against.</td>
|
|
<td><a href="property_types.html#regexp">regular expression</a></td>
|
|
<td><code>null</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>fileNamePattern</td>
|
|
<td>Regular expression to match the file name against.</td>
|
|
<td><a href="property_types.html#regexp">regular expression</a></td>
|
|
<td><code>null</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>match</td>
|
|
<td>Whether to look for a match or mis-match on the file name, if the
|
|
fileNamePattern is supplied, otherwise it is applied on the folderPattern.</td>
|
|
<td><a href="property_types.html#boolean">Boolean</a></td>
|
|
<td><code>true</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>ignoreFileNameExtensions</td>
|
|
<td>Whether to ignore the file extension for the file name match.</td>
|
|
<td><a href="property_types.html#boolean">Boolean</a></td>
|
|
<td><code>false</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>fileExtensions</td>
|
|
<td>File type extension of files to process. If this is specified, then
|
|
only files that match these types are examined with the other patterns.</td>
|
|
<td><a href="property_types.html#stringSet">String Set</a></td>
|
|
<td><code>{}</code></td>
|
|
</tr>
|
|
</table>
|
|
</subsection>
|
|
|
|
<subsection name="Examples">
|
|
<p>
|
|
To configure the check to report file names that contain a space:
|
|
</p>
|
|
<source>
|
|
<module name="RegexpOnFilename"/>
|
|
</source>
|
|
<p>
|
|
To configure the check to force picture files to not be 'gif':
|
|
</p>
|
|
<source>
|
|
<module name="RegexpOnFilename">
|
|
<property name="fileNamePattern" value="\\.gif$"/>
|
|
</module>
|
|
</source>
|
|
<p>
|
|
OR:
|
|
</p>
|
|
<source>
|
|
<module name="RegexpOnFilename">
|
|
<property name="fileNamePattern" value="."/>
|
|
<property name="fileExtensions" value="gif"/>
|
|
</module>
|
|
</source>
|
|
<p>
|
|
To configure the check to only allow property and xml files to be located in the resource folder:
|
|
</p>
|
|
<source>
|
|
<module name="RegexpOnFilename">
|
|
<property name="folderPattern" value="[\\/]src[\\/]\\w+[\\/]resources[\\/]"/>
|
|
<property name="match" value="false"/>
|
|
<property name="fileExtensions" value="properties, xml"/>
|
|
</module>
|
|
</source>
|
|
<p>
|
|
To configure the check to only allow Java and XML files in your folders use the below.
|
|
</p>
|
|
<source>
|
|
<module name="RegexpOnFilename">
|
|
<property name="fileNamePattern" value="\\.(java|xml)$"/>
|
|
<property name="match" value="false"/>
|
|
</module>
|
|
</source>
|
|
<p>
|
|
To configure the check to only allow Java and XML files only in your source folder
|
|
and ignore any other folders:<br />
|
|
<b>Note:</b> 'folderPattern' must be specified if checkstyle is analyzing more than
|
|
the normal source folder, like the 'bin' folder where class files can be located.
|
|
</p>
|
|
<source>
|
|
<module name="RegexpOnFilename">
|
|
<property name="folderPattern" value="[\\/]src[\\/]"/>
|
|
<property name="fileNamePattern" value="\\.(java|xml)$"/>
|
|
<property name="match" value="false"/>
|
|
</module>
|
|
</source>
|
|
<p>
|
|
To configure the check to only allow file names to be camel case:
|
|
</p>
|
|
<source>
|
|
<module name="RegexpOnFilename">
|
|
<property name="fileNamePattern" value="^([A-Z][a-z0-9]+\.?)+$"/>
|
|
<property name="match" value="false"/>
|
|
<property name="ignoreFileNameExtensions" value="true"/>
|
|
</module>
|
|
</source>
|
|
</subsection>
|
|
|
|
<subsection name="Example of Usage">
|
|
<ul>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+RegexpOnFilename">
|
|
Checkstyle Style</a>
|
|
</li>
|
|
</ul>
|
|
</subsection>
|
|
|
|
<subsection name="Error Messages">
|
|
<ul>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fregexp+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22regexp.filename.match%22">
|
|
regexp.filename.match</a>
|
|
</li>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fregexp+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22regexp.filename.mismatch%22">
|
|
regexp.filename.mismatch</a>
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
All messages can be customized if the default message doesn't suite you.
|
|
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
|
|
</p>
|
|
</subsection>
|
|
|
|
<subsection name="Package">
|
|
<p>
|
|
com.puppycrawl.tools.checkstyle.checks.regexp
|
|
</p>
|
|
</subsection>
|
|
|
|
<subsection name="Parent Module">
|
|
<p>
|
|
<a href="config.html#Checker">Checker</a>
|
|
</p>
|
|
</subsection>
|
|
</section>
|
|
|
|
<section name="RegexpSingleline">
|
|
<subsection name="Description">
|
|
<p>
|
|
A check for detecting single lines that match a supplied
|
|
regular expression. Works with any file type.
|
|
</p>
|
|
|
|
<p>
|
|
Rationale: This check can be used to prototype checks and to
|
|
find common bad practice such as calling <code>ex.printStacktrace()</code>, <code>
|
|
System.out.println()</code>, <code>System.exit()</code>, etc.
|
|
</p>
|
|
</subsection>
|
|
|
|
<subsection name="Properties">
|
|
<table>
|
|
<tr>
|
|
<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><code>^$</code> (empty)</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><code>""</code>(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><code>false</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>minimum</td>
|
|
<td>The minimum number of matches required in each file.</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td><code>0</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>maximum</td>
|
|
<td>The maximum number of matches required in each file.</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td><code>0</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>fileExtensions</td>
|
|
<td>file type extension of files to process</td>
|
|
<td><a href="property_types.html#stringSet">String Set</a></td>
|
|
<td><code>{}</code></td>
|
|
</tr>
|
|
</table>
|
|
</subsection>
|
|
|
|
<subsection name="Examples">
|
|
<p>
|
|
To configure the check to find trailing whitespace at the end
|
|
of a line:
|
|
</p>
|
|
<source>
|
|
<module name="RegexpSingleline">
|
|
<!-- \s matches whitespace character, $ matches end of line. -->
|
|
<property name="format" value="\s+$"/>
|
|
</module>
|
|
</source>
|
|
|
|
<p>
|
|
To configure the check to find trailing whitespace at the end
|
|
of a line, with some <i>slack</i> of allowing two occurrences
|
|
per file:
|
|
</p>
|
|
<source>
|
|
<module name="RegexpSingleline">
|
|
<property name="format" value="\s+$"/>
|
|
<!-- next line not required as 0 is the default -->
|
|
<property name="minimum" value="0"/>
|
|
<property name="maximum" value="2"/>
|
|
</module>
|
|
</source>
|
|
|
|
<p>
|
|
An example of how to configure the check to make sure a copyright
|
|
statement is included in the file:
|
|
</p>
|
|
<source>
|
|
<module name="RegexpSingleline">
|
|
<property name="format" value="This file is copyrighted"/>
|
|
<property name="minimum" value="1"/>
|
|
<!-- Need to specify a maximum, so 10 times is more than enough. -->
|
|
<property name="maximum" value="10"/>
|
|
</module>
|
|
</source>
|
|
</subsection>
|
|
|
|
<subsection name="Example of Usage">
|
|
<ul>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+RegexpSingleline">
|
|
Checkstyle Style</a>
|
|
</li>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Asun_checks.xml+repo%3Acheckstyle%2Fcheckstyle+RegexpSingleline">
|
|
Sun Style</a>
|
|
</li>
|
|
</ul>
|
|
</subsection>
|
|
|
|
<subsection name="Error Messages">
|
|
<ul>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fregexp+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22regexp.exceeded%22">
|
|
regexp.exceeded</a>
|
|
</li>
|
|
</ul>
|
|
<ul>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fregexp+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22regexp.minimum%22">
|
|
regexp.minimum</a>
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
All messages can be customized if the default message doesn't suite you.
|
|
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
|
|
</p>
|
|
</subsection>
|
|
|
|
<subsection name="Package">
|
|
<p>
|
|
com.puppycrawl.tools.checkstyle.checks.regexp
|
|
</p>
|
|
</subsection>
|
|
|
|
<subsection name="Parent Module">
|
|
<p>
|
|
<a href="config.html#Checker">Checker</a>
|
|
</p>
|
|
</subsection>
|
|
</section>
|
|
|
|
<section name="RegexpSinglelineJava">
|
|
<subsection name="Description">
|
|
<p>
|
|
This class is variation on <a
|
|
href="#RegexpSingleline">RegexpSingleline</a> for detecting
|
|
single lines that match a supplied regular expression in Java files. It supports suppressing matches in Java comments.
|
|
</p>
|
|
</subsection>
|
|
|
|
<subsection name="Properties">
|
|
<table>
|
|
<tr>
|
|
<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><code>^$</code> (empty)</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><code>""</code>(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><code>false</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>minimum</td>
|
|
<td>The minimum number of matches required in each file.</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td><code>0</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>maximum</td>
|
|
<td>The maximum number of matches required in each file.</td>
|
|
<td><a href="property_types.html#integer">Integer</a></td>
|
|
<td><code>0</code></td>
|
|
</tr>
|
|
<tr>
|
|
<td>ignoreComments</td>
|
|
<td>Controls whether to ignore text in comments when searching.</td>
|
|
<td><a href="property_types.html#boolean">Boolean</a></td>
|
|
<td><code>false</code></td>
|
|
</tr>
|
|
</table>
|
|
</subsection>
|
|
|
|
<subsection name="Examples">
|
|
<p>
|
|
To configure the check for calls to <code>System.out.println</code>, except in comments:
|
|
</p>
|
|
<source>
|
|
<module name="RegexpSinglelineJava">
|
|
<!-- . matches any character, so we need to
|
|
escape it and use \. to match dots. -->
|
|
<property name="format" value="System\.out\.println"/>
|
|
<property name="ignoreComments" value="true"/>
|
|
</module>
|
|
</source>
|
|
|
|
<p>
|
|
To configure the check to find case-insensitive occurrences of
|
|
"debug":
|
|
</p>
|
|
<source>
|
|
<module name="RegexpSinglelineJava">
|
|
<property name="format" value="debug"/>
|
|
<property name="ignoreCase" value="true"/>
|
|
</module>
|
|
</source>
|
|
</subsection>
|
|
|
|
<subsection name="Example of Usage">
|
|
<ul>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Aconfig+filename%3Acheckstyle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+RegexpSinglelineJava">
|
|
Checkstyle Style</a>
|
|
</li>
|
|
</ul>
|
|
</subsection>
|
|
|
|
<subsection name="Error Messages">
|
|
<ul>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fregexp+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22regexp.exceeded%22">
|
|
regexp.exceeded</a>
|
|
</li>
|
|
</ul>
|
|
<ul>
|
|
<li>
|
|
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources%2Fcom%2Fpuppycrawl%2Ftools%2Fcheckstyle%2Fchecks%2Fregexp+filename%3Amessages*.properties+repo%3Acheckstyle%2Fcheckstyle+%22regexp.minimum%22">
|
|
regexp.minimum</a>
|
|
</li>
|
|
</ul>
|
|
<p>
|
|
All messages can be customized if the default message doesn't suite you.
|
|
Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
|
|
</p>
|
|
</subsection>
|
|
|
|
<subsection name="Package">
|
|
<p>
|
|
com.puppycrawl.tools.checkstyle.checks.regexp
|
|
</p>
|
|
</subsection>
|
|
|
|
<subsection name="Parent Module">
|
|
<p>
|
|
<a href="config.html#TreeWalker">TreeWalker</a>
|
|
</p>
|
|
</subsection>
|
|
</section>
|
|
</body>
|
|
</document>
|