Handle CRLF and CR EOL in end-of-file-fixer#1163
Open
edobez wants to merge 6 commits intopre-commit:mainfrom
Open
Handle CRLF and CR EOL in end-of-file-fixer#1163edobez wants to merge 6 commits intopre-commit:mainfrom
edobez wants to merge 6 commits intopre-commit:mainfrom
Conversation
Case is for file using CRLF endings
Added case for which the file has mixed line endings. In this case, default into using LF for end of file line.
This reverts commit 203735e.
asottile
reviewed
May 23, 2025
Member
asottile
left a comment
There was a problem hiding this comment.
like I said -- I don't think this is fixable without significantly regressing performance so I'd rather just say it's unsupported
perhaps instead we should back out any handling of \r
| if last_character not in {LF, CR} and last_character != b'': | ||
| # Look at first line to determine line ending | ||
| file_obj.seek(0, os.SEEK_SET) | ||
| first_line = file_obj.readline() |
Member
There was a problem hiding this comment.
this will read the whole file into memory for \r-delimited files -- and will read the whole file into memory if it has no newlines
Author
|
Ok, I see your point. What about leaving aside the detection logic and have an optional argument for choosing the desired EOL (defaulting to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Second attempt :-)
Correctly adding last-line ending based on the one detected at the first line.
Basically fixes the behavior for CRLF and CR based files.