diff --git a/src/xdocs/config.xml b/src/xdocs/config.xml index e68381ccb..6fb9f0784 100644 --- a/src/xdocs/config.xml +++ b/src/xdocs/config.xml @@ -752,8 +752,7 @@

- As another example, imagine that a configuration contains the - following: + As another example to suppress Check by module id:

@@ -784,6 +783,54 @@ <suppress id="stringEqual" files="SomeTestCode.java"/> +

+ Suppress checks for hidden files and folders: +

+ + +<suppress files="[/\\]\..+" checks=".*"/> + + +

+ Suppress checks for Maven-generated code: +

+ + +<suppress files="[/\\]target[/\\]" checks=".*"/> + + +

+ Suppress checks for archives, classes and other binary files: +

+ + +<suppress files=".+\.(?:jar|zip|war|class|tar|bin)$" checks=".*"/> + + +

+ Suppress checks for image files: +

+ + +<suppress files=".+\.(?:png|gif|jpg|jpeg)$" checks=".*"/> + + +

+ Suppress checks for non-java text files: +

+ + +<suppress files=".+\.(?:txt|xml|csv|sh|thrift|html|sql|eot|ttf|woff|css|png)$" checks=".*"/> + + +

+ Suppress all checks generated sources: +

+ + +<suppress checks="FileLength"files="com[\\/]mycompany[\\/]app[\\/].*IT.java"/> + + @@ -903,6 +950,17 @@ </module> + +//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 +. . . + +

To configure a filter so that // stop constant check and // resume constant check marks @@ -917,6 +975,14 @@ </module> + +//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]*$" + +

To configure a filter so that UNUSED OFF: var and UNUSED ON: var marks a @@ -933,8 +999,21 @@ </module> + +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); +} + +

- To configure a filter so that CSOFF: regexp + To configure a filter so that name of suppressed check mentioned + in comment CSOFF: regexp and CSN: regexp mark a matching check:

@@ -946,6 +1025,11 @@ </module> + +public static final int lowerCaseConstant; // CSOFF: ConstantNameCheck +public static final int lowerCaseConstant1; // CSON: ConstantNameCheck + +

To configure a filter to suppress all audit events between a comment containing CHECKSTYLE_OFF: ALL and a comment containing @@ -954,11 +1038,18 @@ <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> + + +public static final int array []; // CHECKSTYLE_OFF: ALL +private String [] strArray; +private int array1 []; // CHECKSTYLE_ON: ALL + + @@ -1054,6 +1145,10 @@ <module name="SuppressWithNearbyCommentFilter"/> + +private int [] array; // SUPPRESS CHECKSTYLE + +

To configure a filter to suppress all audit events on any line containing the comment CHECKSTYLE IGNORE THIS LINE: @@ -1067,6 +1162,10 @@ </module> + +public static final int lowerCaseConstant; // CHECKSTYLE IGNORE THIS LINE + +

To configure a filter so that // OK to catch (Throwable|Exception|RuntimeException) here @@ -1083,6 +1182,15 @@ </module> + +. . . +catch (RuntimeException re) { + // OK to catch RuntimeException here +} +catch (Throwable th) { ... } +. . . + +

To configure a filter so that CHECKSTYLE IGNORE check FOR NEXT var LINES avoids triggering any audits for the given check for the current line and the next var lines @@ -1097,6 +1205,49 @@ </module> + +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 + + +

+ To configure a filter to avoid any audits on code like: +

+ + +<module name="SuppressWithNearbyCommentFilter"> + <property name="commentFormat" value="ALLOW (\\w+) ON PREVIOUS LINE"/> + <property name="checkFormat" value="$1"/> + <property name="influenceFormat" value="-1"/> +</module> + + + +private int D2; +// ALLOW MemberName ON PREVIOUS LINE +. . . + + +

+ To configure a filter to allow suppress one or more Checks(separated by "|") + and demand comment no less than 14 symbols: +

+ + +<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> + + + +public static final int [] array; // @cs.suppress ConstantName | NoWhitespaceAfter + +
@@ -1121,7 +1272,8 @@ the filter. Because of that, a configuration that includes this filter must also include SuppressWarningsHolder as a child module of the - TreeWalker. + TreeWalker. Name of check in annotation should + be written in lower case with any dotted prefix or "Check" suffix removed.

SuppressWarningsFilter Properties
@@ -1133,18 +1285,26 @@ the filter.

- <module name="TreeWalker"> - ... - <module name="SuppressWarningsHolder" /> - ... - </module> +<module name="TreeWalker"> + ... +<module name="SuppressWarningsHolder" /> + ... +</module>

To configure filter to suppress audit events for annotations add:

- <module name="SuppressWarningsFilter" /> +<module name="SuppressWarningsFilter" /> + +@SuppressWarnings({"membername"}) +private int J; // should NOT fail MemberNameCheck + +@SuppressWarnings({"membername"}) +@SuppressWarnings({"nowhitespaceafter"}) +private int [] ARRAY; // should NOT fail MemberNameCheck and NoWhitespaceAfterCheck +