计算存储库中忽略抑制文件的 checkstyle 错误数

问题描述

我有一个 Maven 应用程序。在 pom.xml 中,它有一个 maven-checkstyle-plugin 3.1.1 配置了 suppressions.xml 文件

我需要计算代码中检查样式错误数量忽略抑制.xml文件

有没有办法通过命令行来做到这一点?

现在我想出了以下几点:

mvn clean checkstyle:checkstyle 
    -Dcheckstyle.config.location=http://example.com/checkstyle.xml
    -Dcheckstyle.config.logViolationsToConsole=true
    -Dcheckstyle.includeResources=false
    -Dcheckstyle.includeTestResources=false

mvn clean org.apache.maven.plugins:maven-checkstyle-plugin:3.1.1:checkstyle
    -Dcheckstyle.config.location=http://example.com/checkstyle.xml
    -Dcheckstyle.config.logViolationsToConsole=true
    -Dcheckstyle.includeResources=false
    -Dcheckstyle.includeTestResources=false

但它仍然需要考虑抑制.xml。

解决方法

没有好的方法可以做到这一点,但有一个解决方法

  1. 用属性替换 checkstyle 抑制文件位置(例如 checkstyle.suppressions)
  2. 创建具有 0 个抑制的抑制文件,例如
<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
    "-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
    "https://checkstyle.org/dtds/suppressions_1_2.dtd">

<suppressions>
</suppressions>

  1. 将步骤 1 中的属性设置为该“空”文件的路径。 Cli 选项覆盖 pom.xml 中的值

此外,您可以在 checkstyle 配置中替换抑制文件的路径,并以相同的方式使用属性覆盖它。