mirror of
https://github.com/pre-commit/pre-commit-hooks.git
synced 2026-04-05 11:36:54 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
4842364696
commit
a455566742
3 changed files with 12 additions and 11 deletions
|
|
@ -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}')
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue