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

Automatically detect the proper line ending #115

Closed
Pacu2 opened this issue Mar 8, 2021 · 2 comments · Fixed by #117
Closed

Automatically detect the proper line ending #115

Pacu2 opened this issue Mar 8, 2021 · 2 comments · Fixed by #117
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@Pacu2
Copy link
Contributor

Pacu2 commented Mar 8, 2021

Text files created on DOS/Windows machines have different line endings than files created on Unix/Linux. DOS uses carriage return and line feed ("\r\n") as a line ending, which Unix uses just line feed ("\n").
Source: http://www.cs.toronto.edu/~krueger/csc209h/tut/line-endings.html#:~:text=Text%20files%20created%20on%20DOS,(%22%5Cn%22).

Darker should not modify the line ending as it results in false-positives.

E.g.

  1. Create a file on Windows
  2. All line endings are equal \r\n
  3. Modify the file with Darker
  4. Every line gets modified, \r\n line ending is changed to \n
  5. In git-diff it looks like every single line was modified

Black on the other hand tries to check for the proper line ending
newline = "\r\n" if b"\r\n" == lines[0][-2:] else "\n"

@Pacu2
Copy link
Contributor Author

Pacu2 commented Mar 8, 2021

@akaihola I think I can handle this at sometime during the week

@akaihola akaihola added this to the 1.2.3 milestone Mar 8, 2021
@akaihola akaihola added the enhancement New feature or request label Mar 8, 2021
@akaihola
Copy link
Owner

akaihola commented Apr 3, 2021

@Pacu2, I thought about this a bit and figured that the file encoding should also be handled correctly. Please see #117.

@akaihola akaihola linked a pull request Apr 3, 2021 that will close this issue
akaihola added a commit that referenced this issue Apr 3, 2021
Keep encoding and newlines intact. Fixes #115.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants