Skip to content

Auto removal of trailing whitespace to skip binary file correctly #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 19, 2021
4 changes: 2 additions & 2 deletions main/githooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ def trim_trailing_whitespace_in_file(filename, new_file, dry_run,
with open(filename, 'rb') as fileobj:
lines = fileobj.read().decode().splitlines(True)
except UnicodeDecodeError:
return
return 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest adding a test for this case


if new_file:
line_nums = [f'1-{len(lines)}']
Expand All @@ -398,7 +398,7 @@ def trim_trailing_whitespace_in_file(filename, new_file, dry_run,
if dry_run:
modified_lines.append(str(line_num))
else:
print(f' Fixed line {line_num}')
print(f' Fixed line {filename}:{line_num}')
modified_file = True
lines[line_num-1] = after

Expand Down