Skip to content

Commit 7af1d77

Browse files
ci(antipattern): fix top-level dir matching + benchmarks/lsp/bench filename allowlists (#6)
1 parent c87d89e commit 7af1d77

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

0 commit comments

Comments
 (0)