Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Handle CRLF and CR EOL in end-of-file-fixer #1163

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

Open
edobez wants to merge 6 commits into pre-commit:main
base: main
Choose a base branch
Loading
from edobez:end-of-file-fixer-crlf-fix

Conversation

Copy link

@edobez edobez commented May 8, 2025

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.

invisiblepancake reacted with heart emoji
edobez added 6 commits May 7, 2025 08:44
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.
Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Author

edobez commented May 24, 2025

Ok, I see your point.

What about leaving aside the detection logic and have an optional argument for choosing the desired EOL (defaulting to \n)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@asottile asottile asottile left review comments

Assignees
No one assigned
Labels
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants

AltStyle によって変換されたページ (->オリジナル) /