【问题标题】:How to configure suppress ParameterNumber on checkstyle?如何在 checkstyle 上配置抑制 ParameterNumber?
【发布时间】:2021-12-25 19:00:06
【问题描述】:

如何配置抑制checkstyle上的参数个数(ParameterNumber):

检查样式配置:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>3.1.2</version>
    <dependencies>
      <dependency>
        <groupId>com.puppycrawl.tools</groupId>
        <artifactId>checkstyle</artifactId>
        <version>9.1</version>
      </dependency>
    </dependencies>
    <configuration>
      <configLocation>/config/checkstyle.xml</configLocation>
      <suppressionsLocation>/config/checkstyle-suppressions.xml</suppressionsLocation>
      <suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
    </configuration>
    <executions>
      <execution>
        <goals>
          <goal>check</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

checkstyle-suppressions.xml 文件:

<suppressions>
  <suppress checks="ParameterNumber" files="src/main/java/org/acme/Signal.java" />
</suppressions>

我仍然收到消息:

Signal.java:[247,26] (sizes) ParameterNumber: More than 7 parameters (found 15).

【问题讨论】:

    标签: checkstyle maven-checkstyle-plugin


    【解决方案1】:

    https://checkstyle.sourceforge.io/config_filters.html#SuppressionFilter

    在文件属性中定义的文件的位置在 以下顺序:

    as a filesystem location
    if no file found, and the location starts with either http:// or https://, then it is interpreted as a URL
    if no file found, then passed to the ClassLoader.getResource() method.
    

    使用包完全是在java中:

    <suppress 
      checks="ParameterNumber"
      files="org.acme.Signal.java" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-30
      • 2015-07-01
      • 2011-04-03
      • 2010-09-16
      • 2020-11-09
      • 2012-10-26
      • 2013-07-23
      相关资源
      最近更新 更多