英文:
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
<module name="NestedIfDepth">
<property name="max" value="{AS_MUCH_AS_YOU_WANT}"/>
</module>
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:
<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>
And of course you need to create checkstyle-surpressions.xml file:
<?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>
This will
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论