Skip to content

Commit 61ca8b6

Browse files
committed
ci(antipattern): fix top-level dir matching + benchmarks/lsp/bench filename allowlists
1 parent 42b2828 commit 61ca8b6

1 file changed

Lines changed: 109 additions & 1 deletion

File tree

.github/workflows/rsr-antipattern.yml

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

0 commit comments

Comments
 (0)