Skip to content

Commit 16fa716

Browse files
committed
Fix overly aggressive filtering of clang-tidy errors
Previous filter removed legitimate error messages. Now only filters: - Lines containing macOS SDK paths - Notes that directly follow SDK lines - 'Error while processing' only when preceded by SDK errors This preserves expected errors from test files while filtering SDK noise.
1 parent 41946d7 commit 16fa716

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

tests/test_hooks.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -466,18 +466,36 @@ def run_shell_cmd(cmd_name, files, args, _, target_output, target_retcode):
466466
if cmd_name == "clang-tidy":
467467
# Filter warnings count
468468
filtered_actual = re.sub(rb"\d+ warnings? generated\.\n", b"", actual)
469-
# Filter errors from macOS SDK system headers
470-
filtered_actual = re.sub(
471-
rb"^.*?/Applications/Xcode[^\n]*?/MacOSX\.sdk/[^\n]*\n", b"", filtered_actual, flags=re.MULTILINE
472-
)
473-
# Filter "X errors generated." from system header errors
474-
filtered_actual = re.sub(rb"\d+ errors? generated\.\n", b"", filtered_actual)
475-
# Filter "Error while processing..." lines
476-
filtered_actual = re.sub(rb"^Error while processing [^\n]*\n", b"", filtered_actual, flags=re.MULTILINE)
477-
# Filter "error:" lines from system headers
478-
filtered_actual = re.sub(rb"^error: too many errors emitted[^\n]*\n", b"", filtered_actual, flags=re.MULTILINE)
479-
# Filter "note:" lines that follow system header errors
480-
filtered_actual = re.sub(rb"^note: [^\n]*\n", b"", filtered_actual, flags=re.MULTILINE)
469+
# Filter errors from macOS SDK system headers (entire lines containing SDK paths)
470+
# Only filter lines that contain the macOS SDK path
471+
lines = filtered_actual.split(b"\n")
472+
filtered_lines = []
473+
skip_next_error_processing = False
474+
for i, line in enumerate(lines):
475+
# Skip lines containing macOS SDK paths
476+
if b"/Applications/Xcode" in line and b"/MacOSX.sdk/" in line:
477+
continue
478+
# Skip "note:" lines that directly follow SDK path lines
479+
if line.startswith(b"note: ") and i > 0 and (
480+
b"/Applications/Xcode" in lines[i-1] and b"/MacOSX.sdk/" in lines[i-1]
481+
):
482+
continue
483+
# Skip "error: too many errors emitted" which only appears with system header errors
484+
if line.startswith(b"error: too many errors emitted"):
485+
skip_next_error_processing = True
486+
continue
487+
# Skip "X errors generated." when preceded by system header errors
488+
if line.strip() and re.match(rb"\d+ errors? generated\.$", line.strip()):
489+
# Check if we've seen SDK paths earlier
490+
if any(b"/MacOSX.sdk/" in l for l in lines[:i]):
491+
skip_next_error_processing = True
492+
continue
493+
# Skip "Error while processing" only if it follows system header errors
494+
if line.startswith(b"Error while processing") and skip_next_error_processing:
495+
skip_next_error_processing = False
496+
continue
497+
filtered_lines.append(line)
498+
filtered_actual = b"\n".join(filtered_lines)
481499
# If we filtered warnings/errors and got exit code 1, normalize to 0 if output matches expected
482500
if filtered_actual != actual and sp_child.returncode == 1:
483501
# clang-tidy returns 1 when warnings/errors are generated, but if we filtered them

0 commit comments

Comments
 (0)