From c881808ed66692568717b2e929dd5e583e4080a7 Mon Sep 17 00:00:00 2001 From: Edoardo Bezzeccheri Date: Wed, 7 May 2025 08:52:52 +0000 Subject: [PATCH] Implementation to pass test --- pre_commit_hooks/end_of_file_fixer.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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}: