Spotless + gradlew
Spotless - https://github.com/apache/geode/blob/master/etc/eclipse-java-google-style.xml
Gradlew - https://docs.gradle.org/current/userguide/gradle_wrapper.html
在使用spotless 的时候,我们启用默认的google style, 会发现一个问题,即是方法调用会水平链接下去。如果你希望垂直对齐,如何设置呢。
1. 流式或者链式代码如何让方法以垂直方式对齐。
如下所示:
super.getFoo().foo().getBar().bar();
->
super.getFoo()
.foo()
.getBar()
.bar();
etc/eclipse-java-google-style.xml, 将下面的value改成false。
<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/>
2. 枚举Enum 的成员垂直对齐。
将alignment_for_enum_constants的value
从0
改成 48
<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="48"/>
public enum WError {
ERROR_FAILED_COMPLEX_WORKFLOW_INVALID("W failed due to generic error"), ERROR_FAILED_COMPLEX_WORKFLOW_INVALID2(
"W failed due to generic error 2"), ERROR_FAILED_COMPLEX_WORKFLOW_ERROR(
"failed due to an error occurred"), ERROR_FAILED_COMPLEX_WORKFLOW_INVALID_DATA(
"data passed in is invalid"), ERROR_FAILED_CHECK(
"Check failed due to some failures"), ERROR_FAILED_COMPLEX_WORKFLOW_ALREADY_EXISTS(
"Value already exists"), ERROR_FAILED_COMPLEX_WORKFLOW_ALREADY_DELETED(
"some data is already deleted."), ERROR_FAILED_COMPLEX_WORKFLOW_CALL_URL(
"Invalid remote call url due to fail to get necessary info from it."), ERROR_FAILED_COMPLEX_WORKFLOW_NOT_FOUND(
"Config value is not found.");
private String message;
WError(String message) {
this.message = message;
}
}
Reference:
https://github.com/apache/geode/blob/master/etc/eclipse-java-google-style.xml
https://github.com/diffplug/spotless/issues/77