Skip to content

Commit 093109e

Browse files
committed
requirements-txt-fixer now supports indents before comments
1 parent 90eee23 commit 093109e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

pre_commit_hooks/requirements_txt_fixer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def fix_requirements(f: IO[bytes]) -> int:
9595
requirement.value = b'\n'
9696
else:
9797
requirement.comments.append(line)
98-
elif line.startswith(b'#') or line.strip() == b'':
98+
elif line.lstrip().startswith(b'#') or line.strip() == b'':
9999
requirement.comments.append(line)
100100
else:
101101
requirement.append_value(line)

tests/requirements_txt_fixer_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@
3030
),
3131
(b'#comment\n\nfoo\nbar\n', FAIL, b'#comment\n\nbar\nfoo\n'),
3232
(b'#comment\n\nbar\nfoo\n', PASS, b'#comment\n\nbar\nfoo\n'),
33+
(
34+
b'foo\n\t#comment with indent\nbar\n',
35+
FAIL,
36+
b'\t#comment with indent\nbar\nfoo\n',
37+
),
38+
(
39+
b'bar\n\t#comment with indent\nfoo\n',
40+
PASS,
41+
b'bar\n\t#comment with indent\nfoo\n',
42+
),
3343
(b'\nfoo\nbar\n', FAIL, b'bar\n\nfoo\n'),
3444
(b'\nbar\nfoo\n', PASS, b'\nbar\nfoo\n'),
3545
(

0 commit comments

Comments
 (0)