All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.hm.hafner.analysis.parser.checkstyle.config_regexp.xml Maven / Gradle / Ivy

<?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" id="Regexp_Description">
        <p>Since Checkstyle 4.0</p>
        <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 &lt; symbol you need to enter &amp;lt;. The regular
          expression should be entered on one line.
        </p>
      </subsection>

      <subsection name="Properties" id="Regexp_Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
            <th>since</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>
            <td>4.0</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>null</code></td>
            <td>4.0</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>
            <td>4.0</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>0</code></td>
            <td>4.0</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>
            <td>4.0</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>
            <td>4.0</td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples" id="Regexp_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>
&lt;module name="Regexp"&gt;
  &lt;property name="format" value="// This code is copyrighted"/&gt;
&lt;/module&gt;
        </source>
        <p> Your statement may be multiline. </p>
        <source>
// This code is copyrighted
// (c) MyCompany
        </source>
        <p> Then the check would be. </p>
        <source>
&lt;module name="Regexp"&gt;
  &lt;property name="format" value="// This code is copyrighted\n// \(c\) MyCompany"/&gt;
&lt;/module&gt;
        </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>
&lt;module name="Regexp"&gt;
  &lt;property name="format" value="// This code is copyrighted\n// \(c\) MyCompany"/&gt;
  &lt;property name=&quot;duplicateLimit&quot; value=&quot;0&quot;/&gt;
&lt;/module&gt;
        </source>
        <p>
          It can also be useful to attach a meaningful message to the check:
        </p>
        <source>
&lt;module name="Regexp"&gt;
  &lt;property name="format" value="// This code is copyrighted\n// \(c\) MyCompany"/&gt;
  &lt;property name=&quot;message&quot; value=&quot;Copyright&quot;/&gt;
&lt;/module&gt;
        </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>
&lt;module name=&quot;Regexp&quot;&gt;
  &lt;!-- . matches any character, so we need to escape it and use \. to match dots. --&gt;
  &lt;property name="format" value="System\.out\.println"/&gt;
  &lt;property name="illegalPattern" value="true"/&gt;
&lt;/module&gt;
        </source>
        <p>
          You may want to make the above check ignore comments, like this:
        </p>
        <source>
&lt;module name=&quot;Regexp&quot;&gt;
  &lt;property name="format" value="System\.out\.println"/&gt;
  &lt;property name="illegalPattern" value="true"/&gt;
  &lt;property name="ignoreComments" value="true"/&gt;
&lt;/module&gt;
        </source>
        <p>
          An example of how to configure the check to find trailing whitespace
          at the end of a line:
        </p>
        <source>
&lt;module name=&quot;Regexp&quot;&gt;
  &lt;property name="format" value="[ \t]+$"/&gt;
  &lt;property name="illegalPattern" value="true"/&gt;
  &lt;property name=&quot;message&quot; value=&quot;Trailing whitespace&quot;/&gt;
&lt;/module&gt;
        </source>
        <p>
          An example of how to configure the check to find case-insensitive
          occurrences of &quot;debug&quot;:
        </p>
        <source>
&lt;module name=&quot;Regexp&quot;&gt;
  &lt;property name="format" value="(?i)debug"/&gt;
  &lt;property name="illegalPattern" value="true"/&gt;
&lt;/module&gt;
        </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>
&lt;module name=&quot;Regexp&quot;&gt;
  &lt;property name="format" value="(?i)debug"/&gt;
  &lt;property name="illegalPattern" value="true"/&gt;
  &lt;property name="errorLimit" value="1000"/&gt;
&lt;/module&gt;
        </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>
&lt;module name=&quot;Regexp&quot;&gt;
  &lt;property
    name=&quot;format&quot;
    value=&quot;\A// Copyright \(C\) \d\d\d\d MyCompany\n// All rights reserved&quot;/&gt;
&lt;/module&gt;
        </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>
&lt;module name=&quot;Regexp&quot;&gt;
  &lt;property
    name=&quot;format&quot;
    value=&quot;\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)* \*/&quot;/&gt;
&lt;/module&gt;
        </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;

/**
*
* &lt;P&gt;
*   &lt;I&gt;This software is the confidential and proprietary information of
*   ACME (&lt;B&gt;"Confidential Information"&lt;/B&gt;). 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.&lt;/I&gt;
* &lt;/P&gt;
*
* &amp;#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>
&lt;module name=&quot;Regexp&quot;&gt;
  &lt;property
    name=&quot;format&quot;
    value=&quot;\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 \* \(&amp;quot;Confidential Information&amp;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)&quot;/&gt;
  &lt;property name=&quot;message&quot; value=&quot;Correct header not found&quot;/&gt;
&lt;/module&gt;
        </source>
        <p>
          This checks for the presence of a copyright notice within the class
          javadoc, lines 24 to 37.
        </p>
        <source>
&lt;module name=&quot;Regexp&quot;&gt;
  &lt;property
    name=&quot;format&quot;
    value=&quot;(/\*\*\n)( \*.*\n)*( \* &amp;lt;P&amp;gt;\n \*   &amp;lt;I&amp;gt;
    This software is the confidential and proprietary information of\n
    \*   ACME \(&amp;lt;B&amp;gt;&amp;quot;Confidential Information&amp;quot;&amp;lt;/B&amp;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\.&amp;lt;/I&amp;gt;\n
    \* &amp;lt;/P&amp;gt;\n \*\n \* &amp;#169; copyright \d\d\d\d ACME\n
    \*\n \* @author .*)(\n\s\*.*)*/\n[\w|\s]*( class | interface )&quot;/&gt;
  &lt;property name=&quot;message&quot;
    value=&quot;Copyright in class/interface Javadoc&quot;/&gt;
  &lt;property name=&quot;duplicateLimit&quot; value=&quot;0&quot;/&gt;
&lt;/module&gt;
        </source>
        <p>
          <b>Note:</b> To search for things that mean something in XML, like
          &lt; you need to escape them like &amp;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" id="Regexp_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" id="Regexp_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 suit you.
          Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
        </p>
      </subsection>

      <subsection name="Package" id="Regexp_Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.regexp
        </p>
      </subsection>

      <subsection name="Parent Module" id="Regexp_Parent_Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>

    <section name="RegexpMultiline">
      <subsection name="Description" id="RegexpMultiline_Description">
        <p>Since Checkstyle 5.0</p>
        <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" id="RegexpMultiline_Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
            <th>since</th>
          </tr>
          <tr>
            <td>format</td>
            <td>illegal pattern</td>
            <td><a href="property_types.html#regexp">Regular Expression</a></td>
            <td><code>&quot;$.&quot;</code></td>
            <td>5.0</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>null</code></td>
            <td>5.0</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>
            <td>5.0</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>
            <td>5.0</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>
            <td>5.0</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>all files</code></td>
            <td>5.0</td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples" id="RegexpMultiline_Examples">
        <p>
          To configure the check to find calls to print to the console:
        </p>
        <source>
&lt;module name=&quot;RegexpMultiline&quot;&gt;
  &lt;property name=&quot;format&quot;
    value=&quot;System\.(out)|(err)\.print(ln)?\(&quot;/&gt;
&lt;/module&gt;
        </source>
      </subsection>

      <subsection name="Example of Usage" id="RegexpMultiline_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" id="RegexpMultiline_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 suit you.
          Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
        </p>
      </subsection>

      <subsection name="Package" id="RegexpMultiline_Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.regexp
        </p>
      </subsection>

      <subsection name="Parent Module" id="RegexpMultiline_Parent_Module">
        <p>
          <a href="config.html#Checker">Checker</a>
        </p>
      </subsection>
    </section>

    <section name="RegexpOnFilename">
      <subsection name="Description" id="RegexpOnFilename_Description">
        <p>Since Checkstyle 6.15</p>
        <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 conjunction 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" id="RegexpOnFilename_Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
            <th>since</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>
            <td>6.15</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>
            <td>6.15</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>
            <td>6.15</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>
            <td>6.15</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>all files</code></td>
            <td>6.15</td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples" id="RegexpOnFilename_Examples">
        <p>
          To configure the check to report file names that contain a space:
        </p>
        <source>
&lt;module name=&quot;RegexpOnFilename&quot;/&gt;
        </source>
        <p>
          To configure the check to force picture files to not be 'gif':
        </p>
        <source>
&lt;module name=&quot;RegexpOnFilename&quot;&gt;
  &lt;property name=&quot;fileNamePattern&quot; value=&quot;\.gif$&quot;/&gt;
&lt;/module&gt;
        </source>
        <p>
          OR:
        </p>
        <source>
&lt;module name=&quot;RegexpOnFilename&quot;&gt;
  &lt;property name=&quot;fileNamePattern&quot; value=&quot;.&quot;/&gt;
  &lt;property name=&quot;fileExtensions&quot; value=&quot;gif&quot;/&gt;
&lt;/module&gt;
        </source>
        <p>
          To configure the check to only allow property and xml files to be located
          in the resource folder:
        </p>
        <source>
&lt;module name=&quot;RegexpOnFilename&quot;&gt;
  &lt;property name=&quot;folderPattern&quot;
    value=&quot;[\\/]src[\\/]\w+[\\/]resources[\\/]&quot;/&gt;
  &lt;property name=&quot;match&quot; value=&quot;false&quot;/&gt;
  &lt;property name=&quot;fileExtensions&quot; value=&quot;properties, xml&quot;/&gt;
&lt;/module&gt;
        </source>
        <p>
          To configure the check to only allow Java and XML files in your folders use the below.
        </p>
        <source>
&lt;module name=&quot;RegexpOnFilename&quot;&gt;
  &lt;property name=&quot;fileNamePattern&quot; value=&quot;\.(java|xml)$&quot;/&gt;
  &lt;property name=&quot;match&quot; value=&quot;false&quot;/&gt;
&lt;/module&gt;
        </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>
&lt;module name=&quot;RegexpOnFilename&quot;&gt;
  &lt;property name=&quot;folderPattern&quot; value=&quot;[\\/]src[\\/]&quot;/&gt;
  &lt;property name=&quot;fileNamePattern&quot; value=&quot;\.(java|xml)$&quot;/&gt;
  &lt;property name=&quot;match&quot; value=&quot;false&quot;/&gt;
&lt;/module&gt;
        </source>
        <p>
          To configure the check to only allow file names to be camel case:
        </p>
        <source>
&lt;module name=&quot;RegexpOnFilename&quot;&gt;
  &lt;property name=&quot;fileNamePattern&quot; value=&quot;^([A-Z][a-z0-9]+\.?)+$&quot;/&gt;
  &lt;property name=&quot;match&quot; value=&quot;false&quot;/&gt;
  &lt;property name=&quot;ignoreFileNameExtensions&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
        </source>
      </subsection>

      <subsection name="Example of Usage" id="RegexpOnFilename_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" id="RegexpOnFilename_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 suit you.
          Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
        </p>
      </subsection>

      <subsection name="Package" id="RegexpOnFilename_Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.regexp
        </p>
      </subsection>

      <subsection name="Parent Module" id="RegexpOnFilename_Parent_Module">
        <p>
          <a href="config.html#Checker">Checker</a>
        </p>
      </subsection>
    </section>

    <section name="RegexpSingleline">
      <subsection name="Description" id="RegexpSingleline_Description">
        <p>Since Checkstyle 5.0</p>
        <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" id="RegexpSingleline_Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
            <th>since</th>
          </tr>
          <tr>
            <td>format</td>
            <td>illegal pattern</td>
            <td><a href="property_types.html#regexp">Regular Expression</a></td>
            <td><code>&quot;$.&quot;</code></td>
            <td>5.0</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>null</code></td>
            <td>5.0</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>
            <td>5.0</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>
            <td>5.0</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>
            <td>5.0</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>all files</code></td>
            <td>5.0</td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples" id="RegexpSingleline_Examples">
        <p>
          To configure the check to find trailing whitespace at the end
          of a line:
        </p>
        <source>
&lt;module name=&quot;RegexpSingleline&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;
        </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>
&lt;module name=&quot;RegexpSingleline&quot;&gt;
  &lt;property name=&quot;format&quot; value=&quot;\s+$&quot;/&gt;
  &lt;!-- next line not required as 0 is the default --&gt;
  &lt;property name=&quot;minimum&quot; value=&quot;0&quot;/&gt;
  &lt;property name=&quot;maximum&quot; value=&quot;2&quot;/&gt;
&lt;/module&gt;
        </source>

        <p>
          An example of how to configure the check to make sure a copyright
          statement is included in the file:
        </p>
        <source>
&lt;module name=&quot;RegexpSingleline&quot;&gt;
  &lt;property name="format" value="This file is copyrighted"/&gt;
  &lt;property name=&quot;minimum&quot; value=&quot;1&quot;/&gt;
  &lt;!--  Need to specify a maximum, so 10 times is more than enough. --&gt;
  &lt;property name=&quot;maximum&quot; value=&quot;10&quot;/&gt;
&lt;/module&gt;
        </source>
      </subsection>

      <subsection name="Example of Usage" id="RegexpSingleline_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" id="RegexpSingleline_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 suit you.
          Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
        </p>
      </subsection>

      <subsection name="Package" id="RegexpSingleline_Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.regexp
        </p>
      </subsection>

      <subsection name="Parent Module" id="RegexpSingleline_Parent_Module">
        <p>
          <a href="config.html#Checker">Checker</a>
        </p>
      </subsection>
    </section>

    <section name="RegexpSinglelineJava">
      <subsection name="Description" id="RegexpSinglelineJava_Description">
        <p>Since Checkstyle 6.0</p>
        <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" id="RegexpSinglelineJava_Properties">
        <table>
          <tr>
            <th>name</th>
            <th>description</th>
            <th>type</th>
            <th>default value</th>
            <th>since</th>
          </tr>
          <tr>
            <td>format</td>
            <td>illegal pattern</td>
            <td><a href="property_types.html#regexp">Regular Expression</a></td>
            <td><code>&quot;$.&quot;</code></td>
            <td>5.0</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>null</code></td>
            <td>6.0</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>
            <td>5.0</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>
            <td>5.0</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>
            <td>5.0</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>
            <td>5.0</td>
          </tr>
        </table>
      </subsection>

      <subsection name="Examples" id="RegexpSinglelineJava_Examples">
        <p>
          To configure the check for calls to <code>System.out.println</code>, except in comments:
        </p>
        <source>
&lt;module name=&quot;RegexpSinglelineJava&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;property name=&quot;ignoreComments&quot; value=&quot;true&quot;/&gt;
&lt;/module&gt;
        </source>

        <p>
          To configure the check to find case-insensitive occurrences of
          &quot;debug&quot;:
        </p>
        <source>
&lt;module name=&quot;RegexpSinglelineJava&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;
        </source>
      </subsection>

      <subsection name="Example of Usage" id="RegexpSinglelineJava_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" id="RegexpSinglelineJava_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 suit you.
          Please <a href="config.html#Custom_messages">see the documentation</a> to learn how to.
        </p>
      </subsection>

      <subsection name="Package" id="RegexpSinglelineJava_Package">
        <p>
          com.puppycrawl.tools.checkstyle.checks.regexp
        </p>
      </subsection>

      <subsection name="Parent Module" id="RegexpSinglelineJava_Parent_Module">
        <p>
          <a href="config.html#TreeWalker">TreeWalker</a>
        </p>
      </subsection>
    </section>
  </body>
</document>




© 2015 - 2025 Weber Informatics LLC | Privacy Policy