简体   繁体   English

计算存储库中忽略抑制文件的检查样式错误数

[英]Count number of checkstyle errors in repository ignoring suppressions file

I have a maven application.我有一个 maven 应用程序。 In pom.xml it has a maven-checkstyle-plugin 3.1.1 configured with suppressions.xml file.在 pom.xml 中,它有一个maven-checkstyle-plugin 3.1.1 配置了suppressions.xml .xml 文件。

I need to count the number of checkstyle errors in the code ignoring the suppressions.xml file.我需要计算代码中忽略了 suppresss.xml文件的 checkstyle 错误的数量。

Is there a way to do it via command line?有没有办法通过命令行来做到这一点?

For now I have come up with the following:现在我想出了以下几点:

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

or或者

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

but it still takes suppressions.xml into account.但它仍然需要抑制。xml 考虑在内。

There is no good way to do that, but there is a workaround没有好的方法可以做到这一点,但是有一个解决方法

  1. Replace checkstyle suppression file location with property (eg checkstyle.suppressions)用属性替换 checkstyle 抑制文件位置(例如 checkstyle.suppressions)
  2. Create suppressions file with 0 suppressions, like创建具有 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. Set property from step 1 to path to this "empty" file.将步骤 1 中的属性设置为此“空”文件的路径。 Cli options override values in pom.xml Cli 选项覆盖 pom.xml 中的值

Also, you can replace path to suppressions file in checkstyle config and override it with property in same way.此外,您可以在 checkstyle 配置中替换抑制文件的路径,并以相同的方式用属性覆盖它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM