mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-03-29 10:16:52 +00:00
Implementation to pass test
This commit is contained in:
parent
c21246f34f
commit
c881808ed6
1 changed files with 5 additions and 1 deletions
|
|
@ -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}:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue