SuppressionSingleFilter

Since Checkstyle 8.23

Description

Filter SuppressionSingleFilter suppresses audit events for Checks violations in the specified file, class, checks, message, module id, lines, and columns.

Rationale: To allow users to use suppressions configured in the same config as other modules. SuppressionFilter and SuppressionXpathFilter require a separate file.

Advice: If checkstyle configuration is used for several projects, single suppressions on common files/folders is better to put in checkstyle configuration as common rule. All suppression that are for specific file names is better to keep in project specific config file.

Attention: This filter only supports single suppression, and will need multiple instances if users wants to suppress multiple violations.

Notes

SuppressionSingleFilter can suppress Checks that have Treewalker or Checker as parent module.

Properties

name description type default value since
checks Define the RegExp for matching against the name of the check associated with an audit event. Pattern null 8.23
columns Specify a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer. String null 8.23
files Define the RegExp for matching against the file name associated with an audit event. Pattern null 8.23
id Specify a string matched against the ID of the check associated with an audit event. String null 8.23
lines Specify a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer. String null 8.23
message Define the RegExp for matching against the message of the check associated with an audit event. Pattern null 8.23

Examples

The following suppressions directs a SuppressionSingleFilter to reject JavadocStyleCheck violations for lines 82 and 108 to 122 of file AbstractComplexityCheck.java, and MagicNumberCheck violations for line 221 of file JavadocStyleCheck.java, and 'Missing a Javadoc comment' violations for all lines and files:

<module name="Checker">
  <module name="SuppressionSingleFilter">
    <property name="checks" value="JavadocStyleCheck"/>
    <property name="files" value="AbstractComplexityCheck.java"/>
    <property name="lines" value="82,108-122"/>
  </module>
  <module name="SuppressionSingleFilter">
    <property name="checks" value="MagicNumberCheck"/>
    <property name="files" value="JavadocStyleCheck.java"/>
    <property name="lines" value="221"/>
  </module>
  <module name="SuppressionSingleFilter">
    <property name="message" value="Missing a Javadoc comment"/>
  </module>
</module>
        

Suppress check by module id when config have two instances on the same check:

<module name="Checker">
  <module name="SuppressionSingleFilter">
    <property name="id" value="stringEqual"/>
    <property name="files" value="SomeTestCode.java"/>
  </module>
</module>
        

Suppress all checks for hidden files and folders:

<module name="Checker">
  <module name="SuppressionSingleFilter">
    <property name="files" value="[/\\]\..+"/>
    <property name="checks" value=".*"/>
  </module>
</module>
        

Suppress all checks for Maven-generated code:

<module name="Checker">
  <module name="SuppressionSingleFilter">
    <property name="files" value="[/\\]target[/\\]"/>
    <property name="checks" value=".*"/>
  </module>
</module>
        

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

<module name="Checker">
  <module name="SuppressionSingleFilter">
    <property name="files" value=".+\.(?:jar|zip|war|class|tar|bin)$"/>
    <property name="checks" value=".*"/>
  </module>
</module>
        

Suppress all checks for image files:

<module name="Checker">
  <module name="SuppressionSingleFilter">
    <property name="files" value=".+\.(?:png|gif|jpg|jpeg)$"/>
    <property name="checks" value=".*"/>
  </module>
</module>
        

Suppress all checks for non-java files:

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

Suppress all checks in generated sources:

<module name="Checker">
  <module name="SuppressionSingleFilter">
    <property name="files" value="com[\\/]mycompany[\\/]app[\\/]gen[\\/]"/>
    <property name="checks" value=".*"/>
  </module>
</module>
        

Suppress FileLength check on integration tests in certain folder:

<module name="Checker">
  <module name="SuppressionSingleFilter">
    <property name="files" value="com[\\/]mycompany[\\/]app[\\/].*IT.java"/>
    <property name="checks" value="FileLength"/>
  </module>
</module>
        

Suppress naming violations on variable named 'log' in all files:

<module name="Checker">
  <module name="SuppressionSingleFilter">
    <property name="message" value="Name 'log' must match pattern"/>
  </module>
</module>
        

Example of Usage

Package

com.puppycrawl.tools.checkstyle.filters

Parent Module

Checker