Reputation: 3304
I have an existing project on which I am trying to add checkstyle checks as part of the build. I see the following output:
A.java:15:1: Line contains a tab character.
B.java:16: Line has trailing spaces.
The error reported in A.java
is in violation to the coding standards followed by my organization. Hence, I want to skip that rule alone for all files in the project.
Can someone suggest how I can get this done?
Upvotes: 2
Views: 10393
Reputation: 64
Checkstyle 3.2 added support for SuppressionFilters. Public Maven repos list the release date as November 8, 2005, but they also list that same release date for several other versions, so presumably, this was the date of some migration, but the release has been available at least since then. The default Checkstyle version in the maven-checkstyle-plugin has been 4.1 at least since January of 2006.
You can configure the suppression filter via Maven, independently of the checkstyle config XML other answers have referenced.
A suppression config something like this should help with the scenario you shared in your question:
<?xml version="1.0"?>
<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.0//EN"
"https://checkstyle.org/dtds/suppressions_1_0.dtd">
<suppressions>
<suppress checks="FileTabCharacter" files=".*\.java" />
</suppressions>
Upvotes: 0
Reputation: 17494
Checkstyle does not offer an option that means something like "Use this configuration, except the following rules." Instead, you must supply a custom rule set which includes only the rules that you want to use.
You can specify the rules configuration that the Checkstyle Maven plugin shall use like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.12.1</version>
<configuration>
<configLocation>checkstyle.xml</configLocation>
</configuration>
</plugin>
In the referenced checkstyle.xml, you can simply remove the unwanted rule. In your case, remove the line that says:
<module name="FileTabCharacter"/>
Checkstyle only executes rules which are explicity mentioned in the configuration. Here's how to write a checkstyle.xml. The default rule file is this one.
Upvotes: 1
Reputation: 11
To define a custom Checkstyle checker configuration inside your pom.xml, use the checkstyleRules parameter.
To allow tab character use FileTabCharacter module
<module name="FileTabCharacter">
<property name="eachLine" value="false"/>
</module>
Upvotes: 1
Reputation: 720
Checkstyle error is not severe. You can disable checkstyle plugin, put
<plugin> <artifactId>maven-checkstyle-plugin</artifactId> <configuration> <skip>true</skip> </configuration> </plugin>
in pom.xml file
Upvotes: -2