Skip to content
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

ktlint format saves file with Unix line endings on Windows #225

Closed
thauk-copperleaf opened this issue Jun 12, 2018 · 6 comments
Closed

ktlint format saves file with Unix line endings on Windows #225

thauk-copperleaf opened this issue Jun 12, 2018 · 6 comments

Comments

@thauk-copperleaf
Copy link

I would expect either (A) the existing line endings to be preserved, or (B) the platform's native line endings to be used.

@shyiko
Copy link
Collaborator

shyiko commented Jun 23, 2018

Support for .editorconfig's end_of_line=crlf added in 2cd9546 (included in 0.24.0).
If crlf is used - ktlint tries to preserver it. If not - it fallback to .editorconfig's end_of_line (lf by default).

@shyiko shyiko closed this as completed Jun 23, 2018
@thauk-copperleaf
Copy link
Author

We check in .editorconfig where it is used by developers on Linux and Windows. Since we share the same file, we can't hard-code a single line ending type.

So unfortunately, the support you mention does not address the underlying issue.

@shyiko
Copy link
Collaborator

shyiko commented Jun 25, 2018

I'm not sure I understand.

end_of_line=crlf in .editoconfig affects both the editor (e.g. IntelliJ) and the ktlint. In other words, CRLF will be enforced regardless whether it's Linux, macOS or Windows (which is the whole point of having end_of_line).
On a separate note, I don't think I've ever seen a project using CRLF instead of LF (unless it's strictly Microsoft-stack-specific).

If you have developers working on the same code both on Linux and Windows, using native line endings doesn't sound like a good idea (polluted git diffs, etc.) (unless you have a proper .gitattributes).

@thauk-copperleaf
Copy link
Author

thauk-copperleaf commented Jun 25, 2018

In other words, CRLF will be enforced regardless whether it's Linux, macOS or Windows

But that's the problem. I want ktlint to use the native line endings of the platform it's running on. Otherwise when I run ktlint format, for one platform, the line endings of files will be changed.

As I said in my original description, I think ktlint should either (A) be configurable to use "platform native line endings", or (B) configurable to respect the existing line endings in the file when it's formatting it.

using native line endings doesn't sound like a good idea (polluted git diffs, etc.)

I'm not sure I follow you. Windows users typically have autocrlf enabled, which allows the local line endings for fetched files to be CRLF, and transparently converts line endings on push to be LF.

In fact, what ends up happening when ktlint runs for me (on Windows) is that all my files are CRLF, except the ones that ktlint formats touched, which are LF, and that leaves me with that confusing diff state to which you refer.

@shyiko
Copy link
Collaborator

shyiko commented Jun 25, 2018

Alright, I'm reopening the ticket as there seems to be an issue with CRLF not being preserved on Windows (case B) (even though it should work). For case A I'm going to add end_of_line=native support.

A note on autocrlf - https://stackoverflow.com/a/2825829/482225 / https://stackoverflow.com/a/10855862/482225.
TLDR: do not use crlf unless you absolutely have to. .editoconfig's end_of_line + .gitattributes is all you need.

@shyiko
Copy link
Collaborator

shyiko commented Jul 25, 2018

end_of_line=native support added in 0.25.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants