Class SuppressWithPlainTextCommentFilter

java.lang.Object
com.puppycrawl.tools.checkstyle.AbstractAutomaticBean
com.puppycrawl.tools.checkstyle.filters.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 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.

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.

Notes: Properties offCommentFormat and onCommentFormat must have equal paren counts.

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

Since:
8.6
  • Field Details

    • DEFAULT_OFF_FORMAT

      private static final String DEFAULT_OFF_FORMAT
      Comment format which turns checkstyle reporting off.
      See Also:
    • DEFAULT_ON_FORMAT

      private static final String DEFAULT_ON_FORMAT
      Comment format which turns checkstyle reporting on.
      See Also:
    • DEFAULT_CHECK_FORMAT

      private static final String DEFAULT_CHECK_FORMAT
      Default check format to suppress. By default, the filter suppress all checks.
      See Also:
    • currentFileSuppressionCache

      private final Collection<SuppressWithPlainTextCommentFilter.Suppression> currentFileSuppressionCache
      List of suppressions from the file. By default, Its null.
    • currentFileName

      private String currentFileName
      File name that was suppressed. By default, Its empty.
    • offCommentFormat

      private Pattern offCommentFormat
      Specify comment pattern to trigger filter to begin suppression.
    • onCommentFormat

      private Pattern onCommentFormat
      Specify comment pattern to trigger filter to end suppression.
    • checkFormat

      private String checkFormat
      Specify check pattern to suppress.
    • messageFormat

      private String messageFormat
      Specify message pattern to suppress.
    • idFormat

      private String idFormat
      Specify check ID pattern to suppress.
  • Constructor Details

    • SuppressWithPlainTextCommentFilter

      public SuppressWithPlainTextCommentFilter()
  • Method Details