mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2025-08-14 01:00:21 +08:00
Fix blank lines
As stated in the documentation: `Note that this hook WILL remove blank lines` Previously this hook would always add blank a blank line. With this fix, if the file is empty, a newline will not be added, and multpline blanklines in a file will be removed. Fixes #935
This commit is contained in:
@ -37,7 +37,10 @@ def sort_file_contents(
|
||||
after = sorted(lines, key=key)
|
||||
|
||||
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:
|
||||
return PASS
|
||||
|
Reference in New Issue
Block a user