Skip to content

Commit d4b544d

Browse files
committed
alter file with new line even if no other content is changed
1 parent da2ea3f commit d4b544d

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

pre_commit_hooks/requirements_txt_fixer.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ def fix_requirements(f): # type: (IO[bytes]) -> int
4343
before = list(f) # type: List[bytes]
4444
after = [] # type: List[bytes]
4545

46+
before_string = b''.join(before)
47+
4648
# adds new line in case one is missing
4749
# AND a change to the requirements file is needed regardless:
4850
if before and not before[-1].endswith(b'\n'):
4951
before[-1] += b'\n'
5052

51-
before_string = b''.join(before)
52-
5353
# If the file is empty (i.e. only whitespace/newlines) exit early
5454
if before_string.strip() == b'':
5555
return PASS
@@ -99,7 +99,7 @@ def fix_requirements(f): # type: (IO[bytes]) -> int
9999

100100
after_string = b''.join(after)
101101

102-
if before_string.rstrip() == after_string.rstrip():
102+
if before_string == after_string:
103103
return PASS
104104
else:
105105
f.seek(0)

tests/requirements_txt_fixer_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
(b'bar\nfoo\n', PASS, b'bar\nfoo\n'),
1818
(b'a\nc\nb\n', FAIL, b'a\nb\nc\n'),
1919
(b'a\nc\nb', FAIL, b'a\nb\nc\n'),
20-
(b'a\nb\nc', PASS, b'a\nb\nc'),
20+
(b'a\nb\nc', FAIL, b'a\nb\nc\n'),
2121
(
2222
b'#comment1\nfoo\n#comment2\nbar\n',
2323
FAIL,

0 commit comments

Comments
 (0)