@benchcutlogic/repo-checks 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +166 -2
- package/dist/checks/agent-contracts.d.ts +4 -0
- package/dist/checks/agent-contracts.js +466 -0
- package/dist/checks/agents-budget.d.ts +2 -0
- package/dist/checks/agents-budget.js +122 -0
- package/dist/checks/doc-paths.d.ts +2 -0
- package/dist/checks/doc-paths.js +183 -0
- package/dist/checks/effect-boundaries.d.ts +2 -0
- package/dist/checks/effect-boundaries.js +72 -0
- package/dist/checks/lockfile-registry.d.ts +2 -0
- package/dist/checks/lockfile-registry.js +56 -0
- package/dist/checks/prose.d.ts +2 -0
- package/dist/checks/prose.js +161 -0
- package/dist/checks/storybook-catalog.d.ts +2 -0
- package/dist/checks/storybook-catalog.js +150 -0
- package/dist/checks/svelte-tokens.d.ts +2 -0
- package/dist/checks/svelte-tokens.js +96 -0
- package/dist/checks/unique-error-tags.d.ts +2 -0
- package/dist/checks/unique-error-tags.js +94 -0
- package/dist/checks/web.d.ts +2 -0
- package/dist/checks/web.js +522 -0
- package/dist/cli.d.ts +18 -0
- package/dist/cli.js +147 -0
- package/dist/config.d.ts +7 -0
- package/dist/config.js +137 -0
- package/dist/fs-utils.d.ts +32 -0
- package/dist/fs-utils.js +198 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +97 -0
- package/dist/types.d.ts +142 -0
- package/dist/types.js +1 -0
- package/package.json +66 -3
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { collectMatchingFiles, readTextSafe } from '../fs-utils.js';
|
|
3
|
+
const RAW_TAILWIND_SCALE_RE = /(?:^|[\s"'`:])((?:bg|text|border|ring|fill|stroke|from|via|to)-(?:slate|gray|zinc|neutral|stone|red|orange|amber|yellow|lime|green|emerald|teal|cyan|sky|blue|indigo|violet|purple|fuchsia|pink|rose)-\d{2,3})\b/;
|
|
4
|
+
const RAW_BW_RE = /(?:^|[\s"'`:])(bg-white|text-black|bg-black|text-white)\b/;
|
|
5
|
+
const RAW_HEX_RE = /(?<![a-zA-Z0-9_/-])#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})\b/g;
|
|
6
|
+
const VW_OVERFLOW_RE = /\b(50|100)vw\b/;
|
|
7
|
+
const UNSAFE_DESTRUCTIVE_PAIR_RE = /\bbg-destructive(?:-[a-z0-9-]+)?\b[^\n"'`<>]*\btext-foreground\b|\btext-foreground\b[^\n"'`<>]*\bbg-destructive(?:-[a-z0-9-]+)?\b/;
|
|
8
|
+
function isHexAnchorContext(line, matchIndex) {
|
|
9
|
+
const prefix = line.slice(Math.max(0, matchIndex - 20), matchIndex);
|
|
10
|
+
return /(?:href|id|url\(|xlink:href)\s*=?\s*["'(]?$/i.test(prefix);
|
|
11
|
+
}
|
|
12
|
+
export function checkSvelteTokens(ctx) {
|
|
13
|
+
const findings = [];
|
|
14
|
+
const files = collectMatchingFiles(ctx.root, ctx.config.svelteTokens.globs, ctx.config.svelteTokens.ignores, ctx.config.files);
|
|
15
|
+
for (const rel of files) {
|
|
16
|
+
const content = readTextSafe(join(ctx.root, rel));
|
|
17
|
+
if (content === null)
|
|
18
|
+
continue;
|
|
19
|
+
const isSvelte = rel.endsWith('.svelte');
|
|
20
|
+
const lines = content.split(/\r?\n/);
|
|
21
|
+
for (let i = 0; i < lines.length; i += 1) {
|
|
22
|
+
const line = lines[i] ?? '';
|
|
23
|
+
const trimmed = line.trim();
|
|
24
|
+
if (trimmed.startsWith('//') ||
|
|
25
|
+
trimmed.startsWith('/*') ||
|
|
26
|
+
trimmed.startsWith('*') ||
|
|
27
|
+
trimmed.startsWith('<!--')) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (/bench-check-ignore:\s*svelte-tokens/.test(line)) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const scaleMatch = line.match(RAW_TAILWIND_SCALE_RE);
|
|
34
|
+
if (scaleMatch?.[1]) {
|
|
35
|
+
findings.push({
|
|
36
|
+
check: 'svelte-tokens',
|
|
37
|
+
severity: 'error',
|
|
38
|
+
file: rel,
|
|
39
|
+
line: i + 1,
|
|
40
|
+
rule: 'no-raw-tailwind-color',
|
|
41
|
+
message: `Raw Tailwind palette class '${scaleMatch[1]}' is banned; use semantic theme tokens instead.`
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const bwMatch = line.match(RAW_BW_RE);
|
|
45
|
+
if (bwMatch?.[1]) {
|
|
46
|
+
findings.push({
|
|
47
|
+
check: 'svelte-tokens',
|
|
48
|
+
severity: 'error',
|
|
49
|
+
file: rel,
|
|
50
|
+
line: i + 1,
|
|
51
|
+
rule: 'no-raw-bw-color',
|
|
52
|
+
message: `Raw '${bwMatch[1]}' class is banned; use semantic surface/foreground tokens for dark-mode safety.`
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if (isSvelte) {
|
|
56
|
+
RAW_HEX_RE.lastIndex = 0;
|
|
57
|
+
let hm;
|
|
58
|
+
while ((hm = RAW_HEX_RE.exec(line)) !== null) {
|
|
59
|
+
if (isHexAnchorContext(line, hm.index))
|
|
60
|
+
continue;
|
|
61
|
+
findings.push({
|
|
62
|
+
check: 'svelte-tokens',
|
|
63
|
+
severity: 'error',
|
|
64
|
+
file: rel,
|
|
65
|
+
line: i + 1,
|
|
66
|
+
rule: 'no-raw-hex-literal',
|
|
67
|
+
message: `Raw hex color literal '${hm[0]}' in component template; use CSS custom properties or semantic tokens.`
|
|
68
|
+
});
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const vwMatch = line.match(VW_OVERFLOW_RE);
|
|
73
|
+
if (vwMatch) {
|
|
74
|
+
findings.push({
|
|
75
|
+
check: 'svelte-tokens',
|
|
76
|
+
severity: 'error',
|
|
77
|
+
file: rel,
|
|
78
|
+
line: i + 1,
|
|
79
|
+
rule: 'no-vw-overflow',
|
|
80
|
+
message: `Avoid '${vwMatch[0]}' (causes horizontal scrollbar overflow); use 100% / dvw / svw or overflow-x-clip.`
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (UNSAFE_DESTRUCTIVE_PAIR_RE.test(line)) {
|
|
84
|
+
findings.push({
|
|
85
|
+
check: 'svelte-tokens',
|
|
86
|
+
severity: 'error',
|
|
87
|
+
file: rel,
|
|
88
|
+
line: i + 1,
|
|
89
|
+
rule: 'unsafe-dark-mode-token-pair',
|
|
90
|
+
message: 'Unsafe dark-mode contrast pair: `bg-destructive*` paired with `text-foreground`. Use `text-destructive-foreground` or `text-destructive`.'
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return { check: 'svelte-tokens', findings };
|
|
96
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { collectMatchingFiles, lineNumberAt, readTextSafe } from '../fs-utils.js';
|
|
3
|
+
const TAGGED_ERROR_PATTERNS = [
|
|
4
|
+
// Schema.TaggedError<MyErr>()('MyTag', ...) or Schema.TaggedError('MyTag')
|
|
5
|
+
/\b(?:Schema|Data)\.TaggedError(?:<[^>()]*>)?\(\)\(\s*['"`]([^'"`]+)['"`]/g,
|
|
6
|
+
/\b(?:Schema|Data)\.TaggedError(?:<[^>()]*>)?\(\s*['"`]([^'"`]+)['"`]/g
|
|
7
|
+
];
|
|
8
|
+
// Matches pgEnum('name', ['a', 'b', ...])
|
|
9
|
+
const PG_ENUM_RE = /\bpgEnum\s*\(\s*['"`]([^'"`]+)['"`]\s*,\s*\[([\s\S]*?)\]\s*\)/g;
|
|
10
|
+
function extractStringTuple(arrayBody) {
|
|
11
|
+
const items = [];
|
|
12
|
+
const strRe = /['"`]([^'"`]+)['"`]/g;
|
|
13
|
+
let m;
|
|
14
|
+
while ((m = strRe.exec(arrayBody)) !== null) {
|
|
15
|
+
items.push(m[1]);
|
|
16
|
+
}
|
|
17
|
+
return items.length > 0 ? items : null;
|
|
18
|
+
}
|
|
19
|
+
export function checkUniqueErrorTags(ctx) {
|
|
20
|
+
const findings = [];
|
|
21
|
+
const tsFiles = collectMatchingFiles(ctx.root, ['**/*.ts', '**/*.mts'], ['**/*.test.ts', '**/*.spec.ts', '**/test/**', '**/tests/**', '**/*.d.ts'], ctx.config.files);
|
|
22
|
+
const tags = new Map();
|
|
23
|
+
const enumTuples = new Map();
|
|
24
|
+
for (const rel of tsFiles) {
|
|
25
|
+
const content = readTextSafe(join(ctx.root, rel));
|
|
26
|
+
if (content === null)
|
|
27
|
+
continue;
|
|
28
|
+
// 1. Collect TaggedError _tag occurrences (dedupe exact file:line matches across patterns)
|
|
29
|
+
const seenAtOffset = new Set();
|
|
30
|
+
for (const pattern of TAGGED_ERROR_PATTERNS) {
|
|
31
|
+
pattern.lastIndex = 0;
|
|
32
|
+
let match;
|
|
33
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
34
|
+
if (seenAtOffset.has(match.index))
|
|
35
|
+
continue;
|
|
36
|
+
seenAtOffset.add(match.index);
|
|
37
|
+
const tag = match[1];
|
|
38
|
+
const line = lineNumberAt(content, match.index);
|
|
39
|
+
const list = tags.get(tag) ?? [];
|
|
40
|
+
list.push({ file: rel, line });
|
|
41
|
+
tags.set(tag, list);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
// 2. Collect inline pgEnum string-tuple literals
|
|
45
|
+
PG_ENUM_RE.lastIndex = 0;
|
|
46
|
+
let em;
|
|
47
|
+
while ((em = PG_ENUM_RE.exec(content)) !== null) {
|
|
48
|
+
const enumName = em[1];
|
|
49
|
+
const tuple = extractStringTuple(em[2] ?? '');
|
|
50
|
+
if (!tuple)
|
|
51
|
+
continue;
|
|
52
|
+
const key = JSON.stringify([...tuple].sort());
|
|
53
|
+
const list = enumTuples.get(key) ?? [];
|
|
54
|
+
list.push({ file: rel, line: lineNumberAt(content, em.index), enumName });
|
|
55
|
+
enumTuples.set(key, list);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
for (const [tag, occurrences] of tags) {
|
|
59
|
+
if (occurrences.length > 1) {
|
|
60
|
+
const first = occurrences[0];
|
|
61
|
+
for (let i = 1; i < occurrences.length; i += 1) {
|
|
62
|
+
const dup = occurrences[i];
|
|
63
|
+
findings.push({
|
|
64
|
+
check: 'unique-error-tags',
|
|
65
|
+
severity: 'error',
|
|
66
|
+
file: dup.file,
|
|
67
|
+
line: dup.line,
|
|
68
|
+
rule: 'duplicate-error-tag',
|
|
69
|
+
message: `Duplicate TaggedError _tag '${tag}' (also declared at ${first.file}:${first.line}).`
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
for (const [tupleKey, occurrences] of enumTuples) {
|
|
75
|
+
const distinctFiles = new Set(occurrences.map((o) => o.file));
|
|
76
|
+
if (distinctFiles.size >= 2) {
|
|
77
|
+
const first = occurrences[0];
|
|
78
|
+
for (let i = 1; i < occurrences.length; i += 1) {
|
|
79
|
+
const dup = occurrences[i];
|
|
80
|
+
if (dup.file === first.file)
|
|
81
|
+
continue;
|
|
82
|
+
findings.push({
|
|
83
|
+
check: 'unique-error-tags',
|
|
84
|
+
severity: 'error',
|
|
85
|
+
file: dup.file,
|
|
86
|
+
line: dup.line,
|
|
87
|
+
rule: 'duplicated-pg-enum-tuple',
|
|
88
|
+
message: `Duplicated inline pgEnum tuple ${tupleKey} (pgEnum '${dup.enumName}' duplicates ${first.file}:${first.line}). Export one shared const tuple instead.`
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return { check: 'unique-error-tags', findings };
|
|
94
|
+
}
|