Skip to content

Commit 54a8c0a

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

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
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+
(b'foo\n\t#comment with indent\nbar\n', FAIL, b'\t#comment with indent\nbar\nfoo\n'),
34+
(b'bar\n\t#comment with indent\nfoo\n', PASS, b'bar\n\t#comment with indent\nfoo\n'),
3335
(b'\nfoo\nbar\n', FAIL, b'bar\n\nfoo\n'),
3436
(b'\nbar\nfoo\n', PASS, b'\nbar\nfoo\n'),
3537
(

0 commit comments

Comments
 (0)