There was an error while loading. Please reload this page.
1 parent da2ea3f commit d4b544dCopy full SHA for d4b544d
2 files changed
pre_commit_hooks/requirements_txt_fixer.py
@@ -43,13 +43,13 @@ def fix_requirements(f): # type: (IO[bytes]) -> int
43
before = list(f) # type: List[bytes]
44
after = [] # type: List[bytes]
45
46
+ before_string = b''.join(before)
47
+
48
# adds new line in case one is missing
49
# AND a change to the requirements file is needed regardless:
50
if before and not before[-1].endswith(b'\n'):
51
before[-1] += b'\n'
52
- before_string = b''.join(before)
-
53
# If the file is empty (i.e. only whitespace/newlines) exit early
54
if before_string.strip() == b'':
55
return PASS
@@ -99,7 +99,7 @@ def fix_requirements(f): # type: (IO[bytes]) -> int
99
100
after_string = b''.join(after)
101
102
- if before_string.rstrip() == after_string.rstrip():
+ if before_string == after_string:
103
104
else:
105
f.seek(0)
tests/requirements_txt_fixer_test.py
@@ -17,7 +17,7 @@
17
(b'bar\nfoo\n', PASS, b'bar\nfoo\n'),
18
(b'a\nc\nb\n', FAIL, b'a\nb\nc\n'),
19
(b'a\nc\nb', FAIL, b'a\nb\nc\n'),
20
- (b'a\nb\nc', PASS, b'a\nb\nc'),
+ (b'a\nb\nc', FAIL, b'a\nb\nc\n'),
21
(
22
b'#comment1\nfoo\n#comment2\nbar\n',
23
FAIL,
0 commit comments