Check the files a commit would commit against rule-hook's file rules, and sort .gitignore's allowlist block
CI / tests (pull_request) Failing after 2m2s

This commit is contained in:
2026-11-11 14:07:34 +01:00
parent 1fa03973a3
commit 3e289c95d9
11 changed files with 154 additions and 29 deletions
+6 -2
View File
@@ -104,6 +104,8 @@ class Breach:
detail: str
# The checkout whose log records an override of this breach.
directory: str
# Text beyond the call's own whose markers override this breach: the file a commit holds, as an Edit's text is for its file.
marked: str = ""
@dataclasses.dataclass(frozen=True)
@@ -124,7 +126,9 @@ def overrides(written: str) -> tuple[dict[str, str], list[str]]:
def check(breaches: list[Breach], written: str, markdown: bool, bash: bool) -> Checked:
granted, malformed = overrides(written)
blocking = [breach for breach in breaches if breach.rule not in granted]
# Each breach is overridden by the call's markers and by its own file's.
grants = [granted | overrides(breach.marked)[0] for breach in breaches]
blocking = [breach for breach, grant in zip(breaches, grants) if breach.rule not in grant]
messages = [f"`{marker}` names no rule below, or gives no reason." for marker in malformed] if blocking else []
where = "the command" if bash else "the text you write, as a comment line"
for rule in sorted({breach.rule for breach in blocking}):
@@ -134,7 +138,7 @@ def check(breaches: list[Breach], written: str, markdown: bool, bash: bool) -> C
continue
marker = f"<!-- rule-override {rule}: <reason> -->" if markdown else f"# rule-override {rule}: <reason>"
messages.append(f"Blocked by rule {rule}: {details}. The rule: {RULES[rule].holds}. Where it does not fit this case, add `{marker}` to {where}; larv-review rules on the reason.")
return Checked(messages, bool(blocking), [(breach, granted[breach.rule]) for breach in breaches if breach.rule in granted])
return Checked(messages, bool(blocking), [(breach, grant[breach.rule]) for breach, grant in zip(breaches, grants) if breach.rule in grant])
def command_breaches(command: str, simples: list[Simple], home: str) -> list[Breach]: