mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2025-08-14 09:27:21 +08:00
fix-whitespace: Added test for custom charsets
This commit is contained in:
@ -29,13 +29,15 @@ def _process_line(line, is_markdown, chars_to_strip):
|
||||
# type: (bytes, bool, Optional[bytes]) -> bytes
|
||||
if line[-2:] == b'\r\n':
|
||||
eol = b'\r\n'
|
||||
line = line[:-2]
|
||||
elif line[-1:] == b'\n':
|
||||
eol = b'\n'
|
||||
line = line[:-1]
|
||||
else:
|
||||
eol = b''
|
||||
# preserve trailing two-space for non-blank lines in markdown files
|
||||
if is_markdown and (not line.isspace()) and line.endswith(b' ' + eol):
|
||||
return line.rstrip(chars_to_strip) + b' ' + eol
|
||||
if is_markdown and (not line.isspace()) and line.endswith(b' '):
|
||||
return line[:-2].rstrip(chars_to_strip) + b' ' + eol
|
||||
return line.rstrip(chars_to_strip) + eol
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user