我正在为我的项目设置代码风格检查。我想自定义一些标准规则。为此,我创建了一个名为checkstyle. xml
的文件:
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
<module name="Checker">
<module name="SuppressionFilter">
<property name="file" value="${checkstyle.suppressions.file}"/>
</module>
<module name="TreeWalker">
<module name="HiddenField">
<property name="ignoreSetter" value="true"/>
<property name="ignoreConstructorParameter" value="true"/>
</module>
</module>
</module>
在项目的pom. xml
中,我配置了maven checkstyle插件:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>checkstyle</goal>
</goals>
</execution>
</executions>
<configuration>
<consoleOutput>${checkstyle.printErrors}</consoleOutput>
<configLocation>checkstyle.xml</configLocation>
<suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
<suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
</configuration>
</plugin>
现在,只应用了HiddenField
检查,来自sun_checks. xml
的所有其他检查都被关闭。如果我在插件设置中关闭自定义checkstyle.xml,则会再次应用标准检查。
问题是,如何应用标准检查,修改其中一个或一些的设置?
您可以通过将标准配置文件复制到本地作为您自己的checkstyle. xml来做到这一点,然后对其进行修改。
请务必使用适合您的Checkstyle版本的。您正在使用的Maven Checkstyle Plugin 2.17使用了Checkstyle 6.11.2(参考)。只需修改配置文件URL中的版本号即可下载正确的版本。