From 7a51dd2b237aaf1dd4e582bbdfb94c29d4dd2422 Mon Sep 17 00:00:00 2001 From: Daniel del Castillo Date: Wed, 18 May 2022 22:41:57 +0100 Subject: [PATCH] Issue #11655: allow suppressing Google style warnings with annotations and comments --- src/main/resources/google_checks.xml | 18 ++++++++++++++- src/xdocs/google_style.xml | 34 ++++++++++++++++++++++++---- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/src/main/resources/google_checks.xml b/src/main/resources/google_checks.xml index a24ce515d45..f0fb6f4e874 100644 --- a/src/main/resources/google_checks.xml +++ b/src/main/resources/google_checks.xml @@ -16,7 +16,10 @@ Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov. --> - + + + + @@ -47,6 +50,19 @@ + + + + + + + + + + + + + diff --git a/src/xdocs/google_style.xml b/src/xdocs/google_style.xml index abb72772284..a49f40740c1 100644 --- a/src/xdocs/google_style.xml +++ b/src/xdocs/google_style.xml @@ -2302,10 +2302,19 @@

It is possible to suppress some violations by embeded filters - SuppressionFilter - and + SuppressionFilter, - SuppressionXpathFilter. + SuppressionXpathFilter, + + SuppressWithNearbyCommentFilter, + + SuppressionCommentFilter + and + + SuppressWarningsFilter + in conjunction with + + SuppressWarningsHolder. Location of config file for SuppressionFilter can be defined by system property org.checkstyle.google.suppressionfilter.config (default value is checkstyle-suppressions.xml). @@ -2313,13 +2322,30 @@ can be defined by system property org.checkstyle.google.suppressionxpathfilter.config (default value is checkstyle-xpath-suppressions.xml). + To suppress a check on a block of code using SuppressWithNearbyCommentFilter + surround the code block with // CHECKSTYLE.OFF: NameOfTheCheck and + // CHECKSTYLE.ON: NameOfTheCheck (replace NameOfTheCheck with the actual + check to be suppressed). + To suppress a check in the next line of code using SuppressionCommentFilter + precede the line of code with // CHECKSTYLE.OFF: NameOfTheCheck (replace + NameOfTheCheck with the actual check to be suppressed). + To suppress a check using SuppressWarningsFilter use Java's @SuppressWarnings + annotation. Each value passed in the array parameter must meet the format + checkstyle:maneofthecheck where the checkstyle: is optional and + maneofthecheck if the actual name of check to be suppressed in lowercase format.

For more details please review exact configuration of Filters in google_checks.xml: SuppressionFilter, - SuppressionXpathFilter. + SuppressionXpathFilter + + SuppressWithNearbyCommentFilter, + + SuppressionCommentFilter, + + SuppressWarningsFilter.