Class SuppressWithNearbyTextFilter
java.lang.Object
com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
com.puppycrawl.tools.checkstyle.filters.SuppressWithNearbyTextFilter
- All Implemented Interfaces:
Configurable
,Contextualizable
,Filter
Filter
SuppressWithNearbyTextFilter
uses plain text to suppress
nearby audit events. The filter can suppress all checks which have Checker as a parent module.
Setting .*
value to nearbyTextPattern
property will see any
text as a suppression and will likely suppress all audit events in the file. It is
best to set this to a key phrase not commonly used in the file to help denote it
out of the rest of the file as a suppression. See the default value as an example.
-
Property
checkPattern
- Specify check name pattern to suppress. Property can also be a RegExp group index atnearbyTextPattern
in format of$x
and be picked from line that matchesnearbyTextPattern
. Type isjava.util.regex.Pattern
. Default value is".*"
. -
Property
idPattern
- Specify check ID pattern to suppress. Type isjava.util.regex.Pattern
. Default value isnull
. -
Property
lineRange
- Specify negative/zero/positive value that defines the number of lines preceding/at/following the suppressing nearby text. Property can also be a RegExp group index atnearbyTextPattern
in format of$x
and be picked from line that matchesnearbyTextPattern
. Type isjava.lang.String
. Default value is"0"
. -
Property
messagePattern
- Specify check violation message pattern to suppress. Type isjava.util.regex.Pattern
. Default value isnull
. -
Property
nearbyTextPattern
- Specify nearby text pattern to trigger filter to begin suppression. Type isjava.util.regex.Pattern
. Default value is"SUPPRESS CHECKSTYLE (\w+)"
.
Parent is com.puppycrawl.tools.checkstyle.Checker
- Since:
- 10.10.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class
The class which represents the suppression.Nested classes/interfaces inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
AbstractAutomaticBean.OutputStreamOptions
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
The absolute path to the currently processed file.private String
Specify check name pattern to suppress.private static final String
Default regex for checks that should be suppressed.private static final String
Default number of lines that should be suppressed.private static final String
Default nearby text pattern to turn check reporting off.private String
Specify check ID pattern to suppress.private String
Specify negative/zero/positive value that defines the number of lines preceding/at/following the suppressing nearby text.private String
Specify check violation message pattern to suppress.private Pattern
Specify nearby text pattern to trigger filter to begin suppression.private final List<SuppressWithNearbyTextFilter.Suppression>
Suppressions encountered in current file. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
accept
(AuditEvent event) Determines whether or not a filtered AuditEvent is accepted.private void
collectSuppressions
(FileText fileText) Collets allSuppressWithNearbyTextFilter.Suppression
instances retrieved from the givenFileText
.protected void
Provides a hook to finish the part of this component's setup that was not handled by the bean introspection.private static FileText
getFileText
(String fileName) ReturnsFileText
instance created based on the given file name.private static Optional<SuppressWithNearbyTextFilter.Suppression>
getNearestSuppression
(Collection<SuppressWithNearbyTextFilter.Suppression> suppressions, AuditEvent event) Finds the nearestSuppressWithNearbyTextFilter.Suppression
instance which can suppress the givenAuditEvent
.getSuppression
(FileText fileText, int lineNo) Tries to extract the suppression from the given line.final void
setCheckPattern
(String pattern) Setter to specify check name pattern to suppress.void
setIdPattern
(String pattern) Setter to specify check ID pattern to suppress.final void
setLineRange
(String format) Setter to specify negative/zero/positive value that defines the number of lines preceding/at/following the suppressing nearby text.void
setMessagePattern
(String pattern) Setter to specify check violation message pattern to suppress.final void
setNearbyTextPattern
(Pattern pattern) Setter to specify nearby text pattern to trigger filter to begin suppression.Methods inherited from class com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
configure, contextualize, getConfiguration, setupChild
-
Field Details
-
DEFAULT_NEARBY_TEXT_PATTERN
Default nearby text pattern to turn check reporting off.- See Also:
-
DEFAULT_CHECK_PATTERN
Default regex for checks that should be suppressed.- See Also:
-
DEFAULT_LINE_RANGE
Default number of lines that should be suppressed.- See Also:
-
suppressions
Suppressions encountered in current file. -
nearbyTextPattern
Specify nearby text pattern to trigger filter to begin suppression. -
checkPattern
Specify check name pattern to suppress. Property can also be a RegExp group index atnearbyTextPattern
in format of$x
and be picked from line that matchesnearbyTextPattern
. -
messagePattern
Specify check violation message pattern to suppress. -
idPattern
Specify check ID pattern to suppress. -
lineRange
Specify negative/zero/positive value that defines the number of lines preceding/at/following the suppressing nearby text. Property can also be a RegExp group index atnearbyTextPattern
in format of$x
and be picked from line that matchesnearbyTextPattern
. -
cachedFileAbsolutePath
The absolute path to the currently processed file.
-
-
Constructor Details
-
SuppressWithNearbyTextFilter
public SuppressWithNearbyTextFilter()
-
-
Method Details
-
setNearbyTextPattern
Setter to specify nearby text pattern to trigger filter to begin suppression.- Parameters:
pattern
- aPattern
value.- Since:
- 10.10.0
-
setCheckPattern
Setter to specify check name pattern to suppress. Property can also be a RegExp group index atnearbyTextPattern
in format of$x
and be picked from line that matchesnearbyTextPattern
.- Parameters:
pattern
- aString
value.- Since:
- 10.10.0
-
setMessagePattern
Setter to specify check violation message pattern to suppress.- Parameters:
pattern
- aString
value.- Since:
- 10.10.0
-
setIdPattern
Setter to specify check ID pattern to suppress.- Parameters:
pattern
- aString
value.- Since:
- 10.10.0
-
setLineRange
Setter to specify negative/zero/positive value that defines the number of lines preceding/at/following the suppressing nearby text. Property can also be a RegExp group index atnearbyTextPattern
in format of$x
and be picked from line that matchesnearbyTextPattern
.- Parameters:
format
- aString
value.- Since:
- 10.10.0
-
accept
Description copied from interface:Filter
Determines whether or not a filtered AuditEvent is accepted. -
finishLocalSetup
Description copied from class:AbstractAutomaticBean
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 classAbstractAutomaticBean
-
getFileText
ReturnsFileText
instance created based on the given file name.- Parameters:
fileName
- the name of the file.- Returns:
FileText
instance.- Throws:
IllegalStateException
- if the file could not be read.
-
collectSuppressions
Collets allSuppressWithNearbyTextFilter.Suppression
instances retrieved from the givenFileText
.- Parameters:
fileText
-FileText
instance.
-
getSuppression
Tries to extract the suppression from the given line.- Parameters:
fileText
-FileText
instance.lineNo
- line number.- Returns:
SuppressWithNearbyTextFilter.Suppression
instance.
-
getNearestSuppression
private static Optional<SuppressWithNearbyTextFilter.Suppression> getNearestSuppression(Collection<SuppressWithNearbyTextFilter.Suppression> suppressions, AuditEvent event) Finds the nearestSuppressWithNearbyTextFilter.Suppression
instance which can suppress the givenAuditEvent
. The nearest suppression is the suppression which scope is before the line and column of the event.- Parameters:
suppressions
- collection ofSuppressWithNearbyTextFilter.Suppression
instances.event
-AuditEvent
instance.- Returns:
SuppressWithNearbyTextFilter.Suppression
instance.
-