Spotless google code style 的一些小bug

 

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的value0 改成 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://issues.apache.org/jira/browse/GEODE-5254?page=com.atlassian.jira.plugin.system.issuetabpanels%3Aall-tabpanel

https://github.com/diffplug/spotless/issues/77

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值