Class SuppressionSingleFilter
- java.lang.Object
-
- com.puppycrawl.tools.checkstyle.api.AutomaticBean
-
- com.puppycrawl.tools.checkstyle.filters.SuppressionSingleFilter
-
- All Implemented Interfaces:
Configurable
,Contextualizable
,Filter
public class SuppressionSingleFilter extends AutomaticBean implements Filter
Filter
SuppressionSingleFilter
suppresses audit events for Checks violations in the specified file, class, checks, message, module id, lines, and columns.Rationale: To allow users use suppressions configured in the same config with other modules. SuppressionFilter and SuppressionXpathFilter are require 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.
SuppressionSingleFilter can suppress Checks that have Treewalker or Checker as parent module.
-
Property
files
- Define the RegExp for matching against the file name associated with an audit event. Type isjava.util.regex.Pattern
. Default value isnull
. -
Property
checks
- Define the RegExp for matching against the name of the check associated with an audit event. Type isjava.util.regex.Pattern
. Default value isnull
. -
Property
message
- Define the RegExp for matching against the message of the check associated with an audit event. Type isjava.util.regex.Pattern
. Default value isnull
. -
Property
id
- Specify a string matched against the ID of the check associated with an audit event. Type isjava.lang.String
. Default value isnull
. -
Property
lines
- Specify a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer. Type isjava.lang.String
. Default value isnull
. -
Property
columns
- Specify a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer. Type isjava.lang.String
. Default value isnull
.
The following suppressions directs a
SuppressionSingleFilter
to rejectJavadocStyleCheck
violations for lines 82 and 108 to 122 of fileAbstractComplexityCheck.java
, andMagicNumberCheck
violations for line 221 of fileJavadocStyleCheck.java
, and'Missing a Javadoc comment'
violations for all lines and files:<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>
Suppress check by module id when config have two instances on the same check:
<module name="SuppressionSingleFilter"> <property name="id" value="stringEqual"/> <property name="files" value="SomeTestCode.java"/> </module>
Suppress all checks for hidden files and folders:
<module name="SuppressionSingleFilter"> <property name="files" value="[/\\]\..+"/> <property name="checks" value=".*"/> </module>
Suppress all checks for Maven-generated code:
<module name="SuppressionSingleFilter"> <property name="files" value="[/\\]target[/\\]"/> <property name="checks" value=".*"/> </module>
Suppress all checks for archives, classes and other binary files:
<module name="SuppressionSingleFilter"> <property name="files" value=".+\.(?:jar|zip|war|class|tar|bin)$"/> <property name="checks" value=".*"/> </module>
Suppress all checks for image files:
<module name="SuppressionSingleFilter"> <property name="files" value=".+\.(?:png|gif|jpg|jpeg)$"/> <property name="checks" value=".*"/> </module>
Suppress all checks for non-java files:
<module name="SuppressionSingleFilter"> <property name="files" value=".+\.(?:txt|xml|csv|sh|thrift|html|sql|eot|ttf|woff|css|png)$"/> <property name="checks" value=".*"/> </module>
Suppress all checks in generated sources:
<module name="SuppressionSingleFilter"> <property name="files" value="com[\\/]mycompany[\\/]app[\\/]gen[\\/]"/> <property name="checks" value=".*"/> </module>
Suppress FileLength check on integration tests in certain folder:
<module name="SuppressionSingleFilter"> <property name="files" value="com[\\/]mycompany[\\/]app[\\/].*IT.java"/> <property name="checks" value="FileLength"/> </module>
Suppress naming violations on variable named 'log' in all files:
<module name="SuppressionSingleFilter"> <property name="message" value="Name 'log' must match pattern"/> </module>
Parent is
com.puppycrawl.tools.checkstyle.Checker
- Since:
- 8.23
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
AutomaticBean.OutputStreamOptions
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.regex.Pattern
checks
Define the RegExp for matching against the name of the check associated with an audit event.private java.lang.String
columns
Specify a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer.private java.util.regex.Pattern
files
Define the RegExp for matching against the file name associated with an audit event.private SuppressFilterElement
filter
SuppressFilterElement instance.private java.lang.String
id
Specify a string matched against the ID of the check associated with an audit event.private java.lang.String
lines
Specify a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer.private java.util.regex.Pattern
message
Define the RegExp for matching against the message of the check associated with an audit event.
-
Constructor Summary
Constructors Constructor Description SuppressionSingleFilter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
accept(AuditEvent event)
Determines whether or not a filtered AuditEvent is accepted.protected void
finishLocalSetup()
Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.void
setChecks(java.lang.String checks)
Setter to define the RegExp for matching against the name of the check associated with an audit event.void
setColumns(java.lang.String columns)
Setter to specify a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer.void
setFiles(java.util.regex.Pattern files)
Setter to define the RegExp for matching against the file name associated with an audit event.void
setId(java.lang.String id)
Setter to specify a string matched against the ID of the check associated with an audit event.void
setLines(java.lang.String lines)
Setter to specify a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer.void
setMessage(java.util.regex.Pattern message)
Setter to define the RegExp for matching against the message of the check associated with an audit event.-
Methods inherited from class com.puppycrawl.tools.checkstyle.api.AutomaticBean
configure, contextualize, getConfiguration, setupChild
-
-
-
-
Field Detail
-
filter
private SuppressFilterElement filter
SuppressFilterElement instance.
-
files
private java.util.regex.Pattern files
Define the RegExp for matching against the file name associated with an audit event.
-
checks
private java.util.regex.Pattern checks
Define the RegExp for matching against the name of the check associated with an audit event.
-
message
private java.util.regex.Pattern message
Define the RegExp for matching against the message of the check associated with an audit event.
-
id
private java.lang.String id
Specify a string matched against the ID of the check associated with an audit event.
-
lines
private java.lang.String lines
Specify a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer.
-
columns
private java.lang.String columns
Specify a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer.
-
-
Constructor Detail
-
SuppressionSingleFilter
public SuppressionSingleFilter()
-
-
Method Detail
-
setFiles
public void setFiles(java.util.regex.Pattern files)
Setter to define the RegExp for matching against the file name associated with an audit event.- Parameters:
files
- regular expression for filtered file names
-
setChecks
public void setChecks(java.lang.String checks)
Setter to define the RegExp for matching against the name of the check associated with an audit event.- Parameters:
checks
- the name of the check
-
setMessage
public void setMessage(java.util.regex.Pattern message)
Setter to define the RegExp for matching against the message of the check associated with an audit event.- Parameters:
message
- the message of the check
-
setId
public void setId(java.lang.String id)
Setter to specify a string matched against the ID of the check associated with an audit event.- Parameters:
id
- the ID of the check
-
setLines
public void setLines(java.lang.String lines)
Setter to specify a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer.- Parameters:
lines
- the lines of the check
-
setColumns
public void setColumns(java.lang.String columns)
Setter to specify a comma-separated list of values, where each value is an integer or a range of integers denoted by integer-integer.- Parameters:
columns
- the columns of the check
-
finishLocalSetup
protected void finishLocalSetup()
Description copied from class:AutomaticBean
Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.The default implementation does nothing.
- Specified by:
finishLocalSetup
in classAutomaticBean
-
accept
public boolean accept(AuditEvent event)
Description copied from interface:Filter
Determines whether or not a filtered AuditEvent is accepted.
-
-