Merge pull request #549 from greshilov/fix-comments-with-indents
Fix comments with indents
diff --git a/pre_commit_hooks/requirements_txt_fixer.py b/pre_commit_hooks/requirements_txt_fixer.py
index 2412633..351e5b1 100644
--- a/pre_commit_hooks/requirements_txt_fixer.py
+++ b/pre_commit_hooks/requirements_txt_fixer.py
@@ -95,7 +95,7 @@
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)
diff --git a/tests/requirements_txt_fixer_test.py b/tests/requirements_txt_fixer_test.py
index f4f679d..e3c6ed5 100644
--- a/tests/requirements_txt_fixer_test.py
+++ b/tests/requirements_txt_fixer_test.py
@@ -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'),
(