Skip to content

Commit acd3d4e

Browse files
Fix hooks printing errors to stderr instead of stdout (#1844)
* Initial plan * Fix hooks to print errors to stdout instead of stderr and remove success messages The hooks were printing error output to stderr and a success message to stdout. In a pre-commit/prek context, stdout is the standard output stream for hook output. Using stderr for errors meant violations could go unseen while the success message on stdout always appeared. Changes: - check-docstring-substrings.py: errors to stdout, removed success msg - check-comment-keywords.py: errors to stdout, removed success msg - check-banned-words.py: errors to stdout, removed success msg - Removed unused sys imports from all three hooks Agent-Logs-Url: https://github.com/usethis-python/usethis-python/sessions/16f73dc6-f9ed-489f-aabd-b89069012a57 Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: nathanjmcdougall <18602289+nathanjmcdougall@users.noreply.github.com>
1 parent 5eb75b1 commit acd3d4e

3 files changed

Lines changed: 7 additions & 16 deletions

File tree

hooks/check-banned-words.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import argparse
1212
import re
13-
import sys
1413
from pathlib import Path
1514

1615

@@ -35,7 +34,7 @@ def main() -> int:
3534
own_name = Path(__file__).name
3635

3736
if not hooks_dir.is_dir():
38-
print(f"ERROR: {hooks_dir} is not a directory.", file=sys.stderr)
37+
print(f"ERROR: {hooks_dir} is not a directory.")
3938
return 1
4039

4140
violations: list[str] = []
@@ -52,15 +51,11 @@ def main() -> int:
5251
violations.append(f" {py_file}:{lineno}: {line.strip()}")
5352

5453
if violations:
55-
print(
56-
"ERROR: Banned word(s) found in hook scripts:",
57-
file=sys.stderr,
58-
)
54+
print("ERROR: Banned word(s) found in hook scripts:")
5955
for v in violations:
60-
print(v, file=sys.stderr)
56+
print(v)
6157
return 1
6258

63-
print("No banned words found in hook scripts.")
6459
return 0
6560

6661

hooks/check-comment-keywords.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from __future__ import annotations
99

1010
import argparse
11-
import sys
1211
import tokenize
1312

1413

@@ -37,12 +36,11 @@ def main() -> int:
3736
violations.extend(_check_file(filepath, keywords))
3837

3938
if violations:
40-
print("ERROR: Banned comment keyword(s) found:", file=sys.stderr)
39+
print("ERROR: Banned comment keyword(s) found:")
4140
for v in violations:
42-
print(v, file=sys.stderr)
41+
print(v)
4342
return 1
4443

45-
print("No banned comment keywords found.")
4644
return 0
4745

4846

hooks/check-docstring-substrings.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import argparse
1111
import ast
1212
import re
13-
import sys
1413

1514

1615
def main() -> int:
@@ -38,12 +37,11 @@ def main() -> int:
3837
violations.extend(_check_file(filepath, compiled))
3938

4039
if violations:
41-
print("ERROR: Forbidden pattern(s) found in docstrings:", file=sys.stderr)
40+
print("ERROR: Forbidden pattern(s) found in docstrings:")
4241
for v in violations:
43-
print(v, file=sys.stderr)
42+
print(v)
4443
return 1
4544

46-
print("No forbidden patterns found in docstrings.")
4745
return 0
4846

4947

0 commit comments

Comments
 (0)