add @SuppressWarnings and checkstyle-suppressions.xml opportunity (#13)

update README
This commit is contained in:
Anatoly Karlov 2021-03-11 19:33:12 +07:00 committed by GitHub
parent 20871f6696
commit 35e07bf52e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 20 deletions

View File

@ -2,27 +2,73 @@
Our check style config based on Google style
Usage example:
```xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<configLocation>https://raw.githubusercontent.com/rbkmoney/java-checkstyle-config/master/conf/rbkmoney_google_checkstyle.xml</configLocation>
<encoding>UTF-8</encoding>
<failsOnError>true</failsOnError>
<consoleOutput>true</consoleOutput>
<violationSeverity>warning</violationSeverity>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.2</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.41</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<configLocation>${checkstyle.config.path}</configLocation>
<encoding>UTF-8</encoding>
<failsOnError>true</failsOnError>
<consoleOutput>true</consoleOutput>
<violationSeverity>warning</violationSeverity>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
<suppressionsLocation>${checkstyle.config.suppressions.path}</suppressionsLocation>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
```
### SuppressWarnings examples
First path — override `${checkstyle.config.suppressions.path}` in project with `checkstyle-suppressions.xml` file and fill with your filters
pom.xml:
```xml
<properties>
<checkstyle.config.suppressions.path>checkstyle-suppressions.xml</checkstyle.config.suppressions.path>
</properties>
```
checkstyle-suppressions.xml:
```xml
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.0//EN"
"https://checkstyle.org/dtds/suppressions_1_0.dtd">
<suppressions>
<!-- EXAMPLE -->
<!-- <suppress checks="LineLength"-->
<!-- files="AppConfig.java"-->
<!-- lines="0-9999"/>-->
</suppressions>
```
Other path — use:
```java
@SuppressWarnings({"checkstyle:%module_name%", "checkstyle:%module_name%""})
```
Example:
```java
@SuppressWarnings({"checkstyle:parametername", "checkstyle:localvariablename"})
```

View File

@ -0,0 +1,12 @@
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.0//EN"
"https://checkstyle.org/dtds/suppressions_1_0.dtd">
<suppressions>
<!-- EXAMPLE -->
<!-- <suppress checks="LineLength"-->
<!-- files="AppConfig.java"-->
<!-- lines="0-9999"/>-->
</suppressions>

View File

@ -33,6 +33,7 @@
default="checkstyle-suppressions.xml" />
<property name="optional" value="true"/>
</module>
<module name="SuppressWarningsFilter"/>
<!-- Checks for whitespace -->
<!-- See http://checkstyle.org/config_whitespace.html -->
@ -48,6 +49,7 @@
</module>
<module name="TreeWalker">
<module name="SuppressWarningsHolder"/>
<module name="OuterTypeFilename"/>
<module name="IllegalTokenText">
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>