Class SuppressWithPlainTextCommentFilter

  • All Implemented Interfaces:
    Configurable, Contextualizable, Filter

    public class SuppressWithPlainTextCommentFilter
    extends AbstractAutomaticBean
    implements Filter

    Filter SuppressWithPlainTextCommentFilter uses plain text to suppress audit events. The filter can be used only to suppress audit events received from the checks which implement FileSetCheck interface. In other words, the checks which have Checker as a parent module. The filter knows nothing about AST, it treats only plain text comments and extracts the information required for suppression from the plain text comments. Currently, the filter supports only single-line comments.

    Please, be aware of the fact that, it is not recommended to use the filter for Java code anymore, however you still are able to use it to suppress audit events received from the checks which implement FileSetCheck interface.

    Rationale: Sometimes there are legitimate reasons for violating a check. When this is a matter of the code in question and not personal preference, the best place to override the policy is in the code itself. Semi-structured comments can be associated with the check. This is sometimes superior to a separate suppressions file, which must be kept up-to-date as the source file is edited.

    Note that the suppression comment should be put before the violation. You can use more than one suppression comment each on separate line.

    Properties offCommentFormat and onCommentFormat must have equal paren counts.

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

    • Property checkFormat - Specify check pattern to suppress. Type is java.util.regex.Pattern. Default value is ".*".
    • Property idFormat - Specify check ID pattern to suppress. Type is java.util.regex.Pattern. Default value is null.
    • Property messageFormat - Specify message pattern to suppress. Type is java.util.regex.Pattern. Default value is null.
    • Property offCommentFormat - Specify comment pattern to trigger filter to begin suppression. Type is java.util.regex.Pattern. Default value is "// CHECKSTYLE:OFF".
    • Property onCommentFormat - Specify comment pattern to trigger filter to end suppression. Type is java.util.regex.Pattern. Default value is "// CHECKSTYLE:ON".

    Parent is com.puppycrawl.tools.checkstyle.Checker

    Since:
    8.6