Skip to content

Commit

Permalink
Issue checkstyle#11655: allow suppressing Google style warnings with …
Browse files Browse the repository at this point in the history
…annotations and comments
  • Loading branch information
ddcprg committed Jun 6, 2022
1 parent 74747a2 commit c99a105
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
18 changes: 17 additions & 1 deletion src/main/resources/google_checks.xml
Expand Up @@ -16,7 +16,10 @@
Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
-->

<module name = "Checker">
<module name="Checker">
<!-- IMPORTANT: Allows use of SuppressWarnings annotation -->
<module name="SuppressWarningsFilter"/>

<property name="charset" value="UTF-8"/>

<property name="severity" value="warning"/>
Expand Down Expand Up @@ -47,6 +50,19 @@
</module>

<module name="TreeWalker">
<module name="SuppressWarningsHolder" />
<module name="SuppressionCommentFilter">
<property name="offCommentFormat" value="CHECKSTYLE.OFF\: ([\w\|]+)" />
<property name="onCommentFormat" value="CHECKSTYLE.ON\: ([\w\|]+)" />
<property name="checkFormat" value="$1" />
</module>
<!-- Allow suppression using a comment on the same line or the line before -->
<module name="SuppressWithNearbyCommentFilter">
<property name="commentFormat" value="CHECKSTYLE.OFF\: ([\w\|]+)"/>
<property name="checkFormat" value="$1"/>
<property name="influenceFormat" value="1"/>
</module>

<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
Expand Down
34 changes: 30 additions & 4 deletions src/xdocs/google_style.xml
Expand Up @@ -2302,24 +2302,50 @@
<p>
It is possible to suppress some violations by embeded filters
<a href="config_filters.html#SuppressionFilter">
SuppressionFilter</a>
and
SuppressionFilter</a>,
<a href="config_filters.html#SuppressionXpathFilter">
SuppressionXpathFilter</a>.
SuppressionXpathFilter</a>,
<a href="config_filters.html#SuppressWithNearbyCommentFilter">
SuppressWithNearbyCommentFilter</a>,
<a href="config_filters.html#SuppressionCommentFilter">
SuppressionCommentFilter</a>
and
<a href="config_filters.html#SuppressWarningsFilter">
SuppressWarningsFilter</a>
in conjunction with
<a href="config_filters.html#SuppressWarningsHolder">
SuppressWarningsHolder</a>.
Location of config file for <i>SuppressionFilter</i> can be defined by system property
<i>org.checkstyle.google.suppressionfilter.config</i> (default value is
<i>checkstyle-suppressions.xml</i>).
Location of config file for <i>SuppressionXpathFilter</i>
can be defined by system property
<i>org.checkstyle.google.suppressionxpathfilter.config</i> (default value is
<i>checkstyle-xpath-suppressions.xml</i>).
To suppress a check on a block of code using <i>SuppressWithNearbyCommentFilter</i>
surround the code block with <i>// CHECKSTYLE.OFF: NameOfTheCheck</i> and
<i>// CHECKSTYLE.ON: NameOfTheCheck</i> (replace <i>NameOfTheCheck</i> with the actual
check to be suppressed).
To suppress a check in the next line of code using <i>SuppressionCommentFilter</i>
precede the line of code with <i>// CHECKSTYLE.OFF: NameOfTheCheck</i> (replace
<i>NameOfTheCheck</i> with the actual check to be suppressed).
To suppress a check using <i>SuppressWarningsFilter</i> use Java's <i>@SuppressWarnings</i>
annotation. Each value passed in the array parameter must meet the format
<i>checkstyle:maneofthecheck</i> where the <i>checkstyle:</i> is optional and
<i>maneofthecheck</i> if the actual name of check to be suppressed in lowercase format.
</p>
<p>
For more details please review exact configuration of Filters in google_checks.xml:
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressionFilter">
SuppressionFilter</a>,
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressionXpathFilter">
SuppressionXpathFilter</a>.
SuppressionXpathFilter</a>
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressWithNearbyCommentFilter">
SuppressWithNearbyCommentFilter</a>,
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressionCommentFilter">
SuppressionCommentFilter</a>,
<a href="https://github.com/search?q=path%3Asrc%2Fmain%2Fresources+filename%3Agoogle_checks.xml+repo%3Acheckstyle%2Fcheckstyle+SuppressWarningsFilter">
SuppressWarningsFilter</a>.
</p>
</subsection>
</section>
Expand Down

0 comments on commit c99a105

Please sign in to comment.