Skip to content

Commit c881808

Browse files
committed
Implementation to pass test
1 parent c21246f commit c881808

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pre_commit_hooks/end_of_file_fixer.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ 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 if file uses CRLF endings
24+
file_obj.seek(0, os.SEEK_SET)
25+
content = file_obj.read()
26+
ending = CRLF if CRLF in content else LF
2327
# Needs this seek for windows, otherwise IOError
2428
file_obj.seek(0, os.SEEK_END)
25-
file_obj.write(LF)
29+
file_obj.write(ending)
2630
return 1
2731

2832
while last_character in {LF, CR}:

0 commit comments

Comments
 (0)