繁体   English   中英

Eclipse自动格式化和检查样式

[英]Eclipse auto formatting and 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。

我们都知道,拥有较长的属性名称以显示意图要比像我们过去几年看到的较小的属性名称更好。

您可以使用空行注释强制对自动格式化程序使用换行符,例如

private final PersistenceAuditEventRepository //
    persistenceAuditEventRepository;

当然,这是手动解决方案。 其他IDE(例如IntelliJ IDEA)具有自动格式化程序设置,该设置表示永不超过行长。 当然,即使那样也不能涵盖所有情况,因此您可能仍然不得不禁止某些警告。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM