Skip to content

Commit

Permalink
Merge pull request #549 from greshilov/fix-comments-with-indents
Browse files Browse the repository at this point in the history
Fix comments with indents
  • Loading branch information
asottile committed Jan 17, 2021
2 parents a6add1c + 28b2c8e commit 43f5ffa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pre_commit_hooks/requirements_txt_fixer.py
Expand Up @@ -95,7 +95,7 @@ def fix_requirements(f: IO[bytes]) -> int:
requirement.value = b'\n'
else:
requirement.comments.append(line)
elif line.startswith(b'#') or line.strip() == b'':
elif line.lstrip().startswith(b'#') or line.strip() == b'':
requirement.comments.append(line)
else:
requirement.append_value(line)
Expand Down
10 changes: 10 additions & 0 deletions tests/requirements_txt_fixer_test.py
Expand Up @@ -30,6 +30,16 @@
),
(b'#comment\n\nfoo\nbar\n', FAIL, b'#comment\n\nbar\nfoo\n'),
(b'#comment\n\nbar\nfoo\n', PASS, b'#comment\n\nbar\nfoo\n'),
(
b'foo\n\t#comment with indent\nbar\n',
FAIL,
b'\t#comment with indent\nbar\nfoo\n',
),
(
b'bar\n\t#comment with indent\nfoo\n',
PASS,
b'bar\n\t#comment with indent\nfoo\n',
),
(b'\nfoo\nbar\n', FAIL, b'bar\n\nfoo\n'),
(b'\nbar\nfoo\n', PASS, b'\nbar\nfoo\n'),
(
Expand Down

0 comments on commit 43f5ffa

Please sign in to comment.