如何增加Maven允许的嵌套if else语句数量

huangapple go评论60阅读模式
英文:

How do increase the number of nested if else statements allowed by maven

问题

我已经编写了用于在Java中搜索图中节点可达性的代码。我不想更改我的代码。我正在使用Maven。当我尝试编译代码时,出现了以下错误。

    [INFO] 使用com/github/ngeor/checkstyle.xml规则集,Checkstyle 8.29报告了1个错误。
    [ERROR] src/main/java/dsa/graphs/Graph.java:[160,25] (coding) 嵌套的if-else深度为2(允许的最大深度为1)。

我该如何解决这个问题。我不想在同一时间禁用**checkstyle**,同时又不想更改我的代码。我该如何将这个数字增加到大于1。
英文:

I have written my code to search if a node can be reached in a graph using java. I don't to change my code. I am using maven. When I try to compile it's giving me the error below.

[INFO] There is 1 error reported by Checkstyle 8.29 with com/github/ngeor/checkstyle.xml ruleset.
[ERROR] src/main/java/dsa/graphs/Graph.java:[160,25] (coding) NestedIfDepth: Nested if-else depth is 2 (max allowed is 1).

How do I get around this. I don't want to disable checkstyle at the same time I don't want to change my code. How can I increase that number to be more than 1.

答案1

得分: 3

我假设您的 checkstyle 位于 com.github.ngeor 包下,所以只需转到文件并进行更改/添加:

<module name="NestedIfDepth">
  <property name="max" value="{AS_MUCH_AS_YOU_WANT}"/>
</module>

或者,如果您引用的 checkstyle 不受您控制,您也可以进行覆盖。

将 checkstyle 插件添加到您的 pom 文件中:

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>3.1.1</version>
    <configuration>
      <configLocation>checkstyle.xml</configLocation>
      <suppressionsLocation>checkstyle-suppressions.xml</suppressionsLocation>
      <suppressionsFileExpression>checkstyle.suppressions.file</suppressionsFileExpression>
    </configuration>
  </plugin>
</plugins>

当然,您需要创建 checkstyle-surpressions.xml 文件:

<?xml version="1.0"?>
 
<!DOCTYPE suppressions PUBLIC
     "-//Checkstyle//DTD SuppressionFilter Configuration 1.0//EN"
     "https://checkstyle.org/dtds/suppressions_1_0.dtd">
 
<suppressions>
  <suppress checks="NestedIfDepth"
            files="Graph.java"
            lines="{what_Lines_you_need}"/>
</suppressions>
英文:

I am presuming that you have the checkstyle under com.github.ngeor package so just go to the file and change/add

&lt;module name=&quot;NestedIfDepth&quot;&gt;
  &lt;property name=&quot;max&quot; value=&quot;{AS_MUCH_AS_YOU_WANT}&quot;/&gt;
&lt;/module&gt;

Or if you are referencing a checkstyle that is not under your control you can also override it.

Add the checkstyle plugin to your pom:

&lt;plugins&gt;
      &lt;plugin&gt;
        &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
        &lt;artifactId&gt;maven-checkstyle-plugin&lt;/artifactId&gt;
        &lt;version&gt;3.1.1&lt;/version&gt;
        &lt;configuration&gt;
          &lt;configLocation&gt;checkstyle.xml&lt;/configLocation&gt;
          &lt;suppressionsLocation&gt;checkstyle-suppressions.xml&lt;/suppressionsLocation&gt;
          &lt;suppressionsFileExpression&gt;checkstyle.suppressions.file&lt;/suppressionsFileExpression&gt;
        &lt;/configuration&gt;
      &lt;/plugin&gt;
    &lt;/plugins&gt;

And of course you need to create checkstyle-surpressions.xml file:

&lt;?xml version=&quot;1.0&quot;?&gt;
 
&lt;!DOCTYPE suppressions PUBLIC
     &quot;-//Checkstyle//DTD SuppressionFilter Configuration 1.0//EN&quot;
     &quot;https://checkstyle.org/dtds/suppressions_1_0.dtd&quot;&gt;
 
&lt;suppressions&gt;
  &lt;suppress checks=&quot;NestedIfDepth&quot;
            files=&quot;Graph.java&quot;
            lines=&quot;{what_Lines_you_need}&quot;/&gt;
&lt;/suppressions&gt;

This will

huangapple
  • 本文由 发表于 2020年10月22日 21:55:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/64483810.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定