diff --git a/pre_commit_hooks/end_of_file_fixer.py b/pre_commit_hooks/end_of_file_fixer.py index fc05d16..2f397eb 100644 --- a/pre_commit_hooks/end_of_file_fixer.py +++ b/pre_commit_hooks/end_of_file_fixer.py @@ -20,9 +20,13 @@ def fix_file(file_obj: IO[bytes]) -> int: last_character = file_obj.read(1) # last_character will be '' for an empty file if last_character not in {LF, CR} and last_character != b'': + # Check if file uses CRLF endings + file_obj.seek(0, os.SEEK_SET) + content = file_obj.read() + ending = CRLF if CRLF in content else LF # Needs this seek for windows, otherwise IOError file_obj.seek(0, os.SEEK_END) - file_obj.write(LF) + file_obj.write(ending) return 1 while last_character in {LF, CR}: