我正在尝试配置 Eclipse Checkstyle 但我找不到两件事的选项:
在方法中我想为每个声明换行:
public int calc (int x,
int y,
int z) {
}
而不是:
public int calc (int x, int y, int z) {
}
声明应该像这样包装
private var a;
private int [] b = null;
private ArrayList<Integer> c = new ArrayList<Integer> ();
而不是:
private var a;
private int [] b = null;
private ArrayList<Integer> c = new ArrayList<Integer> ();
我已经尝试过“MultipleVariableDeclarations”和 OneStatementPerLine,但它们仅在方法内部起作用,不适用于方法的参数。
我希望有人能帮助我。
没有内置的 Checkstyle 规则。但是,对于方法参数/参数对齐,您可以将 lib 与对 checkstyle 的额外检查一起使用 - check-tfij-style.
1。将 lib 添加到您的
maven-checkstyle-plugin
(也适用于 Gradle)作为依赖项,例如:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<configLocation>src/main/resources/checkstyle.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<linkXRef>false</linkXRef>
</configuration>
<executions>
<execution>
<id>validate</id>
<phase>validate</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>pl.tfij</groupId>
<artifactId>check-tfij-style</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>
</plugin>
2。配置您的 checkstyle 检查,例如:
<module name="TreeWalker">
<module name="MethodParameterAlignment"/>
<module name="MethodParameterLinesCheck">
<property name="allowSingleLine" value="false"/>
</module>
</module>
通知
lib 包含更多有用的检查。阅读自述文件以获取更多详细信息 - check-tfij-style.