File size: 2,420 Bytes
3181a66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/env python3
"""Reject self-evaluative marketing phrases on reader-facing surfaces."""

from __future__ import annotations

import re
import sys
from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
PUBLIC_FILES = {
    ROOT / "README.md",
    ROOT / "CONTRIBUTING.md",
    ROOT / "DEFINITION.md",
    ROOT / "CITATION.cff",
    ROOT / "CITATION.bib",
    ROOT / "TRANSLATIONS.md",
    ROOT / "data" / "README.md",
    ROOT / "docs" / "index.html",
    ROOT / "docs" / "llms.txt",
    ROOT / "meta" / "DISTRIBUTION.md",
    ROOT / "meta" / "CURATION.md",
    ROOT / "meta" / "OUTREACH.md",
    ROOT / "meta" / "hf_card_body.md",
    ROOT / "meta" / "social-preview.html",
    ROOT / "posts" / "launch.md",
    ROOT / "posts" / "launch.zh-CN.md",
    ROOT / ".github" / "pull_request_template.md",
}
PUBLIC_FILES.update(ROOT.glob("README.*.md"))
PUBLIC_FILES.update((ROOT / "docs").glob("x-v*.html"))

BANNED_PHRASES = {
    "source-audited": re.compile(r"source[ -]audited", re.IGNORECASE),
    "audited resources": re.compile(r"audited (?:resources|works)", re.IGNORECASE),
    "canonical source": re.compile(r"canonical source", re.IGNORECASE),
    "canonical README": re.compile(r"canonical README", re.IGNORECASE),
    "curated marketing claim": re.compile(
        r"curated (?:field guide|map|resources|order|lists)", re.IGNORECASE
    ),
    "process-first heading": re.compile(
        r"(?:maintainer picks|trust and provenance|audit snapshot)", re.IGNORECASE
    ),
}


def main() -> int:
    failures: list[str] = []
    for path in sorted(PUBLIC_FILES):
        if not path.exists():
            failures.append(f"missing public surface: {path.relative_to(ROOT)}")
            continue
        for line_number, line in enumerate(path.read_text(encoding="utf-8").splitlines(), 1):
            for label, pattern in BANNED_PHRASES.items():
                if pattern.search(line):
                    failures.append(
                        f"{path.relative_to(ROOT)}:{line_number}: {label}: {line.strip()}"
                    )

    if failures:
        print("Reader-facing copy uses process-first language:", file=sys.stderr)
        for failure in failures:
            print(f"- {failure}", file=sys.stderr)
        return 1

    print(f"Reader-facing copy check passed across {len(PUBLIC_FILES)} files.")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())