我希望checkstyle检查xml
/ properties
中的缩进(如果可能,还会在yml
)文件中检查缩进。
然而,使用我当前的配置,我无法完成它。这是我的项目结构的样子
.
├── Makefile
├── README.md
├── checkstyle.xml
├── pom.xml
├── src
│ ├── main
│ └── test
和此特定问题的checkstyle.xml
文件配置是
<module name="Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="error"/>
<property name="fileExtensions" value=""/>
<property name="basedir" value="."/>
<!-- Checks for whitespace -->
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
<module name="FileTabCharacter">
<property name="eachLine" value="true"/>
</module>
我已将basedir
设置为.
并尝试使用/
(因为我的checkstyle位于config/checkstyle
位置)。我也尝试过没有basedir
属性但是当我的XML缩进4个空格时它没有报告XML缩进问题。我在谈论pom.xml
。如何确保checkstyle
检查xml文件。
P.S:
我在maven depdencies中使用checkstyle 7.0版并执行检查mvn checkstyl:checkstyle
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>7.0</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<configuration>
<configLocation>${checkstyle.config.location}</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
答案 0 :(得分:1)
Checkstyle没有对其他文件进行缩进检查,然后是java文件,因此无法使用它来检查XML文件。
基本上所有TreeWalker
检查都适用于java文件(如IndentationCheck
),所有其他检查都可用于其他文件(XML,属性等),但其数量非常有限(例如{{ 1}})。
你需要使用其他工具,但我还没找到。