java - Eclipse 自动格式化和 checkstyle

标签 java eclipse checkstyle

我使用 Eclipse 和 checkstyle 来避免行长超过 80 个字符。

我已经将 Eclipse 格式化程序设置为遵循该规则,并且它适用于项目的大部分内容,除了某些行。

其中一些行是字符串,所以我能够打破它们。

但是,以下行未格式化(或格式错误),并且如果我要更改它们,它们会自动重新格式化。

        for (final PersistentAuditEvent persistentAuditEvent : persistentAuditEvents) {
<小时/>
    private final PersistenceAuditEventRepository persistenceAuditEventRepository;
<小时/>
 * <pre>
 * throw new CustomParameterizedException(&quot;myCustomError&quot;, &quot;hello&quot;, &quot;world&quot;);
 * </pre>
<小时/>
@Import(springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration.class)

请注意,我也设置了评论最大长度

最佳答案

换行不能应用于任何地方,因为它用于使代码更清晰,但不是更紧凑。

在属性上,您可以包装赋值:

    private final PersistenceAuditEventRepository persistenceAuditEventRepository = new PersistenceAuditEventRepository();

可以包装成类似:

    private final PersistenceAuditEventRepository persistenceAuditEventRepository = 
                                  new PersistenceAuditEventRepository();

但是你不能包装这段代码:

    private final PersistenceAuditEventRepository persistenceAuditEventRepository;

至:

    private final PersistenceAuditEventRepository
              persistenceAuditEventRepository;

因为换行并不比没有换行更清晰。

现在我想说,今天 80 是一个非常低的值。我在我的项目中使用 150。

我们都知道,使用较长的属性名称来显示意图比我们多年来看到的小属性名称更好。

关于java - Eclipse 自动格式化和 checkstyle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42069802/

相关文章:

eclipse - maven-checkstyle-plugin : Unable to parse suppressions. xml - 格式或检查格式无效

java - J2SE内置方法的限制

java - 如何通过此 Activity 解决 : IllegalStateException: You need to use a Theme. AppCompat 主题(或后代)

java - 内部 : Write rejected

用于防御性编码的 Wil Shipley 的 `IsEmpty` 方法的 Java 实现

sql - MS Outlook 使用 JAVA 工作

Java GUI运行可执行文件+Jar打包

java - 从intellij-idea导入代码风格格式化设置到eclipse

java.lang.ClassFormatError : Absent Code attribute in method that is not native or abstract in class file javax/faces/FacesException

eclipse - Require-Bundle和Import-Package与feature.xml的需求