@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.
@@ -0,0 +1,183 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { dirname, join, resolve } from 'node:path';
3
+ import { collectMatchingFiles, matchesAnyGlob, readTextSafe } from '../fs-utils.js';
4
+ const KNOWN_EXTENSIONS = new Set([
5
+ 'ts',
6
+ 'tsx',
7
+ 'mts',
8
+ 'cts',
9
+ 'js',
10
+ 'jsx',
11
+ 'mjs',
12
+ 'cjs',
13
+ 'svelte',
14
+ 'json',
15
+ 'jsonc',
16
+ 'yml',
17
+ 'yaml',
18
+ 'md',
19
+ 'mdx',
20
+ 'css',
21
+ 'html',
22
+ 'sh',
23
+ 'bash',
24
+ 'toml',
25
+ 'sql',
26
+ 'nix',
27
+ 'py',
28
+ 'rs',
29
+ 'go',
30
+ 'svg',
31
+ 'png',
32
+ 'ico',
33
+ 'txt'
34
+ ]);
35
+ const URL_SCHEME_RE = /^(https?:|mailto:|file:|data:|tel:|ftp:|ssh:|ws:|wss:)/i;
36
+ function isCandidateBacktickPath(raw) {
37
+ const value = raw.trim();
38
+ if (!value || value.length > 200)
39
+ return false;
40
+ if (/\s/.test(value))
41
+ return false;
42
+ if (URL_SCHEME_RE.test(value))
43
+ return false;
44
+ if (value.startsWith('#') ||
45
+ value.startsWith('-') ||
46
+ value.startsWith('$') ||
47
+ value.startsWith('@')) {
48
+ return false;
49
+ }
50
+ if (value.startsWith('/') || value.startsWith('~'))
51
+ return false;
52
+ if (/[<>{}*?|`'"()[\]]/.test(value))
53
+ return false;
54
+ if (value.includes('://') || (value.includes('..') === false && value.endsWith(':')))
55
+ return false;
56
+ const clean = value.split('#')[0]?.split('?')[0] ?? '';
57
+ if (!clean)
58
+ return false;
59
+ if (clean.includes('/')) {
60
+ // Reject route/API-like fragments that are obviously MIME types or version tags
61
+ if (/^(application|text|image|audio|video|font)\//.test(clean))
62
+ return false;
63
+ if (/^v\d+\//.test(clean))
64
+ return false;
65
+ const lastSeg = clean.split('/').pop() ?? '';
66
+ if (!lastSeg)
67
+ return true; // trailing-slash directory path like `packages/core/`
68
+ const ext = lastSeg.includes('.') ? lastSeg.split('.').pop()?.toLowerCase() : undefined;
69
+ if (ext && KNOWN_EXTENSIONS.has(ext))
70
+ return true;
71
+ // Relative paths starting with ./ or ../ or standard workspace prefixes
72
+ if (/^(\.\.?\/|src\/|apps\/|packages\/|scripts\/|docs\/|tools\/|\.agents\/|\.claude\/|\.github\/|ast-grep\/)/.test(clean)) {
73
+ return true;
74
+ }
75
+ return false;
76
+ }
77
+ const dotIndex = clean.lastIndexOf('.');
78
+ if (dotIndex > 0 && dotIndex < clean.length - 1) {
79
+ const ext = clean.slice(dotIndex + 1).toLowerCase();
80
+ if (KNOWN_EXTENSIONS.has(ext)) {
81
+ // Skip bare domain-like or dotted identifiers like `foo.ts`? Actually bare filenames like `AGENTS.md`, `package.json`, `sgconfig.yml` should be checked!
82
+ // Avoid false positives on JS member expressions like `Effect.try`, `res.data`, `process.env` — none of those end in KNOWN_EXTENSIONS except `.md`, `.json`, `.yml`, `.yaml`, `.toml`, `.sh`, `.svelte`, `.css`, `.html`, `.nix`, `.sql`, `.ts`, `.js`, `.mjs`.
83
+ // Guard against `foo.js` / `foo.ts` / `foo.py` unless uppercase-leading or config file or starts with `.`
84
+ const configExts = new Set([
85
+ 'md',
86
+ 'json',
87
+ 'yml',
88
+ 'yaml',
89
+ 'toml',
90
+ 'nix',
91
+ 'html',
92
+ 'svg',
93
+ 'ico'
94
+ ]);
95
+ return configExts.has(ext);
96
+ }
97
+ }
98
+ return false;
99
+ }
100
+ function resolveDocTarget(root, docAbsPath, rawTarget) {
101
+ const cleaned = rawTarget.trim().split('#')[0]?.split('?')[0]?.replace(/\/+$/, '') ?? '';
102
+ if (!cleaned)
103
+ return true;
104
+ const fromDoc = resolve(dirname(docAbsPath), cleaned);
105
+ if (existsSync(fromDoc))
106
+ return true;
107
+ const fromRoot = resolve(root, cleaned);
108
+ return existsSync(fromRoot);
109
+ }
110
+ export function checkDocPaths(ctx) {
111
+ const findings = [];
112
+ const docFiles = collectMatchingFiles(ctx.root, ctx.config.docPaths.files, [], ctx.config.files);
113
+ for (const relDoc of docFiles) {
114
+ const absDoc = join(ctx.root, relDoc);
115
+ const content = readTextSafe(absDoc);
116
+ if (content === null)
117
+ continue;
118
+ const lines = content.split(/\r?\n/);
119
+ let inFence = false;
120
+ let fenceChar = '';
121
+ for (let i = 0; i < lines.length; i += 1) {
122
+ const line = lines[i] ?? '';
123
+ const fenceMatch = line.match(/^\s*(`{3,}|~{3,})/);
124
+ if (fenceMatch) {
125
+ const marker = fenceMatch[1]?.[0] ?? '`';
126
+ if (!inFence) {
127
+ inFence = true;
128
+ fenceChar = marker;
129
+ }
130
+ else if (marker === fenceChar) {
131
+ inFence = false;
132
+ fenceChar = '';
133
+ }
134
+ continue;
135
+ }
136
+ if (inFence)
137
+ continue;
138
+ // 1. Markdown links [text](target)
139
+ const linkRe = /!?\[[^\]]*\]\(([^)\s]+)(?:\s+["'][^"']*["'])?\)/g;
140
+ let linkMatch;
141
+ while ((linkMatch = linkRe.exec(line)) !== null) {
142
+ const target = linkMatch[1]?.trim() ?? '';
143
+ if (!target || target.startsWith('#') || URL_SCHEME_RE.test(target))
144
+ continue;
145
+ if (/[<>{}*]/.test(target))
146
+ continue;
147
+ if (matchesAnyGlob(target, ctx.config.docPaths.ignorePaths))
148
+ continue;
149
+ if (!resolveDocTarget(ctx.root, absDoc, target)) {
150
+ findings.push({
151
+ check: 'doc-paths',
152
+ severity: 'error',
153
+ file: relDoc,
154
+ line: i + 1,
155
+ rule: 'broken-markdown-link',
156
+ message: `Broken relative markdown link target: '${target}' does not exist on disk.`
157
+ });
158
+ }
159
+ }
160
+ // 2. Inline backticked paths `path/to/file.ext`
161
+ const codeRe = /`([^`\n]+)`/g;
162
+ let codeMatch;
163
+ while ((codeMatch = codeRe.exec(line)) !== null) {
164
+ const token = codeMatch[1]?.trim() ?? '';
165
+ if (!isCandidateBacktickPath(token))
166
+ continue;
167
+ if (matchesAnyGlob(token, ctx.config.docPaths.ignorePaths))
168
+ continue;
169
+ if (!resolveDocTarget(ctx.root, absDoc, token)) {
170
+ findings.push({
171
+ check: 'doc-paths',
172
+ severity: 'error',
173
+ file: relDoc,
174
+ line: i + 1,
175
+ rule: 'missing-backtick-path',
176
+ message: `Referenced path \`${token}\` does not exist on disk.`
177
+ });
178
+ }
179
+ }
180
+ }
181
+ }
182
+ return { check: 'doc-paths', findings };
183
+ }
@@ -0,0 +1,2 @@
1
+ import type { CheckContext, CheckResult } from '../types.js';
2
+ export declare function checkEffectBoundaries(ctx: CheckContext): CheckResult;
@@ -0,0 +1,72 @@
1
+ import { join } from 'node:path';
2
+ import { collectMatchingFiles, lineNumberAt, matchesAnyGlob, readTextSafe, toPosixPath } from '../fs-utils.js';
3
+ const STATIC_IMPORT_RE = /(?:import|export)\s+(?:type\s+)?(?:[\s\S]*?\s+from\s+)?['"]([^'"]+)['"]/g;
4
+ const DYNAMIC_IMPORT_RE = /\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
5
+ const RUNTIME_RUN_RE = /\bEffect\.(runPromise|runPromiseExit|runSync|runSyncExit|runFork)\s*\(/g;
6
+ function matchesForbiddenImport(specifier, forbidden) {
7
+ for (const rule of forbidden) {
8
+ if (rule.endsWith(':') || rule.endsWith('/')) {
9
+ if (specifier.startsWith(rule))
10
+ return rule;
11
+ }
12
+ else if (specifier === rule || specifier.startsWith(`${rule}/`)) {
13
+ return rule;
14
+ }
15
+ }
16
+ return null;
17
+ }
18
+ export function checkEffectBoundaries(ctx) {
19
+ const findings = [];
20
+ const { purePackages, forbiddenImports, allowedRuntimeEntries } = ctx.config.effectBoundaries;
21
+ const tsFiles = collectMatchingFiles(ctx.root, ['**/*.ts', '**/*.mts', '**/*.svelte'], ['**/*.d.ts'], ctx.config.files);
22
+ for (const rel of tsFiles) {
23
+ const content = readTextSafe(join(ctx.root, rel));
24
+ if (content === null)
25
+ continue;
26
+ const norm = toPosixPath(rel);
27
+ const isTest = matchesAnyGlob(norm, [
28
+ '**/*.test.ts',
29
+ '**/*.spec.ts',
30
+ '**/test/**',
31
+ '**/tests/**'
32
+ ]);
33
+ // 1. Check forbidden platform imports inside pure packages (e.g. packages/core)
34
+ const inPurePackage = purePackages.some((pkgDir) => norm.startsWith(`${pkgDir.replace(/\/+$/, '')}/`));
35
+ if (inPurePackage && !isTest) {
36
+ for (const re of [STATIC_IMPORT_RE, DYNAMIC_IMPORT_RE]) {
37
+ re.lastIndex = 0;
38
+ let match;
39
+ while ((match = re.exec(content)) !== null) {
40
+ const specifier = match[1];
41
+ const violated = matchesForbiddenImport(specifier, forbiddenImports);
42
+ if (violated) {
43
+ findings.push({
44
+ check: 'effect-boundaries',
45
+ severity: 'error',
46
+ file: rel,
47
+ line: lineNumberAt(content, match.index),
48
+ rule: 'forbidden-pure-package-import',
49
+ message: `Pure package file imports forbidden platform module '${specifier}' (matched '${violated}').`
50
+ });
51
+ }
52
+ }
53
+ }
54
+ }
55
+ // 2. Check Effect.run* outside allowed runtime entry points
56
+ if (!matchesAnyGlob(norm, allowedRuntimeEntries)) {
57
+ RUNTIME_RUN_RE.lastIndex = 0;
58
+ let match;
59
+ while ((match = RUNTIME_RUN_RE.exec(content)) !== null) {
60
+ findings.push({
61
+ check: 'effect-boundaries',
62
+ severity: 'error',
63
+ file: rel,
64
+ line: lineNumberAt(content, match.index),
65
+ rule: 'effect-run-outside-boundary',
66
+ message: `Effect.${match[1]}() is not allowed outside configured runtime entry points.`
67
+ });
68
+ }
69
+ }
70
+ }
71
+ return { check: 'effect-boundaries', findings };
72
+ }
@@ -0,0 +1,2 @@
1
+ import type { CheckContext, CheckResult } from '../types.js';
2
+ export declare function checkLockfileRegistry(ctx: CheckContext): CheckResult;
@@ -0,0 +1,56 @@
1
+ import { join } from 'node:path';
2
+ import { isExcludedPath, readTextSafe } from '../fs-utils.js';
3
+ const LOCKFILES = ['pnpm-lock.yaml', 'package-lock.json'];
4
+ const PRIVATE_REGISTRY_PATTERNS = [
5
+ {
6
+ label: 'Tailscale (*.ts.net)',
7
+ re: /https?:\/\/[a-zA-Z0-9._-]+\.ts\.net(?:[:/]|$)/i
8
+ },
9
+ {
10
+ label: 'localhost',
11
+ re: /https?:\/\/localhost(?:[:/]|$)/i
12
+ },
13
+ {
14
+ label: 'loopback (127.0.0.1 / 0.0.0.0 / [::1])',
15
+ re: /https?:\/\/(?:127\.\d{1,3}\.\d{1,3}\.\d{1,3}|0\.0\.0\.0|\[::1\])(?:[:/]|$)/i
16
+ },
17
+ {
18
+ label: 'private LAN IP (RFC 1918)',
19
+ re: /https?:\/\/(?:10\.\d{1,3}\.\d{1,3}\.\d{1,3}|192\.168\.\d{1,3}\.\d{1,3}|172\.(?:1[6-9]|2\d|3[01])\.\d{1,3}\.\d{1,3})(?:[:/]|$)/i
20
+ },
21
+ {
22
+ label: 'private DNS (.local/.lan/.internal)',
23
+ re: /https?:\/\/[a-zA-Z0-9._-]+\.(?:local|lan|internal)(?:[:/]|$)/i
24
+ }
25
+ ];
26
+ export function checkLockfileRegistry(ctx) {
27
+ const findings = [];
28
+ for (const rel of LOCKFILES) {
29
+ if (isExcludedPath(rel, ctx.config.files.exclude))
30
+ continue;
31
+ const content = readTextSafe(join(ctx.root, rel));
32
+ if (content === null)
33
+ continue;
34
+ const lines = content.split(/\r?\n/);
35
+ for (let i = 0; i < lines.length; i += 1) {
36
+ const line = lines[i] ?? '';
37
+ if (!line.includes('http://') && !line.includes('https://'))
38
+ continue;
39
+ for (const pat of PRIVATE_REGISTRY_PATTERNS) {
40
+ const match = line.match(pat.re);
41
+ if (match) {
42
+ findings.push({
43
+ check: 'lockfile-registry',
44
+ severity: 'error',
45
+ file: rel,
46
+ line: i + 1,
47
+ rule: 'private-registry-url',
48
+ message: `Lockfile contains private/local registry URL (${pat.label}): ${match[0]}`
49
+ });
50
+ break;
51
+ }
52
+ }
53
+ }
54
+ }
55
+ return { check: 'lockfile-registry', findings };
56
+ }
@@ -0,0 +1,2 @@
1
+ import type { CheckContext, CheckResult } from '../types.js';
2
+ export declare function checkProse(ctx: CheckContext): CheckResult;
@@ -0,0 +1,161 @@
1
+ import { join } from 'node:path';
2
+ import YAML from 'yaml';
3
+ import { collectMatchingFiles, readTextSafe } from '../fs-utils.js';
4
+ const SLOP_PATTERNS = [
5
+ { label: '"It\'s not just"', re: /\bit['’]s not just\b/i },
6
+ { label: '"delve"', re: /\bdelve(?:s|d|ing)?\b/i },
7
+ { label: '"tapestry"', re: /\btapestry\b/i },
8
+ { label: '"testament"', re: /\btestament\b/i },
9
+ { label: '"landscape"', re: /\blandscape\b/i },
10
+ { label: '"in today\'s fast-paced"', re: /\bin today['’]s fast-paced\b/i },
11
+ { label: '"game-changer"', re: /\bgame[- ]changer\b/i },
12
+ { label: '"unlock the power"', re: /\bunlock the power\b/i }
13
+ ];
14
+ function extractFrontmatter(content) {
15
+ const match = content.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/);
16
+ if (!match) {
17
+ return { data: null, bodyStartLine: 0 };
18
+ }
19
+ const fmLines = match[0].split(/\r?\n/).length - 1;
20
+ try {
21
+ const parsed = YAML.parse(match[1] ?? '');
22
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
23
+ return { data: parsed, bodyStartLine: fmLines };
24
+ }
25
+ return { data: null, bodyStartLine: fmLines };
26
+ }
27
+ catch (err) {
28
+ return {
29
+ data: null,
30
+ bodyStartLine: fmLines,
31
+ parseError: err.message
32
+ };
33
+ }
34
+ }
35
+ export function checkProse(ctx) {
36
+ const findings = [];
37
+ const { globs, titleMax, descriptionMax, allowedTags, bannedTerms, slopMode } = ctx.config.prose;
38
+ const files = collectMatchingFiles(ctx.root, globs, [], ctx.config.files);
39
+ const allowedTagSet = allowedTags ? new Set(allowedTags) : null;
40
+ const compiledBanned = bannedTerms.map((rule) => ({
41
+ rule,
42
+ re: new RegExp(rule.pattern, rule.flags ?? 'g')
43
+ }));
44
+ for (const rel of files) {
45
+ const content = readTextSafe(join(ctx.root, rel));
46
+ if (content === null)
47
+ continue;
48
+ const fm = extractFrontmatter(content);
49
+ if (fm.parseError) {
50
+ findings.push({
51
+ check: 'prose',
52
+ severity: 'error',
53
+ file: rel,
54
+ line: 1,
55
+ rule: 'prose-frontmatter-parse',
56
+ message: `Invalid YAML frontmatter: ${fm.parseError}`
57
+ });
58
+ }
59
+ else if (fm.data) {
60
+ const title = fm.data['title'];
61
+ if (typeof title === 'string' && title.trim().length > titleMax) {
62
+ findings.push({
63
+ check: 'prose',
64
+ severity: 'error',
65
+ file: rel,
66
+ line: 1,
67
+ rule: 'prose-title-length',
68
+ message: `Frontmatter title is ${title.trim().length} characters (max ${titleMax}).`
69
+ });
70
+ }
71
+ const description = fm.data['description'];
72
+ if (typeof description === 'string' && description.trim().length > descriptionMax) {
73
+ findings.push({
74
+ check: 'prose',
75
+ severity: 'error',
76
+ file: rel,
77
+ line: 1,
78
+ rule: 'prose-description-length',
79
+ message: `Frontmatter description is ${description.trim().length} characters (max ${descriptionMax}).`
80
+ });
81
+ }
82
+ if (allowedTagSet && Array.isArray(fm.data['tags'])) {
83
+ for (const tag of fm.data['tags']) {
84
+ if (typeof tag === 'string' && !allowedTagSet.has(tag)) {
85
+ findings.push({
86
+ check: 'prose',
87
+ severity: 'error',
88
+ file: rel,
89
+ line: 1,
90
+ rule: 'prose-invalid-tag',
91
+ message: `Frontmatter tag '${tag}' is not in configured allowedTags.`
92
+ });
93
+ }
94
+ }
95
+ }
96
+ }
97
+ const lines = content.split(/\r?\n/);
98
+ let inFence = false;
99
+ let fenceTickLen = 0;
100
+ for (let i = fm.bodyStartLine; i < lines.length; i += 1) {
101
+ const line = lines[i] ?? '';
102
+ const fenceMatch = line.match(/^\s*(`{3,})(.*)$/);
103
+ if (fenceMatch) {
104
+ const ticks = fenceMatch[1].length;
105
+ const info = (fenceMatch[2] ?? '').trim();
106
+ if (!inFence) {
107
+ inFence = true;
108
+ fenceTickLen = ticks;
109
+ if (info.length === 0) {
110
+ findings.push({
111
+ check: 'prose',
112
+ severity: 'error',
113
+ file: rel,
114
+ line: i + 1,
115
+ rule: 'prose-unlabeled-code-fence',
116
+ message: 'Code fence is missing a language label (e.g. ```ts, ```sh, ```text).'
117
+ });
118
+ }
119
+ }
120
+ else if (ticks >= fenceTickLen && info.length === 0) {
121
+ inFence = false;
122
+ fenceTickLen = 0;
123
+ }
124
+ continue;
125
+ }
126
+ if (inFence)
127
+ continue;
128
+ // Repo-configured bannedTerms -> always error
129
+ for (const { rule, re } of compiledBanned) {
130
+ re.lastIndex = 0;
131
+ if (re.test(line)) {
132
+ findings.push({
133
+ check: 'prose',
134
+ severity: 'error',
135
+ file: rel,
136
+ line: i + 1,
137
+ rule: 'prose-banned-term',
138
+ message: `Banned term matched /${rule.pattern}/: ${rule.reason}`
139
+ });
140
+ }
141
+ }
142
+ // Advisory slop warnings (promoted to error under --strict or slopMode === 'error')
143
+ if (slopMode !== 'off') {
144
+ const slopSeverity = ctx.strict || slopMode === 'error' ? 'error' : 'warning';
145
+ for (const pat of SLOP_PATTERNS) {
146
+ if (pat.re.test(line)) {
147
+ findings.push({
148
+ check: 'prose',
149
+ severity: slopSeverity,
150
+ file: rel,
151
+ line: i + 1,
152
+ rule: 'prose-slop',
153
+ message: `AI-slop phrase detected (${pat.label}); rewrite in plain, concrete terms.`
154
+ });
155
+ }
156
+ }
157
+ }
158
+ }
159
+ }
160
+ return { check: 'prose', findings };
161
+ }
@@ -0,0 +1,2 @@
1
+ import type { CheckContext, CheckResult } from '../types.js';
2
+ export declare function checkStorybookCatalog(ctx: CheckContext): CheckResult;
@@ -0,0 +1,150 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { basename, join } from 'node:path';
3
+ import { collectMatchingFiles, readTextSafe, toPosixPath } from '../fs-utils.js';
4
+ const AUTO_CATALOG_CANDIDATES = [
5
+ '.storybook/catalog.json',
6
+ 'storybook-catalog.json',
7
+ 'stories-catalog.json'
8
+ ];
9
+ function parseCatalogEntries(content, catalogRel) {
10
+ if (catalogRel.endsWith('.json')) {
11
+ const parsed = JSON.parse(content);
12
+ if (Array.isArray(parsed)) {
13
+ return parsed.filter((item) => typeof item === 'string');
14
+ }
15
+ if (parsed && typeof parsed === 'object' && 'stories' in parsed) {
16
+ const stories = parsed.stories;
17
+ if (Array.isArray(stories)) {
18
+ return stories.filter((item) => typeof item === 'string');
19
+ }
20
+ }
21
+ if (parsed &&
22
+ typeof parsed === 'object' &&
23
+ ('visualEntries' in parsed || 'excluded' in parsed)) {
24
+ const record = parsed;
25
+ const extractFiles = (list) => {
26
+ if (list === undefined)
27
+ return [];
28
+ if (!Array.isArray(list))
29
+ return null;
30
+ const files = [];
31
+ for (const item of list) {
32
+ if (typeof item === 'string') {
33
+ files.push(item);
34
+ }
35
+ else if (item &&
36
+ typeof item === 'object' &&
37
+ typeof item.file === 'string') {
38
+ files.push(item.file);
39
+ }
40
+ }
41
+ return files;
42
+ };
43
+ const visualFiles = extractFiles(record.visualEntries);
44
+ const excludedFiles = extractFiles(record.excluded);
45
+ if (visualFiles !== null && excludedFiles !== null) {
46
+ return [...visualFiles, ...excludedFiles];
47
+ }
48
+ }
49
+ return null;
50
+ }
51
+ // TS/JS catalog file: extract quoted *.stories.{svelte,ts} paths
52
+ const matches = [];
53
+ const re = /['"`]([^'"`]+\.stories\.(?:svelte|ts))['"`]/g;
54
+ let m;
55
+ while ((m = re.exec(content)) !== null) {
56
+ matches.push(m[1]);
57
+ }
58
+ return matches;
59
+ }
60
+ export function checkStorybookCatalog(ctx) {
61
+ const findings = [];
62
+ const discovered = collectMatchingFiles(ctx.root, ['**/*.stories.svelte', '**/*.stories.ts'], [], ctx.config.files);
63
+ let catalogRel = ctx.config.storybook.catalogFile;
64
+ if (!catalogRel) {
65
+ catalogRel = AUTO_CATALOG_CANDIDATES.find((candidate) => existsSync(join(ctx.root, candidate)));
66
+ }
67
+ if (catalogRel) {
68
+ const content = readTextSafe(join(ctx.root, catalogRel));
69
+ if (content === null) {
70
+ findings.push({
71
+ check: 'storybook-catalog',
72
+ severity: 'error',
73
+ file: catalogRel,
74
+ rule: 'catalog-missing',
75
+ message: `Configured Storybook catalog '${catalogRel}' does not exist.`
76
+ });
77
+ return { check: 'storybook-catalog', findings };
78
+ }
79
+ let entries = null;
80
+ try {
81
+ entries = parseCatalogEntries(content, catalogRel);
82
+ }
83
+ catch (err) {
84
+ findings.push({
85
+ check: 'storybook-catalog',
86
+ severity: 'error',
87
+ file: catalogRel,
88
+ rule: 'catalog-parse-error',
89
+ message: `Failed to parse Storybook catalog: ${err.message}`
90
+ });
91
+ return { check: 'storybook-catalog', findings };
92
+ }
93
+ if (!entries) {
94
+ findings.push({
95
+ check: 'storybook-catalog',
96
+ severity: 'error',
97
+ file: catalogRel,
98
+ rule: 'catalog-invalid-shape',
99
+ message: 'Storybook catalog must be a JSON array of story paths, `{ "stories": [...] }`, or a `bench-reg catalog` JSON object (`{ "visualEntries": [...], "excluded": [...] }`).'
100
+ });
101
+ return { check: 'storybook-catalog', findings };
102
+ }
103
+ const normalizedDiscovered = new Set(discovered.map((p) => toPosixPath(p).replace(/^\.\//, '')));
104
+ const normalizedCatalog = new Set(entries.map((p) => toPosixPath(p).replace(/^\.\//, '')));
105
+ for (const story of normalizedDiscovered) {
106
+ if (!normalizedCatalog.has(story)) {
107
+ findings.push({
108
+ check: 'storybook-catalog',
109
+ severity: 'error',
110
+ file: story,
111
+ rule: 'story-unregistered',
112
+ message: `Story '${story}' is missing from Storybook catalog '${catalogRel}'.`
113
+ });
114
+ }
115
+ }
116
+ for (const entry of normalizedCatalog) {
117
+ if (!normalizedDiscovered.has(entry) && !existsSync(join(ctx.root, entry))) {
118
+ findings.push({
119
+ check: 'storybook-catalog',
120
+ severity: 'error',
121
+ file: catalogRel,
122
+ rule: 'story-catalog-orphan',
123
+ message: `Catalog entry '${entry}' does not match any existing story file on disk.`
124
+ });
125
+ }
126
+ }
127
+ return { check: 'storybook-catalog', findings };
128
+ }
129
+ // Clean auto-discovery mode: ensure no colliding story titles/basenames in same directory
130
+ const seen = new Map();
131
+ for (const story of discovered) {
132
+ const stem = basename(story).replace(/\.stories\.(svelte|ts)$/, '');
133
+ const dir = story.slice(0, story.lastIndexOf('/'));
134
+ const key = `${dir}/${stem}`;
135
+ const prev = seen.get(key);
136
+ if (prev) {
137
+ findings.push({
138
+ check: 'storybook-catalog',
139
+ severity: 'error',
140
+ file: story,
141
+ rule: 'duplicate-story-stem',
142
+ message: `Duplicate story stem '${stem}' collides with '${prev}'.`
143
+ });
144
+ }
145
+ else {
146
+ seen.set(key, story);
147
+ }
148
+ }
149
+ return { check: 'storybook-catalog', findings };
150
+ }
@@ -0,0 +1,2 @@
1
+ import type { CheckContext, CheckResult } from '../types.js';
2
+ export declare function checkSvelteTokens(ctx: CheckContext): CheckResult;