Skip to content

The agent that grows with you

fix(code-health): an allow comment may separate its rules with spaces

Teknium7ef5f0e1f95b
diff --git a/scripts/code_health/report.py b/scripts/code_health/report.py
index 5afad1fedb0..2efe4af027c 100644
--- a/scripts/code_health/report.py
+++ b/scripts/code_health/report.py
@@ -33,7 +33,8 @@ def apply_allows(findings: list[Finding], head: dict[str, FileMeasure]) -> None:
for line_no in _allow_lines(finding, fm):
text = fm.comments.get(line_no, "")
match = _ALLOW.search(text)
- if match and finding.rule in {r.strip() for r in match.group(1).split(",")}:
+ # `allow BLE001 S110` and `allow BLE001, S110` both name two rules (_ALLOW takes either).
+ if match and finding.rule in re.split(r"[,\s]+", match.group(1).strip()):
finding.allowed_reason = match.group(2).strip()
break
if _ALLOW_BARE.search(text) and finding.rule in text:
diff --git a/tests/scripts/test_code_health_cli.py b/tests/scripts/test_code_health_cli.py
index c24ee13cc59..b40ca698b92 100644
--- a/tests/scripts/test_code_health_cli.py
+++ b/tests/scripts/test_code_health_cli.py
@@ -153,6 +153,18 @@ def test_json_stdout_is_json_on_every_path(tmp_path, capsys, case, switch, files
assert "code health:" in err # the human explanation moves to stderr
+# --- allow comments may list several rules ----------------------------------------------------
+
+
[email protected]("rules", ["BLE001 S110", "BLE001, S110", "BLE001,S110"])
+def test_allow_comment_lists_rules_by_comma_or_space(tmp_path, capsys, rules):
+ repo, base = _ratchet_repo(tmp_path)
+ swallow = ("def other():\n try:\n pass\n"
+ f" except Exception: # health: allow {rules} -- boundary\n pass\n")
+ head = _commit(repo, {"pkg/b.py": swallow})
+ assert cli.run(repo, base, head) == 0, capsys.readouterr().out
+
+
# --- measurement tooling failures are errors, not findings ------------------------------------