@mapringg/standard 0.0.0-stage → 1.15.4

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.
Files changed (45) hide show
  1. package/.claude/skills/adopt-standard/SKILL.md +196 -0
  2. package/.claude/skills/capture/SKILL.md +27 -0
  3. package/.claude/skills/pr/LICENSE +21 -0
  4. package/.claude/skills/pr/SKILL.md +170 -0
  5. package/.claude/skills/pr/UPSTREAM.md +4 -0
  6. package/.claude/skills/review-standard/SKILL.md +12 -0
  7. package/.claude/skills/test-audit/SKILL.md +25 -0
  8. package/.claude/skills/upgrade-standard/SKILL.md +25 -0
  9. package/LICENSE +21 -0
  10. package/README.md +10 -2
  11. package/bin/check-pr.mjs +11 -0
  12. package/bin/upload-evidence.mjs +120 -0
  13. package/knip.json +25 -0
  14. package/oxfmt.json +8 -0
  15. package/oxlint.json +464 -0
  16. package/package.json +66 -4
  17. package/packages/create-mapringg-repo/LICENSE +21 -0
  18. package/packages/create-mapringg-repo/cli.mjs +324 -0
  19. package/packages/create-mapringg-repo/github.mjs +128 -0
  20. package/packages/create-mapringg-repo/package.json +25 -0
  21. package/packages/create-mapringg-repo/release.mjs +52 -0
  22. package/packages/create-mapringg-repo/setup.mjs +224 -0
  23. package/src/plugin/agent-docs.mjs +240 -0
  24. package/src/plugin/design-system.mjs +75 -0
  25. package/src/plugin/feature-imports.mjs +38 -0
  26. package/src/plugin/hono.mjs +186 -0
  27. package/src/plugin/index.mjs +42 -0
  28. package/src/plugin/markdown-lines.mjs +35 -0
  29. package/src/plugin/next-data.mjs +124 -0
  30. package/src/plugin/next-routes.mjs +63 -0
  31. package/src/plugin/no-chained-assertions.mjs +22 -0
  32. package/src/plugin/no-comments.mjs +23 -0
  33. package/src/plugin/no-return-types.mjs +48 -0
  34. package/src/plugin/no-typeof.mjs +27 -0
  35. package/src/plugin/owners.mjs +428 -0
  36. package/src/plugin/params.mjs +75 -0
  37. package/src/plugin/paths.mjs +192 -0
  38. package/src/plugin/pr-check.mjs +141 -0
  39. package/src/plugin/query-client.mjs +49 -0
  40. package/src/plugin/reducer.mjs +84 -0
  41. package/src/plugin/repo-shape.mjs +351 -0
  42. package/src/plugin/repository-docs.mjs +119 -0
  43. package/src/plugin/server-actions.mjs +60 -0
  44. package/src/plugin/tests.mjs +222 -0
  45. package/tsconfig.json +23 -0
@@ -0,0 +1,141 @@
1
+ import { readFileSync } from "node:fs";
2
+
3
+ import { anchorFor, listFiles, locate } from "./paths.mjs";
4
+ import { repositoryDocProblems } from "./repository-docs.mjs";
5
+
6
+ const CODE = /\.[cm]?[jt]sx?$/;
7
+ const anchors = new Map();
8
+ const TITLE_MAX = 80;
9
+ const PREFIX = /^[\w-]+(?:\([^)]*\))?!?:\s/;
10
+ const SECTIONS = ["Summary", "Evidence", "Merge Danger"];
11
+ const TICKET = /^Ticket: \S+$/;
12
+ const HEADING = /^ {0,3}(#{1,6})[ \t]+(.*?)[ \t#]*$/;
13
+ const FENCE = /^ {0,3}(?:`{3,}|~{3,})/;
14
+ const IMAGE = /!\[[^\]]*\]\([^)]+\)|<img\b/i;
15
+ const EVIDENCE_LABEL = /^\s*(?:[-*+]\s+)?(Before|After):\s*(.*)$/;
16
+ const EVIDENCE_PLACEHOLDER = /^<screenshot\/output\/(?:failing|passing) test run>$/;
17
+ const DOOR = /^\**Door:\**\s*\**(one-way|two-way)\b/im;
18
+ const BLAST = /^\**Blast Radius:\**\s*\**([^\s*]+)\**\s*$/im;
19
+
20
+ function split(lines) {
21
+ const sections = new Map();
22
+ let fenced = false;
23
+ let current = null;
24
+ for (const line of lines) {
25
+ if (FENCE.test(line)) fenced = !fenced;
26
+ const match = fenced ? null : HEADING.exec(line);
27
+ if (match?.[1] === "##") {
28
+ current = match[2];
29
+ sections.set(current, [...(sections.get(current) ?? []), []]);
30
+ } else if (current) sections.get(current).at(-1).push(line);
31
+ }
32
+ return {
33
+ titles: [...sections.keys()],
34
+ counts: sections,
35
+ text: (title) => sections.get(title)?.[0]?.join("\n") ?? "",
36
+ };
37
+ }
38
+
39
+ function templateProblems(lines) {
40
+ const found = [];
41
+ const { titles, counts, text } = split(lines);
42
+ const start = TICKET.test(lines[0]) ? 1 : 0;
43
+ const opening = lines.slice(start).find((line) => line.trim() !== "");
44
+ if (opening?.trim() !== "## Summary")
45
+ found.push("Body: start with ## Summary (after an optional Ticket: line); skip preambles.");
46
+ const shape = SECTIONS.every((title, at) => titles[at] === title) && titles.length === SECTIONS.length;
47
+ if (!shape || [...counts.values()].some((list) => list.length > 1))
48
+ found.push(
49
+ `Body: use the template's sections once each, in order: ## ${SECTIONS.join(", ## ")}. Got ${titles.length > 0 ? `## ${titles.join(", ## ")}` : "none"}.`,
50
+ );
51
+ const summary = text("Summary");
52
+ if (counts.has("Summary") && !summary.split("\n").some((line) => FENCE.test(line)) && !IMAGE.test(summary))
53
+ found.push(
54
+ "Summary: add one visual, such as pseudocode, a call tree, a component tree, a file tree, a Mermaid diagram or a diff block.",
55
+ );
56
+ if (counts.has("Evidence") && !hasEvidence(text("Evidence")))
57
+ found.push("Evidence: show a Before: and an After: (screenshot, output or test).");
58
+ const danger = text("Merge Danger");
59
+ if (counts.has("Merge Danger") && !DOOR.test(danger))
60
+ found.push("Merge Danger: add a line **Door:** one-way or **Door:** two-way.");
61
+ if (counts.has("Merge Danger") && !BLAST.test(danger))
62
+ found.push("Merge Danger: add a line **Blast Radius:** <one word>, naming who or what the change can hurt.");
63
+ return found;
64
+ }
65
+
66
+ function hasEvidence(text) {
67
+ const filled = new Set();
68
+ let current = null;
69
+ let fenced = false;
70
+ for (const line of text.replaceAll(/<!--[\s\S]*?-->/g, "").split("\n")) {
71
+ if (FENCE.test(line.trimStart())) {
72
+ fenced = !fenced;
73
+ continue;
74
+ }
75
+ const entry = fenced ? null : EVIDENCE_LABEL.exec(line.replaceAll("**", ""));
76
+ if (entry) current = entry[1];
77
+ const content = (entry?.[2] ?? line).trim();
78
+ if (current && content && !EVIDENCE_PLACEHOLDER.test(content)) filled.add(current);
79
+ }
80
+ return filled.has("Before") && filled.has("After");
81
+ }
82
+
83
+ function titleProblems(title, number) {
84
+ const found = [];
85
+ if (PREFIX.test(title)) found.push("Title: drop the type(scope): prefix and write one plain sentence.");
86
+ else if (!/^\p{Lu}/u.test(title)) found.push("Title: start with a capitalised verb, such as Allow, Fix or Remove.");
87
+ if (title.endsWith(".")) found.push("Title: drop the trailing period.");
88
+ const length = `${title} (#${number})`.length;
89
+ if (length > TITLE_MAX)
90
+ found.push(`Title: shorten to ${TITLE_MAX} characters including " (#${number})". It is ${length}.`);
91
+ return found;
92
+ }
93
+
94
+ export function check(pull) {
95
+ if (pull.bot) return [];
96
+ const body = (pull.body ?? "").replaceAll("\r\n", "\n").trim();
97
+ const found = templateProblems(body.split("\n"));
98
+ found.unshift(...titleProblems((pull.title ?? "").trim(), pull.number));
99
+ return found;
100
+ }
101
+
102
+ export function checkEvent(eventPath) {
103
+ const pull = JSON.parse(readFileSync(eventPath, "utf8")).pull_request;
104
+ return check({
105
+ number: pull.number,
106
+ title: pull.title,
107
+ body: pull.body,
108
+ bot: pull.user.type === "Bot",
109
+ });
110
+ }
111
+
112
+ function anchorOf(root) {
113
+ if (!anchors.has(root))
114
+ anchors.set(
115
+ root,
116
+ anchorFor(
117
+ "",
118
+ listFiles(root).filter((rel) => CODE.test(rel)),
119
+ ),
120
+ );
121
+ return anchors.get(root);
122
+ }
123
+
124
+ export default {
125
+ meta: {
126
+ type: "problem",
127
+ docs: {
128
+ description: "A pull request follows the PR skill's title and template. Reports on the first linted file in CI.",
129
+ },
130
+ },
131
+ create(context) {
132
+ const where = locate(context.filename);
133
+ if (process.env.GITHUB_EVENT_NAME !== "pull_request" || !where || anchorOf(where.root) !== where.rel) return {};
134
+ return {
135
+ Program(node) {
136
+ for (const message of [...checkEvent(process.env.GITHUB_EVENT_PATH), ...repositoryDocProblems(where.root)])
137
+ context.report({ node, message });
138
+ },
139
+ };
140
+ },
141
+ };
@@ -0,0 +1,49 @@
1
+ import { UI_APPS, locate } from "./paths.mjs";
2
+
3
+ const FUNCTION = new Set(["FunctionExpression", "ArrowFunctionExpression"]);
4
+
5
+ function resolve(scope, name) {
6
+ for (let current = scope; current; current = current.upper) {
7
+ const variable = current.set.get(name);
8
+ if (variable) return variable;
9
+ }
10
+ return null;
11
+ }
12
+
13
+ function isFunction(node, scope) {
14
+ if (FUNCTION.has(node.type)) return true;
15
+ if (node.type !== "Identifier") return false;
16
+ const definition = resolve(scope, node.name)?.defs[0];
17
+ if (definition?.type === "FunctionName" || definition?.type === "ImportBinding") return true;
18
+ const init = definition?.type === "Variable" ? definition.node.init : null;
19
+ return Boolean(init && FUNCTION.has(init.type));
20
+ }
21
+ const MESSAGE =
22
+ "Pass retry a function that retries once and never retries 400, 401, 403, 404, 409, 413, 415 or 422 errors.";
23
+
24
+ export default {
25
+ meta: {
26
+ type: "problem",
27
+ docs: { description: "The query client in lib/query.ts passes retry a function." },
28
+ },
29
+ create(context) {
30
+ const where = locate(context.filename);
31
+ if (!UI_APPS.has(where?.kind) || where.local !== "src/lib/query.ts") return {};
32
+ const clients = [];
33
+ let retries = false;
34
+ return {
35
+ NewExpression(node) {
36
+ if (node.callee.type === "Identifier" && node.callee.name === "QueryClient") clients.push(node);
37
+ },
38
+ Property(node) {
39
+ if ((node.key?.name ?? node.key?.value) !== "retry") return;
40
+ retries = true;
41
+ if (!isFunction(node.value, context.sourceCode.getScope(node)))
42
+ context.report({ node: node.value, message: MESSAGE });
43
+ },
44
+ "Program:exit"() {
45
+ if (!retries) for (const node of clients) context.report({ node, message: MESSAGE });
46
+ },
47
+ };
48
+ },
49
+ };
@@ -0,0 +1,84 @@
1
+ import { stem } from "./paths.mjs";
2
+
3
+ const FUNCTION = new Set(["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression"]);
4
+
5
+ function enclosingFunction(node) {
6
+ for (let current = node.parent; current; current = current.parent) if (FUNCTION.has(current.type)) return current;
7
+ return null;
8
+ }
9
+
10
+ function isReducerCall(node) {
11
+ const callee = node.callee;
12
+ return (
13
+ (callee.type === "Identifier" && callee.name === "useReducer") ||
14
+ (callee.type === "MemberExpression" && callee.property.name === "useReducer")
15
+ );
16
+ }
17
+
18
+ const WRAPPERS = new Set(["TSInstantiationExpression", "TSAsExpression", "TSSatisfiesExpression"]);
19
+
20
+ function unwrap(node) {
21
+ let current = node;
22
+ while (current && WRAPPERS.has(current.type)) current = current.expression;
23
+ return current;
24
+ }
25
+
26
+ function returnsSecondParam(node) {
27
+ const second = node.params[1];
28
+ if (second?.type !== "Identifier") return false;
29
+ const body = node.body;
30
+ if (body.type === "Identifier") return body.name === second.name;
31
+ if (body.type !== "BlockStatement" || body.body.length !== 1) return false;
32
+ const only = body.body[0];
33
+ return only.type === "ReturnStatement" && only.argument?.type === "Identifier" && only.argument.name === second.name;
34
+ }
35
+
36
+ export default {
37
+ meta: {
38
+ type: "problem",
39
+ docs: { description: "One useReducer per component, with its reducer from a <feature>-state.ts file." },
40
+ },
41
+ create(context) {
42
+ const counts = new Map();
43
+ const stateImports = new Set();
44
+ const setterCheck = (node) => {
45
+ if (returnsSecondParam(node))
46
+ context.report({
47
+ node,
48
+ message: "Model named actions in the reducer instead of returning the action as the new state.",
49
+ });
50
+ };
51
+ return {
52
+ ImportDeclaration(node) {
53
+ if (!/-state(?:\.[cm]?[jt]sx?)?$/.test(node.source.value)) return;
54
+ for (const specifier of node.specifiers) stateImports.add(specifier.local.name);
55
+ },
56
+ CallExpression(node) {
57
+ if (!isReducerCall(node)) return;
58
+ const owner = enclosingFunction(node);
59
+ const count = (counts.get(owner) ?? 0) + 1;
60
+ counts.set(owner, count);
61
+ if (count === 2)
62
+ context.report({
63
+ node,
64
+ message: "Merge the state into one useReducer with one union in <feature>-state.ts.",
65
+ });
66
+ const reducer = unwrap(node.arguments[0]);
67
+ const fromState =
68
+ reducer?.type === "Identifier"
69
+ ? stateImports.has(reducer.name)
70
+ : reducer?.type === "MemberExpression" &&
71
+ reducer.object.type === "Identifier" &&
72
+ stateImports.has(reducer.object.name);
73
+ if (!fromState)
74
+ context.report({
75
+ node: reducer ?? node,
76
+ message: "Import the reducer from <feature>-state.ts, next to its state and action unions.",
77
+ });
78
+ },
79
+ ...(stem(context.filename).endsWith("-state")
80
+ ? Object.fromEntries([...FUNCTION].map((type) => [type, setterCheck]))
81
+ : {}),
82
+ };
83
+ },
84
+ };
@@ -0,0 +1,351 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+
4
+ import {
5
+ DATABASE_SUITE,
6
+ UI_APPS,
7
+ anchorFor,
8
+ describe,
9
+ exportedIds,
10
+ isGenerated,
11
+ isTest,
12
+ isTestSupport,
13
+ listFiles,
14
+ locate,
15
+ stem,
16
+ } from "./paths.mjs";
17
+
18
+ const PACKAGES = new Set(["tokens", "i18n"]);
19
+ const TOP_DIRS = new Set(["apps", "packages", "infra", "scripts", ".github", ".githooks", ".claude", ".vscode"]);
20
+ const CHECK_SCRIPT = /(?:^|[-.])(?:check|lint|verify|validate|audit|enforce)(?:[-.]|$)/;
21
+ const CODE = /\.[cm]?[jt]sx?$/;
22
+ const DIRECTIVE = /(?:\/\/|\/\*)\s*(?:eslint|oxlint)-(?:disable|enable)/;
23
+ const NEXT_FILES = new Set([
24
+ "page",
25
+ "layout",
26
+ "error",
27
+ "global-error",
28
+ "not-found",
29
+ "global-not-found",
30
+ "template",
31
+ "forbidden",
32
+ "unauthorized",
33
+ "route",
34
+ "sitemap",
35
+ "robots",
36
+ "manifest",
37
+ "icon",
38
+ "apple-icon",
39
+ "opengraph-image",
40
+ "twitter-image",
41
+ ]);
42
+ const API_FEATURE_FILES = new Set(["routes", "schema", "db", "service"]);
43
+ const API_ROOT_FILES = new Set(["app.ts", "factory.ts", "env.ts", "server.ts", "client.ts"]);
44
+ const API_DIRS = new Set(["middleware", "infra", "upstreams"]);
45
+ const WEB_ROOT_FILES = new Set(["proxy", "instrumentation", "instrumentation-client"]);
46
+ const SSE = /text\/event-stream|\.to\w*StreamResponse\(/;
47
+ const CACHE_MS = 2000;
48
+ const scans = new Map();
49
+
50
+ function routesDir(kind) {
51
+ return kind === "astro" ? "pages" : "app";
52
+ }
53
+
54
+ const HANDLER_MESSAGE =
55
+ "Move the handler into a webhooks/ folder, a metadata route like sitemap.xml/route.ts or a Server Action; keep only GET at src/app/health/route.ts, MCP at src/app/mcp/route.ts, or streaming or cancellable handlers under src/app/api/ with text/event-stream or a value import from <feature>-stream.server.ts or <feature>-cancellable.server.ts.";
56
+
57
+ function handlerAllowed(where, program, text) {
58
+ const segments = where.local.split("/").slice(2, -1);
59
+ if (segments.includes("webhooks") || segments.at(-1)?.includes(".")) return true;
60
+ if (where.local === "src/app/mcp/route.ts") return true;
61
+ if (where.local === "src/app/health/route.ts") {
62
+ const exports = program.body.filter((node) => node.type.startsWith("Export"));
63
+ return (
64
+ exports.length > 0 &&
65
+ exports.every(
66
+ (node) =>
67
+ node.type === "ExportNamedDeclaration" &&
68
+ node.exportKind !== "type" &&
69
+ !node.declaration?.type.startsWith("TS") &&
70
+ node.specifiers.every((specifier) => specifier.exportKind !== "type") &&
71
+ exportedIds(node).length > 0 &&
72
+ exportedIds(node).every((id) => (id.name ?? id.value) === "GET"),
73
+ )
74
+ );
75
+ }
76
+ return (
77
+ segments[0] === "api" &&
78
+ (SSE.test(text) ||
79
+ program.body.some(
80
+ (node) =>
81
+ node.type === "ImportDeclaration" &&
82
+ node.importKind !== "type" &&
83
+ node.specifiers.some((specifier) => specifier.importKind !== "type") &&
84
+ /(?:^|\/)[^/]+-(?:stream|cancellable)\.server(?:\.ts)?$/.test(node.source.value),
85
+ ))
86
+ );
87
+ }
88
+
89
+ function webRoute(rest, name) {
90
+ const segments = rest.split("/").slice(1, -1);
91
+ const found = [];
92
+ for (const segment of segments) {
93
+ if (segment.startsWith("@")) found.push("Compose the sections inside one page instead of a parallel route.");
94
+ if (/^\(\.{1,3}\)/.test(segment)) found.push("Link to the real route instead of intercepting it.");
95
+ if (segment.startsWith("_")) found.push("Move the code from the _private folder into a feature or components/.");
96
+ }
97
+ const file = stem(name);
98
+ if (file === "loading")
99
+ found.push(
100
+ "Delete loading.tsx and wrap the slow section in <Section fallback> from #/components/boundary/section.",
101
+ );
102
+ else if (file === "default") found.push("Delete default.tsx and compose the sections inside one page.");
103
+ else if (!NEXT_FILES.has(file))
104
+ found.push("Move this code into a feature or components/; app/ holds only Next route files.");
105
+ return found;
106
+ }
107
+
108
+ function astroText(text) {
109
+ let rest = text
110
+ .replace(/^---[\s\S]*?---/, "")
111
+ .replace(/<(script|style)\b[\s\S]*?<\/\1>/g, "")
112
+ .replace(/<!--[\s\S]*?-->/g, "");
113
+ for (let previous = ""; previous !== rest;) {
114
+ previous = rest;
115
+ rest = rest.replace(/\{[^{}]*\}/g, "");
116
+ }
117
+ return /\p{L}/u.test(rest.replace(/<[^>]*>/g, ""));
118
+ }
119
+
120
+ function codeProblems(where) {
121
+ const { kind, pkg, local, name, feature } = where;
122
+ if (isGenerated(name)) return [];
123
+ if (local.startsWith("e2e/")) {
124
+ return local.split("/").length === 2 && isTestSupport(name)
125
+ ? []
126
+ : ["Move the journey to apps/<app>/e2e/<journey>.test.ts."];
127
+ }
128
+ if (kind === "hono" && local.startsWith("migrations/")) return [];
129
+ if (!local.includes("/"))
130
+ return /\.config\./.test(name)
131
+ ? []
132
+ : [`${kind ? "App" : "Package"} root holds config only. Move this code into src/.`];
133
+ if (!local.startsWith("src/")) return ["Move the code into src/."];
134
+ if (pkg) return [];
135
+ const rest = local.slice(4);
136
+ const parts = rest.split("/");
137
+ const found = [];
138
+ const apiPlaced =
139
+ kind === "hono" &&
140
+ ((parts.length === 1 && API_ROOT_FILES.has(name.replace(/\.(?:test|fixture|test-utils)\.ts$/, ".ts"))) ||
141
+ (parts.length === 2 && API_DIRS.has(parts[0])));
142
+ if (isTestSupport(name) && !apiPlaced && !["features", "lib", "components"].includes(parts[0])) {
143
+ found.push(
144
+ parts[0] === routesDir(kind)
145
+ ? "Move the test to the feature code it covers; route files never have tests."
146
+ : kind === "hono"
147
+ ? "Move the test next to the code it tests in features/, lib/, middleware/, infra/, upstreams/ or beside app.ts, factory.ts, env.ts, server.ts or client.ts."
148
+ : "Move the test next to the code it tests in features/, lib/ or components/.",
149
+ );
150
+ }
151
+ if (parts[0] === "features") {
152
+ if (parts.length !== 3) return [...found, "Flatten the feature folder, or split a big feature into two features."];
153
+ const base = stem(name).split(".")[0];
154
+ if (kind === "hono") {
155
+ if (!API_FEATURE_FILES.has(base))
156
+ found.push("Move the code into the feature's routes.ts, schema.ts, db.ts or service.ts.");
157
+ } else if (base !== feature && !base.startsWith(`${feature}-`)) {
158
+ found.push(`Rename the file to ${feature}-${base} so it starts with its feature.`);
159
+ }
160
+ return found;
161
+ }
162
+ if (parts[0] === "lib") return found;
163
+ if (kind === "hono") {
164
+ if (apiPlaced) return found;
165
+ return [
166
+ ...found,
167
+ "Move the code into app.ts, factory.ts, env.ts, server.ts, client.ts, middleware/, lib/, infra/, upstreams/ or features/<resource>/.",
168
+ ];
169
+ }
170
+ if (parts[0] === "components") {
171
+ return parts.length === 3 ? found : [...found, "Move the component to components/<group>/<file>, one level deep."];
172
+ }
173
+ if (parts[0] === routesDir(kind)) return kind === "next" ? [...found, ...webRoute(rest, name)] : found;
174
+ if (parts.length === 1) {
175
+ if (kind === "next" && WEB_ROOT_FILES.has(stem(name))) return found;
176
+ if (kind === "vite" && name === "main.tsx") return found;
177
+ if (kind === "astro" && stem(name) === "content.config") return found;
178
+ }
179
+ if (kind === "astro" && parts[0] === "content") return found;
180
+ return [...found, `Move the code into src/${routesDir(kind)}/, src/features/, src/components/ or src/lib/.`];
181
+ }
182
+
183
+ function fileProblems(rel, root, localized) {
184
+ const where = describe(rel, root);
185
+ const parts = rel.split("/");
186
+ const { name, kind, pkg, base, local } = where;
187
+ if (name === "AGENTS.md") return [];
188
+ const found = [];
189
+ if (parts.length > 1 && !TOP_DIRS.has(parts[0]))
190
+ return ["Move this into apps/ or packages/; the top level holds only config."];
191
+ if (parts[0] === "apps" && parts.length > 2 && !kind)
192
+ return [
193
+ "Add hono, next, vite, expo or astro to the app's package.json dependencies so the standard knows its kind.",
194
+ ];
195
+ if (parts[0] === "packages" && parts.length > 2 && !PACKAGES.has(pkg))
196
+ return [`Move this into an app's lib/; packages/ holds only ${[...PACKAGES].join(" and ")}.`];
197
+ if (/\.mdx?$/.test(name)) {
198
+ const exempt = rel.startsWith(".claude/skills/") || (kind === "astro" && local.startsWith("src/content/"));
199
+ const placed = rel === "README.md";
200
+ if (!exempt && !placed) found.push("Fold this into README.md or AGENTS.md, or delete it.");
201
+ }
202
+ if (/\.(?:scss|sass|less|styl)$/.test(name))
203
+ found.push("Replace the preprocessor file with Tailwind classes and the one global CSS file.");
204
+ if (name.endsWith(".module.css")) found.push("Replace the CSS module with Tailwind classes.");
205
+ if (name.endsWith(".css") && !base) found.push("Move the CSS into the app's one global CSS file.");
206
+ if (name.endsWith(".astro")) {
207
+ if (kind !== "astro" || !local.startsWith("src/") || local.startsWith("src/lib/"))
208
+ found.push("Write this component as .tsx; .astro files live only in the marketing app's routes and components.");
209
+ else if (astroText(readFileSync(join(root, rel), "utf8")))
210
+ found.push("Move the text into a content collection entry or pass it as a prop.");
211
+ }
212
+ if (parts[0] === "scripts" && CHECK_SCRIPT.test(name))
213
+ found.push("Delete the check script and add the check to the standard; scripts/ holds operational tools.");
214
+ if (/\.spec\.[cm]?[jt]sx?$/.test(name)) found.push("Rename the test to *.test.ts or *.test.tsx.");
215
+ if (
216
+ CODE.test(name) &&
217
+ /^(?:(?:.*[-.])?(?:helpers?|mocks?|stubs?|fakes?|test-?utils)|(?:(?:vi)?test[-.]|jest[-.])?setup)\.[cm]?[jt]sx?$/.test(
218
+ name,
219
+ ) &&
220
+ !/\.test-utils\.[cm]?[jt]sx?$/.test(name)
221
+ ) {
222
+ found.push("Rename the file to <name>.fixture.ts or <name>.test-utils.ts.");
223
+ }
224
+ if (
225
+ kind &&
226
+ UI_APPS.has(kind) &&
227
+ /(?:^|\/)(?:i18n|messages)\//.test(local) &&
228
+ !local.startsWith(`src/${routesDir(kind)}/`) &&
229
+ !/^src\/lib\/i18n\/messages\/[a-z0-9-]+\.ts$/.test(local)
230
+ ) {
231
+ found.push("Move the dictionary to src/lib/i18n/messages/<feature>.ts.");
232
+ }
233
+ if (
234
+ kind === "astro" &&
235
+ localized?.has(base) &&
236
+ local.startsWith("src/pages/") &&
237
+ !local.startsWith("src/pages/[locale]/")
238
+ ) {
239
+ found.push("Move the page under src/pages/[locale]/.");
240
+ }
241
+ if (parts.length === 1 && CODE.test(name) && !/\.config\./.test(name))
242
+ found.push("Move this code into an app or package; the top level holds only config.");
243
+ if (base && CODE.test(name)) found.push(...codeProblems(where));
244
+ return found;
245
+ }
246
+
247
+ function scan(root) {
248
+ const files = listFiles(root);
249
+ const localized = new Set(
250
+ files
251
+ .filter((rel) => /^apps\/[^/]+\/src\/pages\/\[locale\]\//.test(rel))
252
+ .map((rel) => rel.split("/").slice(0, 2).join("/")),
253
+ );
254
+ const lintable = files.filter((rel) => CODE.test(rel));
255
+ const findings = new Map();
256
+ const add = (anchor, message) => {
257
+ if (!anchor) return;
258
+ if (!findings.has(anchor)) findings.set(anchor, []);
259
+ findings.get(anchor).push(message);
260
+ };
261
+ const css = new Map();
262
+ const bases = new Set();
263
+ const groups = new Set();
264
+ const directives = [];
265
+ for (const rel of files) {
266
+ const where = describe(rel, root);
267
+ if (where.kind) bases.add(where.base);
268
+ if (where.kind === "next" && where.local.startsWith("src/app/")) {
269
+ const segments = rel.split("/").slice(0, -1);
270
+ const last = segments.findLastIndex((segment) => /^\([^.].*\)$/.test(segment));
271
+ if (last !== -1) groups.add(segments.slice(0, last + 1).join("/"));
272
+ }
273
+ if (rel.endsWith(".css") && !rel.endsWith(".module.css") && where.base)
274
+ css.set(where.base, [...(css.get(where.base) ?? []), rel]);
275
+ const own = CODE.test(rel);
276
+ for (const message of fileProblems(rel, root, localized))
277
+ add(own ? rel : anchorFor(rel.slice(0, rel.lastIndexOf("/")), lintable), own ? message : `${rel}: ${message}`);
278
+ if (own && !isGenerated(rel) && DIRECTIVE.test(readFileSync(join(root, rel), "utf8"))) directives.push(rel);
279
+ }
280
+ for (const list of css.values()) {
281
+ for (const rel of list.slice(1))
282
+ add(
283
+ anchorFor(rel.slice(0, rel.lastIndexOf("/")), lintable),
284
+ `${rel}: Move these styles into ${list[0]}, the one global CSS file.`,
285
+ );
286
+ }
287
+ for (const base of bases) {
288
+ const kind = describe(`${base}/x`, root).kind;
289
+ const routes = kind === "hono" ? "src/app.ts" : `src/${routesDir(kind)}/`;
290
+ for (const need of [routes, "src/lib/"]) {
291
+ const present = need.endsWith("/")
292
+ ? files.some((rel) => rel.startsWith(`${base}/${need}`))
293
+ : files.includes(`${base}/${need}`);
294
+ if (!present) add(anchorFor(base, lintable), `${base}: Add ${need}.`);
295
+ }
296
+ }
297
+ for (const group of groups) {
298
+ if (!files.includes(`${group}/error.tsx`))
299
+ add(anchorFor(group, lintable), `${group}: Add an error.tsx with retry to the route group.`);
300
+ }
301
+ const tests = new Map();
302
+ for (const rel of lintable.filter((file) => isTest(file) && !/^apps\/[^/]+\/e2e\//.test(file))) {
303
+ const dir = rel.slice(0, rel.lastIndexOf("/") + 1);
304
+ const key = dir + rel.slice(dir.length).split(".")[0];
305
+ tests.set(key, [...(tests.get(key) ?? []), rel]);
306
+ }
307
+ for (const [key, list] of tests) {
308
+ if (!lintable.some((rel) => !isTest(rel) && rel.startsWith(`${key}.`)))
309
+ for (const rel of list)
310
+ add(rel, `Name the test after the source file next to it; ${key.split("/").at(-1)}.ts does not exist.`);
311
+ const suites = Map.groupBy(list, (rel) => DATABASE_SUITE.exec(rel)?.[1] ?? "");
312
+ for (const suite of suites.values())
313
+ for (const rel of suite.slice(1)) add(rel, `Merge this test into ${suite[0]}, the one test file for its source.`);
314
+ }
315
+ const clean = lintable.find((rel) => !directives.includes(rel));
316
+ for (const rel of directives)
317
+ add(clean, `${rel}: Delete the disable directive and fix the code, or change the standard.`);
318
+ return findings;
319
+ }
320
+
321
+ function findingsFor(root) {
322
+ const cached = scans.get(root);
323
+ if (cached && Date.now() - cached.time < CACHE_MS) return cached.findings;
324
+ const findings = scan(root);
325
+ scans.set(root, { time: Date.now(), findings });
326
+ return findings;
327
+ }
328
+
329
+ export default {
330
+ meta: {
331
+ type: "problem",
332
+ docs: {
333
+ description: "Files sit only where the standard puts them; repo-wide findings report on the nearest linted file.",
334
+ },
335
+ },
336
+ create(context) {
337
+ const where = locate(context.filename);
338
+ if (!where) return {};
339
+ return {
340
+ Program(node) {
341
+ if (
342
+ where.kind === "next" &&
343
+ /^src\/app\/(?:.*\/)?route\.[cm]?[jt]sx?$/.test(where.local) &&
344
+ !handlerAllowed(where, node, context.sourceCode.getText())
345
+ )
346
+ context.report({ node, message: HANDLER_MESSAGE });
347
+ for (const message of findingsFor(where.root).get(where.rel) ?? []) context.report({ node, message });
348
+ },
349
+ };
350
+ },
351
+ };