mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-09 12:54:17 +00:00
Merge pull request #944 from RoelAdriaans/file-content-sorted-blank-line-fix
Fix blank lines in file-contents-sorter plugin
This commit is contained in:
commit
61b5f7e6f7
2 changed files with 7 additions and 2 deletions
|
|
@ -37,7 +37,10 @@ def sort_file_contents(
|
||||||
after = sorted(lines, key=key)
|
after = sorted(lines, key=key)
|
||||||
|
|
||||||
before_string = b''.join(before)
|
before_string = b''.join(before)
|
||||||
after_string = b'\n'.join(after) + b'\n'
|
after_string = b'\n'.join(after)
|
||||||
|
|
||||||
|
if after_string:
|
||||||
|
after_string += b'\n'
|
||||||
|
|
||||||
if before_string == after_string:
|
if before_string == after_string:
|
||||||
return PASS
|
return PASS
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,9 @@ from pre_commit_hooks.file_contents_sorter import PASS
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
('input_s', 'argv', 'expected_retval', 'output'),
|
('input_s', 'argv', 'expected_retval', 'output'),
|
||||||
(
|
(
|
||||||
(b'', [], FAIL, b'\n'),
|
(b'', [], PASS, b''),
|
||||||
|
(b'\n', [], FAIL, b''),
|
||||||
|
(b'\n\n', [], FAIL, b''),
|
||||||
(b'lonesome\n', [], PASS, b'lonesome\n'),
|
(b'lonesome\n', [], PASS, b'lonesome\n'),
|
||||||
(b'missing_newline', [], FAIL, b'missing_newline\n'),
|
(b'missing_newline', [], FAIL, b'missing_newline\n'),
|
||||||
(b'newline\nmissing', [], FAIL, b'missing\nnewline\n'),
|
(b'newline\nmissing', [], FAIL, b'missing\nnewline\n'),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue