diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml index a22350f..1178584 100644 --- a/.github/workflows/website.yml +++ b/.github/workflows/website.yml @@ -35,6 +35,9 @@ jobs: cache: npm cache-dependency-path: website/package-lock.json + - name: Check docs style + run: python3 scripts/check_docs_style.py + - name: Install dependencies run: npm ci diff --git a/website/STYLE.md b/website/STYLE.md index 78709f7..0e7d297 100644 --- a/website/STYLE.md +++ b/website/STYLE.md @@ -52,3 +52,13 @@ These rules apply to every page under `website/src/content/docs/`. Pages that fo paragraph to the end of a section or page. - Don't repeat a rule that another page owns. Link to it instead, for example to `rules/overview#exceptions` for how exceptions match findings. + +## Automated checks + +Run `python3 website/scripts/check_docs_style.py` before opening a pull request (also enforced by +`.github/workflows/website.yml`): + +- Page line budget: 450 lines by default (split or condense before raising a budget). +- Navigation `` descriptions: max 90 characters. +- No release-note or version-history phrases (`earlier versions`, `earlier releases`, `formerly`, + `replaces the former`, `release note:`, `upgrade note:`). diff --git a/website/scripts/check_docs_style.py b/website/scripts/check_docs_style.py new file mode 100644 index 0000000..68e6867 --- /dev/null +++ b/website/scripts/check_docs_style.py @@ -0,0 +1,95 @@ +"""Check SQLClean docs pages against website/STYLE.md guardrails.""" + +from __future__ import annotations + +import re +import sys +from pathlib import Path + +DEFAULT_MAX_LINES = 450 +MAX_CARD_CHARS = 90 + +# Explicit line-budget exceptions for comprehensive single-page references. +LINE_LIMIT_OVERRIDES: dict[str, int] = {} + +# Phrases that indicate release-note or version-history wording in user docs. +HISTORY_PATTERNS: list[tuple[str, re.Pattern[str]]] = [ + ("release note", re.compile(r"\brelease note\s*:", re.IGNORECASE)), + ("upgrade note", re.compile(r"\bupgrade note\s*:", re.IGNORECASE)), + ("earlier versions", re.compile(r"\bearlier versions?\b", re.IGNORECASE)), + ("earlier releases", re.compile(r"\bearlier releases?\b", re.IGNORECASE)), + ("replaces the former", re.compile(r"\breplaces the former\b", re.IGNORECASE)), + ("formerly", re.compile(r"\bformerly\b", re.IGNORECASE)), +] + +CARD_RE = re.compile(r"]*>(.*?)", re.DOTALL) + + +def strip_fenced_blocks(text: str) -> list[tuple[int, str]]: + """Return (1-based line number, line text) for lines outside fenced code blocks.""" + result: list[tuple[int, str]] = [] + in_fence = False + for lineno, line in enumerate(text.splitlines(), start=1): + stripped = line.lstrip() + if stripped.startswith("```"): + in_fence = not in_fence + continue + if not in_fence: + result.append((lineno, line)) + return result + + +def check_file(docs_root: Path, path: Path) -> list[str]: + errors: list[str] = [] + rel = path.relative_to(docs_root).as_posix() + text = path.read_text(encoding="utf-8") + lines = text.splitlines() + + limit = LINE_LIMIT_OVERRIDES.get(rel, DEFAULT_MAX_LINES) + if len(lines) > limit: + errors.append( + f"{rel}: {len(lines)} lines exceeds budget of {limit} " + "(split or condense per website/STYLE.md)" + ) + + for lineno, line in strip_fenced_blocks(text): + for label, pattern in HISTORY_PATTERNS: + if pattern.search(line): + errors.append( + f"{rel}:{lineno}: history wording ({label!r}); " + "describe current behavior only (see website/STYLE.md)" + ) + + for match in CARD_RE.finditer(text): + body = " ".join(match.group(1).split()) + if len(body) > MAX_CARD_CHARS: + lineno = text[: match.start()].count("\n") + 1 + errors.append( + f"{rel}:{lineno}: description is {len(body)} chars " + f"(max {MAX_CARD_CHARS}): {body!r}" + ) + + return errors + + +def main() -> int: + default_root = Path(__file__).resolve().parent.parent / "src/content/docs/docs" + docs_root = Path(sys.argv[1]) if len(sys.argv) > 1 else default_root + if not docs_root.is_dir(): + print(f"error: docs directory not found: {docs_root}", file=sys.stderr) + return 2 + + files = sorted(docs_root.rglob("*.mdx")) + errors: list[str] = [] + for path in files: + errors.extend(check_file(docs_root, path)) + + for error in errors: + print(error, file=sys.stderr) + + print(f"{len(files)} docs pages checked, {len(errors)} style issue(s)") + return 1 if errors else 0 + + +if __name__ == "__main__": + raise SystemExit(main())