[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2026-04-03 08:47:37 +00:00
parent 4842364696
commit a455566742
3 changed files with 12 additions and 11 deletions

View file

@ -30,7 +30,7 @@ def _process_line(
is_markdown: bool, is_markdown: bool,
chars: bytes | None, chars: bytes | None,
line_num: int, line_num: int,
error_lines: list[int] | None error_lines: list[int] | None,
) -> bytes: ) -> bytes:
org_line = line org_line = line
if line[-2:] == b'\r\n': if line[-2:] == b'\r\n':
@ -46,7 +46,7 @@ def _process_line(
return line[:-2].rstrip(chars) + b' ' + eol return line[:-2].rstrip(chars) + b' ' + eol
result = line.rstrip(chars) + eol result = line.rstrip(chars) + eol
if error_lines is not None and org_line != result: if error_lines is not None and org_line != result:
error_lines.append(line_num+1) error_lines.append(line_num + 1)
return result return result
@ -106,8 +106,8 @@ def main(argv: Sequence[str] | None = None) -> int:
error_lines = [] error_lines = []
if _fix_file(filename, md, chars, args.check, error_lines): if _fix_file(filename, md, chars, args.check, error_lines):
if args.check: if args.check:
location = ",".join(map(str, error_lines[:4])) location = ','.join(map(str, error_lines[:4]))
location += "..." if len(error_lines) > 4 else "" location += '...' if len(error_lines) > 4 else ''
print(f'Trailing whitespace check failed: {filename} @ {location}') print(f'Trailing whitespace check failed: {filename} @ {location}')
else: else:
print(f'Fixing {filename}') print(f'Fixing {filename}')

View file

@ -44,7 +44,7 @@ def test_fix_file(input_s, expected_retval, output, options):
options = [options] options = [options]
file_obj = io.BytesIO(input_s) 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 file_obj.getvalue() == output
assert ret == expected_retval assert ret == expected_retval

View file

@ -18,21 +18,22 @@ def test_fixes_trailing_whitespace(input_s, expected, tmpdir):
assert main((str(path),)) == 1 assert main((str(path),)) == 1
assert path.read() == expected assert path.read() == expected
@pytest.mark.parametrize( @pytest.mark.parametrize(
('input_s', 'exit_code', "lines"), ('input_s', 'exit_code', 'lines'),
( (
('foo \nbar \n', 1, [1,2]), ('foo \nbar \n', 1, [1, 2]),
('bar\t\nbaz\t\n', 1, [1,2]), ('bar\t\nbaz\t\n', 1, [1, 2]),
('bar\nbaz\t\n', 1, [2]), ('bar\nbaz\t\n', 1, [2]),
), ),
) )
def test_fixes_trailing_whitespace_check_only(capsys, input_s, exit_code, lines, tmpdir): def test_fixes_trailing_whitespace_check_only(capsys, input_s, exit_code, lines, tmpdir):
path = tmpdir.join('file.md') path = tmpdir.join('file.md')
path.write(input_s) path.write(input_s)
assert main(('--check', str(path),)) == exit_code assert main(('--check', str(path))) == exit_code
assert path.read() == input_s assert path.read() == input_s
captured = capsys.readouterr() captured = capsys.readouterr()
location = "@ " + ','.join(map(str, lines)) location = '@ ' + ','.join(map(str, lines))
assert location in captured.out assert location in captured.out