diff --git a/pre_commit_hooks/trailing_whitespace_fixer.py b/pre_commit_hooks/trailing_whitespace_fixer.py index 20a4ced..fc6dc86 100644 --- a/pre_commit_hooks/trailing_whitespace_fixer.py +++ b/pre_commit_hooks/trailing_whitespace_fixer.py @@ -30,7 +30,7 @@ def _process_line( is_markdown: bool, chars: bytes | None, line_num: int, - error_lines: list[int] | None + error_lines: list[int] | None, ) -> bytes: org_line = line if line[-2:] == b'\r\n': @@ -46,7 +46,7 @@ def _process_line( return line[:-2].rstrip(chars) + b' ' + eol result = line.rstrip(chars) + eol if error_lines is not None and org_line != result: - error_lines.append(line_num+1) + error_lines.append(line_num + 1) return result @@ -106,8 +106,8 @@ def main(argv: Sequence[str] | None = None) -> int: error_lines = [] if _fix_file(filename, md, chars, args.check, error_lines): if args.check: - location = ",".join(map(str, error_lines[:4])) - location += "..." if len(error_lines) > 4 else "" + location = ','.join(map(str, error_lines[:4])) + location += '...' if len(error_lines) > 4 else '' print(f'Trailing whitespace check failed: {filename} @ {location}') else: print(f'Fixing {filename}') diff --git a/tests/end_of_file_fixer_test.py b/tests/end_of_file_fixer_test.py index a5349d5..db6ef35 100644 --- a/tests/end_of_file_fixer_test.py +++ b/tests/end_of_file_fixer_test.py @@ -44,7 +44,7 @@ def test_fix_file(input_s, expected_retval, output, options): options = [options] file_obj = io.BytesIO(input_s) - ret = fix_file(file_obj, "--check" in [*options]) + ret = fix_file(file_obj, '--check' in [*options]) assert file_obj.getvalue() == output assert ret == expected_retval diff --git a/tests/trailing_whitespace_fixer_test.py b/tests/trailing_whitespace_fixer_test.py index fc221e2..949d420 100644 --- a/tests/trailing_whitespace_fixer_test.py +++ b/tests/trailing_whitespace_fixer_test.py @@ -18,21 +18,22 @@ def test_fixes_trailing_whitespace(input_s, expected, tmpdir): assert main((str(path),)) == 1 assert path.read() == expected + @pytest.mark.parametrize( - ('input_s', 'exit_code', "lines"), + ('input_s', 'exit_code', 'lines'), ( - ('foo \nbar \n', 1, [1,2]), - ('bar\t\nbaz\t\n', 1, [1,2]), - ('bar\nbaz\t\n', 1, [2]), + ('foo \nbar \n', 1, [1, 2]), + ('bar\t\nbaz\t\n', 1, [1, 2]), + ('bar\nbaz\t\n', 1, [2]), ), ) def test_fixes_trailing_whitespace_check_only(capsys, input_s, exit_code, lines, tmpdir): path = tmpdir.join('file.md') path.write(input_s) - assert main(('--check', str(path),)) == exit_code + assert main(('--check', str(path))) == exit_code assert path.read() == input_s captured = capsys.readouterr() - location = "@ " + ','.join(map(str, lines)) + location = '@ ' + ','.join(map(str, lines)) assert location in captured.out