mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-03-29 18:16:52 +00:00
alter file with new line even if no other content is changed
This commit is contained in:
parent
da2ea3f7a7
commit
d4b544daf3
2 changed files with 4 additions and 4 deletions
|
|
@ -43,13 +43,13 @@ def fix_requirements(f): # type: (IO[bytes]) -> int
|
|||
before = list(f) # type: List[bytes]
|
||||
after = [] # type: List[bytes]
|
||||
|
||||
before_string = b''.join(before)
|
||||
|
||||
# adds new line in case one is missing
|
||||
# AND a change to the requirements file is needed regardless:
|
||||
if before and not before[-1].endswith(b'\n'):
|
||||
before[-1] += b'\n'
|
||||
|
||||
before_string = b''.join(before)
|
||||
|
||||
# If the file is empty (i.e. only whitespace/newlines) exit early
|
||||
if before_string.strip() == b'':
|
||||
return PASS
|
||||
|
|
@ -99,7 +99,7 @@ def fix_requirements(f): # type: (IO[bytes]) -> int
|
|||
|
||||
after_string = b''.join(after)
|
||||
|
||||
if before_string.rstrip() == after_string.rstrip():
|
||||
if before_string == after_string:
|
||||
return PASS
|
||||
else:
|
||||
f.seek(0)
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ from pre_commit_hooks.requirements_txt_fixer import Requirement
|
|||
(b'bar\nfoo\n', PASS, b'bar\nfoo\n'),
|
||||
(b'a\nc\nb\n', FAIL, b'a\nb\nc\n'),
|
||||
(b'a\nc\nb', FAIL, b'a\nb\nc\n'),
|
||||
(b'a\nb\nc', PASS, b'a\nb\nc'),
|
||||
(b'a\nb\nc', FAIL, b'a\nb\nc\n'),
|
||||
(
|
||||
b'#comment1\nfoo\n#comment2\nbar\n',
|
||||
FAIL,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue