-
Notifications
You must be signed in to change notification settings - Fork 463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The greclipse
formatter changes the line separator unconditionally, breaking subsequent executions of the java
formatter on Windows
#1049
Comments
Very interesting! Thanks for the detailed investigation. Are you using the default @fvgh, I think one way to resolve this would be to remove this method Lines 119 to 121 in a7f25eb
And modify this method: Lines 80 to 82 in a7f25eb
by adding: static final LINE_ENDINGS_NATIVE = System.getProperty("line.separator");
public String format(String rawUnix) throws Exception {
String raw;
if (LINE_ENDINGS_NATIVE.equals("\n")) {
raw = rawUnix;
} else {
raw = rawUnix.replace("\n", LINE_ENDINGS_NATIVE);
}
IDocument doc = new Document(raw); Spotless always passes unix line endings to each step, but it doesn't care which line endings it gets back spotless/lib/src/main/java/com/diffplug/spotless/Formatter.java Lines 236 to 237 in bd2195e
Probably safer for the formatter to mutate the input to match its expectations, rather than mutate the system property. |
The default. |
An excellent example of Postel's law:
|
As stated in the code comment,
E.g. Eclipse formatters use the first line ending they find as the default one. If there is none, they fall back to the system one (at least that was the behavior some years ago). Some formatters like JDT and CDT also accept the desired line separator as argument. Removing the the To keep the code clean I would propose to:
Since the scenario described by @basil is relatively rare, I don't think a back port to older formatters is required. |
No longer an issue as of the latest version. |
Observed in jenkinsci/jenkins#6104 when trying to add
greclipse
formatting to a Maven multi-module project with thejava
formatter already enabled. The checks started failing on Windows but kept passing on Linux.I looked into how this was working before adding
greclipse
. Thejava
formatter was working fine on both Linux and Windows; inFormatter#computeLineEndings
,lineEndingsPolicy.getEndingFor(file)
was returning\n
on Linux and\r\n
on Windows as expected.After adding
greclipse
to the Maven multi-module project, the behavior continued to be as expected until thegreclipse
formatter ran. During its execution, it got tospotless/_ext/eclipse-base/src/main/java/com/diffplug/spotless/extra/eclipse/base/SpotlessEclipseServiceConfig.java
Lines 111 to 121 in a7f25eb
upon which it changed the line separator to
\n
unconditionally for both Linux and Windows. That is as expected forgreclipse
's own execution, but then it never set the value back to the original value. So in a subsequent execution of thejava
formatter on a different Maven module,lineEndingsPolicy.getEndingFor(file)
started returning\n
on Windows (not expected) and the Windows build failed with hundreds of errors likeThe
greclipse
formatter should set the line ending back to the original value when it is done.The text was updated successfully, but these errors were encountered: