Skip to content

Commit 372afe4

Browse files
authored
Merge pull request #748 from pre-commit/adjust-error-outputs
adjust error outputs to be more standardized
2 parents 3adbd36 + b13ff9b commit 372afe4

File tree

6 files changed

+22
-13
lines changed

6 files changed

+22
-13
lines changed

pre_commit_hooks/check_docstring_first.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ def check_docstring_first(src: bytes, filename: str = '<unknown>') -> int:
2828
if tok_type == tokenize.STRING and scol == 0:
2929
if found_docstring_line is not None:
3030
print(
31-
f'{filename}:{sline} Multiple module docstrings '
31+
f'{filename}:{sline}: Multiple module docstrings '
3232
f'(first docstring on line {found_docstring_line}).',
3333
)
3434
return 1
3535
elif found_code_line is not None:
3636
print(
37-
f'{filename}:{sline} Module docstring appears after code '
37+
f'{filename}:{sline}: Module docstring appears after code '
3838
f'(code seen on line {found_code_line}).',
3939
)
4040
return 1

pre_commit_hooks/check_merge_conflict.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
CONFLICT_PATTERNS = [
1111
b'<<<<<<< ',
1212
b'======= ',
13+
b'=======\r\n',
1314
b'=======\n',
1415
b'>>>>>>> ',
1516
]
@@ -39,12 +40,12 @@ def main(argv: Sequence[str] | None = None) -> int:
3940
retcode = 0
4041
for filename in args.filenames:
4142
with open(filename, 'rb') as inputfile:
42-
for i, line in enumerate(inputfile):
43+
for i, line in enumerate(inputfile, start=1):
4344
for pattern in CONFLICT_PATTERNS:
4445
if line.startswith(pattern):
4546
print(
46-
f'Merge conflict string "{pattern.decode()}" '
47-
f'found in {filename}:{i + 1}',
47+
f'{filename}:{i}: Merge conflict string '
48+
f'{pattern.strip().decode()!r} found',
4849
)
4950
retcode = 1
5051

pre_commit_hooks/debug_statement_hook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def check_file(filename: str) -> int:
6565
visitor.visit(ast_obj)
6666

6767
for bp in visitor.breakpoints:
68-
print(f'{filename}:{bp.line}:{bp.col} - {bp.name} {bp.reason}')
68+
print(f'{filename}:{bp.line}:{bp.col}: {bp.name} {bp.reason}')
6969

7070
return int(bool(visitor.breakpoints))
7171

tests/check_docstring_first_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
b'from __future__ import unicode_literals\n'
1818
b'"foo"\n',
1919
1,
20-
'{filename}:2 Module docstring appears after code '
20+
'{filename}:2: Module docstring appears after code '
2121
'(code seen on line 1).\n',
2222
),
2323
# Test double docstring
@@ -26,7 +26,7 @@
2626
b'from __future__ import absolute_import\n'
2727
b'"fake docstring"\n',
2828
1,
29-
'{filename}:3 Multiple module docstrings '
29+
'{filename}:3: Multiple module docstrings '
3030
'(first docstring on line 1).\n',
3131
),
3232
# Test multiple lines of code above
@@ -35,7 +35,7 @@
3535
b'import sys\n'
3636
b'"docstring"\n',
3737
1,
38-
'{filename}:3 Module docstring appears after code '
38+
'{filename}:3: Module docstring appears after code '
3939
'(code seen on line 1).\n',
4040
),
4141
# String literals in expressions are ok.

tests/check_merge_conflict_test.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,14 @@ def repository_pending_merge(tmpdir):
101101

102102

103103
@pytest.mark.usefixtures('f1_is_a_conflict_file')
104-
def test_merge_conflicts_git():
104+
def test_merge_conflicts_git(capsys):
105105
assert main(['f1']) == 1
106+
out, _ = capsys.readouterr()
107+
assert out == (
108+
"f1:1: Merge conflict string '<<<<<<<' found\n"
109+
"f1:3: Merge conflict string '=======' found\n"
110+
"f1:5: Merge conflict string '>>>>>>>' found\n"
111+
)
106112

107113

108114
@pytest.mark.parametrize(
@@ -139,7 +145,7 @@ def test_care_when_assumed_merge(tmpdir):
139145
assert main([str(f.realpath()), '--assume-in-merge']) == 1
140146

141147

142-
def test_worktree_merge_conflicts(f1_is_a_conflict_file, tmpdir):
148+
def test_worktree_merge_conflicts(f1_is_a_conflict_file, tmpdir, capsys):
143149
worktree = tmpdir.join('worktree')
144150
cmd_output('git', 'worktree', 'add', str(worktree))
145151
with worktree.as_cwd():
@@ -148,4 +154,4 @@ def test_worktree_merge_conflicts(f1_is_a_conflict_file, tmpdir):
148154
)
149155
msg = f1_is_a_conflict_file.join('.git/worktrees/worktree/MERGE_MSG')
150156
assert msg.exists()
151-
test_merge_conflicts_git()
157+
test_merge_conflicts_git(capsys)

tests/debug_statement_hook_test.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ def test_non_utf8_file(tmpdir):
5555
assert main((str(f_py),)) == 0
5656

5757

58-
def test_py37_breakpoint(tmpdir):
58+
def test_py37_breakpoint(tmpdir, capsys):
5959
f_py = tmpdir.join('f.py')
6060
f_py.write('def f():\n breakpoint()\n')
6161
assert main((str(f_py),)) == 1
62+
out, _ = capsys.readouterr()
63+
assert out == f'{f_py}:2:4: breakpoint called\n'

0 commit comments

Comments
 (0)