Vark
Vark

Reputation: 113

Eclipse auto formatting and checkstyle

I'm using Eclipse and checkstyle to not have lines longer than 80 characters.

I've set the Eclipse formatter to follow that rule and it worked for most of the project, except some lines.

Some of those lines were strings so I was able to break them.

However the following lines are not formatted (or wrongly formatted) and automatically reformatted back if I were to change them.

        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)

Note that I've also set the comment maximum length too

Upvotes: 0

Views: 769

Answers (2)

barfuin
barfuin

Reputation: 17474

You could use an empty line comment to force line breaks against the autoformatter, e.g.

private final PersistenceAuditEventRepository //
    persistenceAuditEventRepository;

This is a manual solution of course. Other IDEs, for example IntelliJ IDEA, have an autoformatter setting that says to never exceed the line length. Even that will not cover all cases, of course, so you may still have to suppress some of the warnings.

Upvotes: 1

Matthieu Saleta
Matthieu Saleta

Reputation: 1508

The line wrapping cannot apply everywhere, because it's used to make code clearer but not more compact.

On attributes, you can wrap the assignment :

    private final PersistenceAuditEventRepository persistenceAuditEventRepository = new PersistenceAuditEventRepository();

can be wrapped to something like:

    private final PersistenceAuditEventRepository persistenceAuditEventRepository = 
                                  new PersistenceAuditEventRepository();

but you can't wrap this code :

    private final PersistenceAuditEventRepository persistenceAuditEventRepository;

to :

    private final PersistenceAuditEventRepository
              persistenceAuditEventRepository;

Because this is not clearer with line wrapping than without.

Now i would say that today 80 is a very low value. I use 150 on my project.

We all know that it's better to have longer attributes name to show intent than small attributes name like we used to see for years.

Upvotes: 1

Related Questions