mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-04 11:16:53 +00:00
Merge pull request #243 from pre-commit/comment_only_requirements_txt
Fix requirements-txt-fixer for comments at end of file
This commit is contained in:
commit
361a6ac1bc
2 changed files with 9 additions and 0 deletions
|
|
@ -63,9 +63,16 @@ def fix_requirements(f):
|
|||
else:
|
||||
requirement.value = line
|
||||
|
||||
# if a file ends in a comment, preserve it at the end
|
||||
if requirements[-1].value is None:
|
||||
rest = requirements.pop().comments
|
||||
else:
|
||||
rest = []
|
||||
|
||||
for requirement in sorted(requirements):
|
||||
after.extend(requirement.comments)
|
||||
after.append(requirement.value)
|
||||
after.extend(rest)
|
||||
|
||||
after_string = b''.join(after)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue