mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-03-31 02:36:52 +00:00
Fix CRLF lines
This commit is contained in:
parent
e01bc2c2a1
commit
abd3d0ec3f
2 changed files with 5 additions and 2 deletions
|
|
@ -21,7 +21,7 @@ def fix_file(file_obj):
|
|||
file_obj.write(b'\n')
|
||||
return 1
|
||||
|
||||
while last_character == b'\n':
|
||||
while last_character == b'\n' or last_character == b'\r':
|
||||
# Deal with the beginning of the file
|
||||
if file_obj.tell() == 1:
|
||||
# If we've reached the beginning of the file and it is all
|
||||
|
|
@ -39,8 +39,9 @@ def fix_file(file_obj):
|
|||
# there are extraneous newlines at the ned of the file. Then backtrack and
|
||||
# trim the end off.
|
||||
if len(file_obj.read(2)) == 2:
|
||||
file_obj.seek(-1, os.SEEK_CUR)
|
||||
file_obj.seek(-2, os.SEEK_CUR)
|
||||
file_obj.truncate()
|
||||
file_obj.write(b'\n')
|
||||
return 1
|
||||
|
||||
return 0
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ TESTS = (
|
|||
(b'foo', 1, b'foo\n'),
|
||||
(b'foo\n\n\n', 1, b'foo\n'),
|
||||
(b'\xe2\x98\x83', 1, b'\xe2\x98\x83\n'),
|
||||
(b'foo\r\n', 1, b'foo\n'),
|
||||
(b'foo\r\n\r\n', 1, b'foo\n'),
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue