@@ -24,7 +24,115 @@ jobs:
2424 - name : Check for TypeScript
2525 run : |
2626 python3 << 'PYEOF'
27- import re, sys, fnmatch, pathlib
27+ import re, sys, pathlib
28+
29+ # Universal allowlist — bridges and conventions that need no per-repo declaration.
30+ # Implemented as explicit string predicates rather than glob patterns so that
31+ # top-level directories (e.g. tests/foo.ts) are matched the same as nested ones,
32+ # which fnmatch's * cannot do reliably.
33+ DIR_NAMES_ALLOWED = {
34+ 'bindings', 'tests', 'test', 'scripts',
35+ 'mcp-adapter', 'cli', 'vendor', 'examples', 'ffi',
36+ 'node_modules', 'benchmarks',
37+ }
38+
39+ def builtin_allowed(p):
40+ # `p` is a posix-style path with no leading ./
41+ # 1. Type declaration files
42+ if p.endswith('.d.ts'):
43+ return True
44+ # 2. Canonical Deno entrypoint filenames
45+ base = p.rsplit('/', 1)[-1]
46+ if base == 'mod.ts':
47+ return True
48+ # 3. LSP server files (filename suffixes)
49+ if base in ('lsp-server.ts', 'lsp_server.ts', 'lsp.ts') or base.endswith('-lsp.ts'):
50+ return True
51+ # 4. Benchmark files (filename suffixes)
52+ if base.endswith('.bench.ts') or base.endswith('_bench.ts'):
53+ return True
54+ # 5. Any directory segment (excluding basename) matches an allowed dir
55+ segs = p.split('/')
56+ for s in segs[:-1]:
57+ if s in DIR_NAMES_ALLOWED:
58+ return True
59+ # vscode-anything or anything-vscode
60+ if 'vscode' in s:
61+ return True
62+ # deno-named subprojects
63+ if s.startswith('deno-'):
64+ return True
65+ return False
66+
67+ # Per-repo exemptions parsed from .claude/CLAUDE.md "TypeScript Exemptions" table.
68+ # This is the documented single source of truth: adding one row here unblocks CI.
69+ # Glob characters: '*' and '**' both mean "any chars including /". This loose
70+ # interpretation matches user intent when an exemption row reads, e.g.,
71+ # `affinescript-deno-test/*.ts` (covering nested files too).
72+ def glob_to_regex(g):
73+ out = []
74+ for c in g.lstrip('./'):
75+ if c == '*': out.append('.*')
76+ elif c == '?': out.append('.')
77+ elif c in '.+(){}[]|^$\\': out.append(re.escape(c))
78+ else: out.append(c)
79+ return re.compile('^' + ''.join(out) + '$')
80+
81+ exemption_patterns = []
82+ claude_md = pathlib.Path('.claude/CLAUDE.md')
83+ if claude_md.exists():
84+ in_table = False
85+ for line in claude_md.read_text(encoding='utf-8').splitlines():
86+ if re.search(r'TypeScript [Ee]xemptions', line):
87+ in_table = True
88+ continue
89+ if in_table and line.startswith(('### ', '## ', '# ')):
90+ break
91+ if in_table and line.startswith('|'):
92+ m = re.match(r'\|\s*`([^`]+)`', line)
93+ if m:
94+ exemption_patterns.append((m.group(1), glob_to_regex(m.group(1))))
95+
96+ def exempt(p):
97+ for raw, regex in exemption_patterns:
98+ if regex.match(p):
99+ return True
100+ # Also allow exact-path matches and prefix matches for paths
101+ # ending in `/`
102+ if p == raw.lstrip('./'):
103+ return True
104+ if raw.endswith('/') and p.startswith(raw.lstrip('./')):
105+ return True
106+ return False
107+
108+ # Find all .ts and .tsx files (excluding common dot-dirs that find normally skips)
109+ found = []
110+ for ext in ('ts', 'tsx'):
111+ for p in pathlib.Path('.').rglob(f'*.{ext}'):
112+ parts = p.parts
113+ if any(part.startswith('.') and part not in ('.', '..') for part in parts):
114+ continue
115+ found.append(p.as_posix().lstrip('./'))
116+
117+ bad = sorted(f for f in found if not (builtin_allowed(f) or exempt(f)))
118+ if bad:
119+ print("❌ TypeScript files detected outside the allowlist.\n")
120+ for f in bad:
121+ print(f" {f}")
122+ print()
123+ print("To resolve, choose one:")
124+ print(" (a) migrate the file to AffineScript")
125+ print(" (see Human_Programming_Guide.adoc 'Migrating from -script Languages')")
126+ print(" (b) move to an allowlisted bridge path")
127+ print(" (bindings/, tests/, test/, scripts/, benchmarks/, mcp-adapter/,")
128+ print(" *vscode*/, cli/, deno-*/, vendor/, examples/, ffi/)")
129+ print(" (c) add an entry to the 'TypeScript Exemptions' table in .claude/CLAUDE.md")
130+ print(" with rationale + unblock condition")
131+ if exemption_patterns:
132+ print(f"\n(Currently {len(exemption_patterns)} exemption(s) parsed from .claude/CLAUDE.md.)")
133+ sys.exit(1)
134+ print(f"✅ No TypeScript files outside allowlist ({len(exemption_patterns)} per-repo exemption(s) parsed).")
135+ PYEOF
28136
29137 # Universal builtin allowlist — bridges that need no per-repo declaration.
30138 # Files matching any of these patterns are always allowed.
0 commit comments