Skip to content

Commit 50a0038

Browse files
ci(antipattern): TS check reads .claude/CLAUDE.md exemption table (#14)
Replaces the static grep-chain TS check with a python step that: - Applies the universal builtin allowlist (bindings/, tests/, scripts/, mcp-adapter/, *vscode*/, cli/, mod.ts, lsp-server.ts, deno-*/, etc.) - **Reads the per-repo `.claude/CLAUDE.md` 'TypeScript Exemptions' table at CI time** and treats each `Path` row as allowed. Why: the previous static allowlist required editing the workflow whenever a legitimate per-repo exemption was needed. This made the per-repo `.claude/CLAUDE.md` exemption table (the documented source of truth) and the workflow drift apart. Now they're the same single source. To exempt a path going forward: add one row to `.claude/CLAUDE.md`'s 'TypeScript Exemptions' table — no workflow edit required. To migrate off TS: see Human_Programming_Guide.adoc migration chapter (in affinescript repo).
1 parent 5962a09 commit 50a0038

1 file changed

Lines changed: 79 additions & 32 deletions

File tree

.github/workflows/rsr-antipattern.yml

Lines changed: 79 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,85 @@ jobs:
2323

2424
- name: Check for TypeScript
2525
run: |
26-
# Allowlist (TS legitimate as a bridge/adapter to a non-ReScript ecosystem):
27-
# bindings/ - language bindings (Deno/TS/AssemblyScript FFI)
28-
# *.d.ts - TypeScript type declarations for ReScript FFI
29-
# tests/, test/ - Deno test runners
30-
# scripts/ - Deno build scripts
31-
# mcp-adapter/ - MCP server adapters (MCP is Deno/TS-typed by spec)
32-
# *vscode* - VSCode extensions (TS is the ecosystem default)
33-
# cli/ - CLI entry points (Deno scripts)
34-
# mod.ts - canonical Deno module entrypoint
35-
# *lsp-server.ts, *lsp.ts - Language Server Protocol implementations
36-
# deno-*/ - subprojects explicitly named for Deno
37-
TS_FILES=$(find . \( -name "*.ts" -o -name "*.tsx" \) \
38-
| grep -v node_modules \
39-
| grep -v '/bindings/' \
40-
| grep -v '\.d\.ts$' \
41-
| grep -v '/tests/' \
42-
| grep -v '/test/' \
43-
| grep -v '/scripts/' \
44-
| grep -v '/mcp-adapter/' \
45-
| grep -Ev '/[^/]*vscode[^/]*/' \
46-
| grep -v '/cli/' \
47-
| grep -v '/mod\.ts$' \
48-
| grep -Ev 'lsp[-_]?server\.ts$' \
49-
| grep -Ev '[/-]lsp\.ts$' \
50-
| grep -Ev '/deno-[^/]+/' \
51-
|| true)
52-
if [ -n "$TS_FILES" ]; then
53-
echo "❌ TypeScript files detected - use ReScript instead"
54-
echo "$TS_FILES"
55-
exit 1
56-
fi
57-
echo "✅ No TypeScript files outside allowlisted bridge/adapter paths"
26+
python3 << 'PYEOF'
27+
import re, sys, fnmatch, pathlib
28+
29+
# Universal builtin allowlist — bridges that need no per-repo declaration.
30+
# Files matching any of these patterns are always allowed.
31+
BUILTIN_GLOBS = [
32+
'*.d.ts',
33+
'**/bindings/**',
34+
'**/tests/**', '**/test/**',
35+
'**/scripts/**',
36+
'**/mcp-adapter/**',
37+
'**/*vscode*/**',
38+
'**/cli/**',
39+
'**/mod.ts',
40+
'**/lsp-server.ts', '**/lsp_server.ts', '**/lsp.ts', '**/*-lsp.ts',
41+
'**/deno-*/**',
42+
'**/node_modules/**',
43+
'**/vendor/**',
44+
'**/examples/**',
45+
'**/ffi/**',
46+
]
47+
48+
# Per-repo exemptions parsed from .claude/CLAUDE.md "TypeScript Exemptions" table.
49+
# Single source of truth — adding a row here unblocks CI for that path.
50+
# Format expected:
51+
# ### TypeScript Exemptions ...
52+
# | Path | Files | Rationale | Unblock condition |
53+
# |---|---|---|---|
54+
# | `path/to/file.ts` | 1 | ... | ... |
55+
# | `dir/*.ts` | 6 | ... | ... |
56+
exemptions = []
57+
claude_md = pathlib.Path('.claude/CLAUDE.md')
58+
if claude_md.exists():
59+
in_table = False
60+
for line in claude_md.read_text(encoding='utf-8').splitlines():
61+
if re.search(r'TypeScript [Ee]xemptions', line):
62+
in_table = True
63+
continue
64+
if in_table and line.startswith(('### ', '## ', '# ')):
65+
break
66+
if in_table and line.startswith('|'):
67+
m = re.match(r'\|\s*`([^`]+)`', line)
68+
if m:
69+
exemptions.append(m.group(1))
70+
71+
# Find all .ts and .tsx files
72+
found = []
73+
for ext in ('ts', 'tsx'):
74+
found.extend(str(p) for p in pathlib.Path('.').rglob(f'*.{ext}'))
75+
76+
def allowed(path):
77+
p = path.lstrip('./')
78+
for g in BUILTIN_GLOBS + exemptions:
79+
if fnmatch.fnmatchcase(p, g):
80+
return True
81+
# also treat glob ending with / as a directory prefix
82+
base = g.rstrip('/').rstrip('*').rstrip('/')
83+
if base and (p == base or p.startswith(base + '/')):
84+
return True
85+
return False
86+
87+
bad = sorted(f for f in found if not allowed(f))
88+
if bad:
89+
print("❌ TypeScript files detected outside the allowlist.\n")
90+
for f in bad:
91+
print(f" {f}")
92+
print()
93+
print("To resolve, either:")
94+
print(" (a) migrate the file to AffineScript")
95+
print(" (see Human_Programming_Guide.adoc migration chapter), OR")
96+
print(" (b) move it to an allowlisted bridge path")
97+
print(" (bindings/, tests/, scripts/, mcp-adapter/, *vscode*/, cli/, deno-*/, etc.), OR")
98+
print(" (c) add an entry to the 'TypeScript Exemptions' table in .claude/CLAUDE.md")
99+
print(" with rationale + unblock condition.")
100+
if exemptions:
101+
print(f"\n(Currently {len(exemptions)} exemption(s) parsed from .claude/CLAUDE.md.)")
102+
sys.exit(1)
103+
print(f"✅ No TypeScript files outside allowlist ({len(exemptions)} per-repo exemption(s) parsed).")
104+
PYEOF
58105
59106
- name: Check for Go
60107
run: |

0 commit comments

Comments
 (0)