Robottinosino
Robottinosino

Reputation: 10892

Eclipse formatter is not strict?

I use this to set my maximum line width to 80:

org.eclipse.jdt.core/org.eclipse.jdt.core.formatter.lineSplit=80

Let's face it, Eclipse's formatter is not strict.

It has a very high success rate, and format things very nicely indeed, but it is not 100% strict, sometimes it leaves lines > 80 characters and so it is useless for a project that just lints and refuses code not strictly matching the 80 columns limit and requires Eclipse code auto-formatting.

These 2 things, Eclipse-based formatting and lint, can only really work together when the success rate is 100%. If not, even changing the code by hand triggers a "reformat/reflow" on save and the check-in bombs and refuses the commit.

I cannot disable the formatting on the client and I cannot circumvent the linting.

Is there any way at all to just make the wonderful Eclipse formatter 100% strict? Something like "considerTheLimitSeriously=true"?

Notice: it's eminently "unstrict" in lines with method signatures, but not only.

Upvotes: 2

Views: 1624

Answers (1)

Bill the Lizard
Bill the Lizard

Reputation: 406025

Sorry, there's no way to make the formatter 100% strict when it comes to line splitting. According to JLS 3.8. Identifiers:

An identifier is an unlimited-length sequence of Java letters and Java digits, the first of which must be a Java letter.

So it's possible that some lines cannot be split without causing a compile error.

The best you can do is set the formatting as strict as possible, then look at specific lines in your code to see where this is failing. On the Eclipse main menu go to Window > Preferences, then go to the Java > Code Style > Formatter tab, then click Edit. There you'll find a Line Wrapping tab where you can customize the line wrapping rules.

Upvotes: 1

Related Questions