mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 11:36:54 +00:00
Merge pull request #549 from greshilov/fix-comments-with-indents
Fix comments with indents
This commit is contained in:
commit
43f5ffaeab
2 changed files with 11 additions and 1 deletions
|
|
@ -95,7 +95,7 @@ def fix_requirements(f: IO[bytes]) -> int:
|
||||||
requirement.value = b'\n'
|
requirement.value = b'\n'
|
||||||
else:
|
else:
|
||||||
requirement.comments.append(line)
|
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)
|
requirement.comments.append(line)
|
||||||
else:
|
else:
|
||||||
requirement.append_value(line)
|
requirement.append_value(line)
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,16 @@ from pre_commit_hooks.requirements_txt_fixer import Requirement
|
||||||
),
|
),
|
||||||
(b'#comment\n\nfoo\nbar\n', FAIL, b'#comment\n\nbar\nfoo\n'),
|
(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'#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'\nfoo\nbar\n', FAIL, b'bar\n\nfoo\n'),
|
||||||
(b'\nbar\nfoo\n', PASS, b'\nbar\nfoo\n'),
|
(b'\nbar\nfoo\n', PASS, b'\nbar\nfoo\n'),
|
||||||
(
|
(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue