Answer stability round 3: an empty argument separates no command, and two overrides on one line are read apart

This commit is contained in:
2026-10-12 23:26:07 +02:00
parent 5c306fdd51
commit 0292c1a55c
3 changed files with 25 additions and 14 deletions
+8 -6
View File
@@ -10,9 +10,9 @@ RULES = {
"ignorefile-sorted": "each block of an ignore file is sorted, since its order carries no meaning; where order matters, such as a re-include after its exclude, split the block with a blank line or a comment",
"image-pin": "a container image is pinned to its full patch version, such as node:24.18.1-bookworm-slim, or to a date-stamped tag or an @sha256: digest, so the same commit builds the same image on every day; a bot such as Renovate raises the bumps as reviewable PRs. An image that publishes no three-part tag, such as postgres:16.4, takes an override",
"no-ai-attribution": "no commit, PR, issue comment or file carries a Claude or Anthropic attribution, such as a co-author trailer or a generated-with line",
"todo-rank-check": "a committed todo.md passes ~/.claude/bin/rank_todo.py --check",
"todo-rank-check": "while todo.md has changes, staged or not, a git commit waits until ~/.claude/bin/rank_todo.py --check passes on it",
}
OVERRIDE = re.compile(r"(?:#|<!--)\s*rule-override ([a-z-]+):([^\n]*)")
OVERRIDE = re.compile(r"(?:#|<!--)\s*rule-override ([a-z-]+):([^\n]*?)(?=[ \t]*(?:#|<!--)\s*rule-override |$)", re.MULTILINE)
# [-] keeps this file from matching itself.
ATTRIBUTION = re.compile(r"co-authored[-]by:[^\n]*\b(?:claude|anthropic)\b|generated with \[?claude code", re.IGNORECASE)
SEMVER = re.compile(r"v?\d+(?:\.\d+){0,2}")
@@ -43,9 +43,11 @@ class Commit:
from_file: bool
def overrides(text: str) -> dict[str, str]:
given = {rule: reason.strip().removesuffix("-->").strip() for rule, reason in OVERRIDE.findall(text)}
return {rule: reason for rule, reason in given.items() if rule in RULES and reason}
def overrides(text: str) -> tuple[dict[str, str], list[str]]:
"""The rules the text overrides with their reasons, and the markers that name no rule or give no reason."""
given = [(rule, reason.strip().removesuffix("-->").strip()) for rule, reason in OVERRIDE.findall(text)]
granted = {rule: reason for rule, reason in given if rule in RULES and reason}
return granted, [f"rule-override {rule}: {reason}" for rule, reason in given if rule not in granted]
def segments(command: str) -> list[list[str]] | None:
@@ -61,7 +63,7 @@ def segments(command: str) -> list[list[str]] | None:
split: list[list[str]] = [[]]
for word in words:
# Unquoted, a run such as "&&\n" lexes as one word.
if set(word) <= SEPARATING:
if word and set(word) <= SEPARATING:
split.append([])
else:
split[-1].append(word)