Skip to content

Commit 647959c

Browse files
committed
Revert "Edge case with mixed endings"
This reverts commit 203735e.
1 parent 203735e commit 647959c

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

pre_commit_hooks/end_of_file_fixer.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@ def fix_file(file_obj: IO[bytes]) -> int:
2020
last_character = file_obj.read(1)
2121
# last_character will be '' for an empty file
2222
if last_character not in {LF, CR} and last_character != b'':
23-
# Check for consistent CRLF usage
23+
# Check if file uses CRLF endings
2424
file_obj.seek(0, os.SEEK_SET)
2525
content = file_obj.read()
26-
lf_count = content.count(LF)
27-
crlf_count = content.count(CRLF)
28-
# Use CRLF only if all line endings are CRLF
29-
ending = CRLF if crlf_count > 0 and crlf_count == lf_count else LF
26+
ending = CRLF if CRLF in content else LF
3027
# Needs this seek for windows, otherwise IOError
3128
file_obj.seek(0, os.SEEK_END)
3229
file_obj.write(ending)

tests/end_of_file_fixer_test.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
(b'\xe2\x98\x83', 1, b'\xe2\x98\x83\n'),
2020
(b'foo\r\n', 0, b'foo\r\n'),
2121
(b'foo\r\nbar', 1, b'foo\r\nbar\r\n'),
22-
(b'foo\nbar\r\nbaz', 1, b'foo\nbar\r\nbaz\n'),
2322
(b'foo\r\n\r\n\r\n', 1, b'foo\r\n'),
2423
(b'foo\r', 0, b'foo\r'),
2524
(b'foo\r\r\r\r', 1, b'foo\r'),

0 commit comments

Comments
 (0)