Code examples of filters' usage, issue #289
This commit is contained in:
parent
dcb3029c00
commit
b7322b7454
|
|
@ -752,8 +752,7 @@
|
|||
</source>
|
||||
|
||||
<p>
|
||||
As another example, imagine that a configuration contains the
|
||||
following:
|
||||
As another example to suppress Check by module id:
|
||||
</p>
|
||||
|
||||
<source>
|
||||
|
|
@ -784,6 +783,54 @@
|
|||
<suppress id="stringEqual" files="SomeTestCode.java"/>
|
||||
</source>
|
||||
|
||||
<p>
|
||||
Suppress checks for hidden files and folders:
|
||||
</p>
|
||||
|
||||
<source>
|
||||
<suppress files="[/\\]\..+" checks=".*"/>
|
||||
</source>
|
||||
|
||||
<p>
|
||||
Suppress checks for Maven-generated code:
|
||||
</p>
|
||||
|
||||
<source>
|
||||
<suppress files="[/\\]target[/\\]" checks=".*"/>
|
||||
</source>
|
||||
|
||||
<p>
|
||||
Suppress checks for archives, classes and other binary files:
|
||||
</p>
|
||||
|
||||
<source>
|
||||
<suppress files=".+\.(?:jar|zip|war|class|tar|bin)$" checks=".*"/>
|
||||
</source>
|
||||
|
||||
<p>
|
||||
Suppress checks for image files:
|
||||
</p>
|
||||
|
||||
<source>
|
||||
<suppress files=".+\.(?:png|gif|jpg|jpeg)$" checks=".*"/>
|
||||
</source>
|
||||
|
||||
<p>
|
||||
Suppress checks for non-java text files:
|
||||
</p>
|
||||
|
||||
<source>
|
||||
<suppress files=".+\.(?:txt|xml|csv|sh|thrift|html|sql|eot|ttf|woff|css|png)$" checks=".*"/>
|
||||
</source>
|
||||
|
||||
<p>
|
||||
Suppress all checks generated sources:
|
||||
</p>
|
||||
|
||||
<source>
|
||||
<suppress checks="FileLength"files="com[\\/]mycompany[\\/]app[\\/].*IT.java"/>
|
||||
</source>
|
||||
|
||||
</subsection>
|
||||
|
||||
<subsection name="SuppressionCommentFilter">
|
||||
|
|
@ -903,6 +950,17 @@
|
|||
</module>
|
||||
</source>
|
||||
|
||||
<source>
|
||||
//BEGIN GENERATED CODE
|
||||
@Override
|
||||
public boolean equals(Object obj) { ... } // No violation events will be reported
|
||||
|
||||
@Override
|
||||
public int hashCode() { ... } // No violation events will be reported
|
||||
//END GENERATED CODE
|
||||
. . .
|
||||
</source>
|
||||
|
||||
<p>
|
||||
To configure a filter so that <code>// stop constant
|
||||
check</code> and <code>// resume constant check</code> marks
|
||||
|
|
@ -917,6 +975,14 @@
|
|||
</module>
|
||||
</source>
|
||||
|
||||
<source>
|
||||
//stop constant check
|
||||
public static final int someConstant; // won't warn here
|
||||
//resume constant check
|
||||
public static final int someConstant; // will warn here as constant's name doesn't match the
|
||||
// pattern "^[A-Z][A-Z0-9]*$"
|
||||
</source>
|
||||
|
||||
<p>
|
||||
To configure a filter so that <code>UNUSED OFF:
|
||||
<i>var</i></code> and <code>UNUSED ON: <i>var</i></code> marks a
|
||||
|
|
@ -933,8 +999,21 @@
|
|||
</module>
|
||||
</source>
|
||||
|
||||
<source>
|
||||
private static void foo(int a, int b) // UNUSED OFF: b
|
||||
{
|
||||
System.out.println(a);
|
||||
}
|
||||
|
||||
private static void foo1(int a, int b) // UNUSED ON: a
|
||||
{
|
||||
System.out.println(b);
|
||||
}
|
||||
</source>
|
||||
|
||||
<p>
|
||||
To configure a filter so that <code>CSOFF: <i>regexp</i></code>
|
||||
To configure a filter so that name of suppressed check mentioned
|
||||
in comment <code>CSOFF: <i>regexp</i></code>
|
||||
and <code>CSN: <i>regexp</i></code> mark a matching check:
|
||||
</p>
|
||||
|
||||
|
|
@ -946,6 +1025,11 @@
|
|||
</module>
|
||||
</source>
|
||||
|
||||
<source>
|
||||
public static final int lowerCaseConstant; // CSOFF: ConstantNameCheck
|
||||
public static final int lowerCaseConstant1; // CSON: ConstantNameCheck
|
||||
</source>
|
||||
|
||||
<p>
|
||||
To configure a filter to suppress all audit events between a comment
|
||||
containing <code>CHECKSTYLE_OFF: ALL</code> and a comment containing
|
||||
|
|
@ -954,11 +1038,18 @@
|
|||
|
||||
<source>
|
||||
<module name="SuppressionCommentFilter">
|
||||
<property name="offCommentFormat" value="CHECKSTYLE_OFF: ALL"/>
|
||||
<property name="onCommentFormat" value="CHECKSTYLE_ON: ALL"/>
|
||||
<property name="offCommentFormat" value="CHECKSTYLE_OFF: ALMOST_ALL"/>
|
||||
<property name="onCommentFormat" value="CHECKSTYLE_ON: ALMOST_ALL"/>
|
||||
<property name="checkFormat" value="^((?!(EqualsHashCode)).)*$"/>
|
||||
</module>
|
||||
</source>
|
||||
|
||||
<source>
|
||||
public static final int array []; // CHECKSTYLE_OFF: ALL
|
||||
private String [] strArray;
|
||||
private int array1 []; // CHECKSTYLE_ON: ALL
|
||||
</source>
|
||||
|
||||
</subsection>
|
||||
|
||||
<subsection name="SuppressWithNearbyCommentFilter">
|
||||
|
|
@ -1054,6 +1145,10 @@
|
|||
<module name="SuppressWithNearbyCommentFilter"/>
|
||||
</source>
|
||||
|
||||
<source>
|
||||
private int [] array; // SUPPRESS CHECKSTYLE
|
||||
</source>
|
||||
|
||||
<p>
|
||||
To configure a filter to suppress all audit events on any line
|
||||
containing the comment <code>CHECKSTYLE IGNORE THIS LINE</code>:
|
||||
|
|
@ -1067,6 +1162,10 @@
|
|||
</module>
|
||||
</source>
|
||||
|
||||
<source>
|
||||
public static final int lowerCaseConstant; // CHECKSTYLE IGNORE THIS LINE
|
||||
</source>
|
||||
|
||||
<p>
|
||||
To configure a filter so that
|
||||
<code>// OK to catch (Throwable|Exception|RuntimeException) here</code>
|
||||
|
|
@ -1083,6 +1182,15 @@
|
|||
</module>
|
||||
</source>
|
||||
|
||||
<source>
|
||||
. . .
|
||||
catch (RuntimeException re) {
|
||||
// OK to catch RuntimeException here
|
||||
}
|
||||
catch (Throwable th) { ... }
|
||||
. . .
|
||||
</source>
|
||||
|
||||
<p>
|
||||
To configure a filter so that <code>CHECKSTYLE IGNORE <i>check</i> FOR NEXT <i>var</i> LINES</code>
|
||||
avoids triggering any audits for the given check for the current line and the next <i>var</i> lines
|
||||
|
|
@ -1097,6 +1205,49 @@
|
|||
</module>
|
||||
</source>
|
||||
|
||||
<source>
|
||||
public static final int lowerCaseConstant; // CHECKSTYLE IGNORE ConstantNameCheck FOR NEXT 3 LINES
|
||||
public static final int lowerCaseConstant1;
|
||||
public static final int lowerCaseConstant2;
|
||||
public static final int lowerCaseConstant3;
|
||||
public static final int lowerCaseConstant4; // will warn here
|
||||
</source>
|
||||
|
||||
<p>
|
||||
To configure a filter to avoid any audits on code like:
|
||||
</p>
|
||||
|
||||
<source>
|
||||
<module name="SuppressWithNearbyCommentFilter">
|
||||
<property name="commentFormat" value="ALLOW (\\w+) ON PREVIOUS LINE"/>
|
||||
<property name="checkFormat" value="$1"/>
|
||||
<property name="influenceFormat" value="-1"/>
|
||||
</module>
|
||||
</source>
|
||||
|
||||
<source>
|
||||
private int D2;
|
||||
// ALLOW MemberName ON PREVIOUS LINE
|
||||
. . .
|
||||
</source>
|
||||
|
||||
<p>
|
||||
To configure a filter to allow suppress one or more Checks(separated by "|")
|
||||
and demand comment no less than 14 symbols:
|
||||
</p>
|
||||
|
||||
<source>
|
||||
<module name="SuppressWithNearbyCommentFilter">
|
||||
<property name="commentFormat" value="@cs.suppress \[(\w(\|\w)*)\] \w[-\.'`,:;\w ]{14,}"/>
|
||||
<property name="checkFormat" value="$1"/>
|
||||
<property name="influenceFormat" value="1"/>
|
||||
</module>
|
||||
</source>
|
||||
|
||||
<source>
|
||||
public static final int [] array; // @cs.suppress ConstantName | NoWhitespaceAfter
|
||||
</source>
|
||||
|
||||
</subsection>
|
||||
|
||||
<subsection name="SuppressWarningsFilter">
|
||||
|
|
@ -1121,7 +1272,8 @@
|
|||
the filter. Because of that, a configuration that includes
|
||||
this filter must also include
|
||||
<code>SuppressWarningsHolder</code> as a child module of the
|
||||
<code>TreeWalker</code>.
|
||||
<code>TreeWalker</code>. Name of check in annotation should
|
||||
be written in lower case with any dotted prefix or "Check" suffix removed.
|
||||
</p>
|
||||
|
||||
<h5>SuppressWarningsFilter Properties</h5>
|
||||
|
|
@ -1133,18 +1285,26 @@
|
|||
the filter.
|
||||
</p>
|
||||
<source>
|
||||
<module name="TreeWalker">
|
||||
...
|
||||
<module name="SuppressWarningsHolder" />
|
||||
...
|
||||
</module>
|
||||
<module name="TreeWalker">
|
||||
...
|
||||
<module name="SuppressWarningsHolder" />
|
||||
...
|
||||
</module>
|
||||
</source>
|
||||
|
||||
<p>To configure filter to suppress audit events for annotations add:</p>
|
||||
<source>
|
||||
<module name="SuppressWarningsFilter" />
|
||||
<module name="SuppressWarningsFilter" />
|
||||
</source>
|
||||
|
||||
<source>
|
||||
@SuppressWarnings({"membername"})
|
||||
private int J; // should NOT fail MemberNameCheck
|
||||
|
||||
@SuppressWarnings({"membername"})
|
||||
@SuppressWarnings({"nowhitespaceafter"})
|
||||
private int [] ARRAY; // should NOT fail MemberNameCheck and NoWhitespaceAfterCheck
|
||||
</source>
|
||||
</subsection>
|
||||
|
||||
</section>
|
||||
|
|
|
|||
Loading…
Reference in New Issue