我希望 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 文件。
附注:
我在我的 Maven 依赖项中使用 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>
最佳答案
Checkstyle 没有对 Java 文件以外的其他文件进行缩进检查,因此无法使用它在 XML 文件中进行缩进检查。
基本上所有 TreeWalker
检查都是针对 java 文件的(例如 IndentationCheck
),所有其他检查都可用于其他文件(XML、属性等),但数量非常有限其中(例如 FileTabCharacterCheck
)。
您需要使用其他工具来实现此目的,但我还没有找到。
关于java - checkstyle 不检查 XML 中的空格缩进,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38105600/