@mapringg/standard 0.0.0-stage → 1.15.3

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 +189 -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 +63 -4
  17. package/packages/create-mapringg-repo/LICENSE +21 -0
  18. package/packages/create-mapringg-repo/cli.mjs +323 -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 +173 -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,173 @@
1
+ import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+
4
+ import { isMap, isSeq, parseDocument } from "yaml";
5
+
6
+ import { releaseSha, releaseTag } from "./release.mjs";
7
+
8
+ const STANDARD = "github:mapringg/standard#";
9
+ const ACTION = "mapringg/standard/.github/actions/check-pr@";
10
+ const CHECKOUT = "actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09";
11
+ const EVENTS = ["opened", "synchronize", "reopened", "edited"];
12
+ const SKILLS =
13
+ /@mapringg\/standard\/\.claude\/skills\/(?:pr|capture|test-audit|review-standard|upgrade-standard)\/SKILL\.md|github\.com\/mapringg\/standard\/blob\/[^/]+\/\.claude\/skills\/(?:pr|capture)\/SKILL\.md/;
14
+
15
+ function read(path) {
16
+ return existsSync(path) ? readFileSync(path, "utf8") : null;
17
+ }
18
+
19
+ function write(path, text) {
20
+ if (read(path) === text) return;
21
+ mkdirSync(dirname(path), { recursive: true });
22
+ writeFileSync(path, text);
23
+ }
24
+
25
+ function agents(root, installed) {
26
+ const path = join(root, "AGENTS.md");
27
+ const skillsRoot = installed
28
+ ? "node_modules/@mapringg/standard/.claude/skills"
29
+ : `https://github.com/mapringg/standard/blob/${releaseTag()}/.claude/skills`;
30
+ const original = read(path) ?? "# AGENTS.md\n";
31
+ const shared = original.split("\n").filter((line) => SKILLS.test(line));
32
+ if (
33
+ shared.length === 2 &&
34
+ ["pr", "capture"].every((skill) => shared.some((line) => line.includes(`${skillsRoot}/${skill}/SKILL.md)`)))
35
+ )
36
+ return;
37
+ const lines = original
38
+ .trimEnd()
39
+ .split("\n")
40
+ .filter((line) => !(/^\s*[-*] /.test(line) && SKILLS.test(line)));
41
+ const links = [
42
+ `- Use [PR writing](${skillsRoot}/pr/SKILL.md) when writing a pull request.`,
43
+ `- Follow [Capture](${skillsRoot}/capture/SKILL.md) when preparing pull request evidence.`,
44
+ ];
45
+ const sources = lines.indexOf("## Sources");
46
+ if (sources === -1) {
47
+ lines.push("", "## Sources", "", ...links);
48
+ } else {
49
+ let start = sources + 1;
50
+ while (lines[start] === "") start += 1;
51
+ lines.splice(sources + 1, start - sources - 1, "", ...links);
52
+ if (lines[sources + 4]?.startsWith("#")) lines.splice(sources + 4, 0, "");
53
+ }
54
+ write(path, `${lines.join("\n").trimEnd()}\n`);
55
+ }
56
+
57
+ function workflowFiles(root) {
58
+ const dir = join(root, ".github", "workflows");
59
+ if (!existsSync(dir)) return [];
60
+ return readdirSync(dir)
61
+ .filter((name) => /\.ya?ml$/.test(name))
62
+ .map((name) => {
63
+ const path = join(dir, name);
64
+ const doc = parseDocument(read(path));
65
+ if (doc.errors.length > 0) throw new Error(`Fix invalid workflow YAML in ${name} before adopting Standard.`);
66
+ return { path, doc, data: doc.toJS() ?? {} };
67
+ });
68
+ }
69
+
70
+ function hasPr(on) {
71
+ if (typeof on === "string") return on === "pull_request";
72
+ if (Array.isArray(on)) return on.includes("pull_request");
73
+ return Boolean(on && Object.hasOwn(on, "pull_request"));
74
+ }
75
+
76
+ function enablePrEdits(doc) {
77
+ const on = doc.get("on", true);
78
+ if (!isMap(on)) {
79
+ const values = isSeq(on) ? on.items.map((item) => item.value) : on?.value ? [on.value] : [];
80
+ doc.set("on", Object.fromEntries(values.map((event) => [event, null])));
81
+ }
82
+ const path = ["on", "pull_request"];
83
+ const existing = doc.getIn(path, true);
84
+ if (!isMap(existing)) doc.setIn(path, {});
85
+ const types = doc.getIn([...path, "types"], true);
86
+ const events = isSeq(types) ? types.items.map((item) => item.value) : [];
87
+ if (EVENTS.some((event) => !events.includes(event)))
88
+ doc.setIn([...path, "types"], [...new Set([...events, ...EVENTS])]);
89
+ }
90
+
91
+ function configureCheck(root, installed) {
92
+ const jobs = workflowFiles(root).flatMap((workflow) =>
93
+ Object.entries(workflow.data.jobs ?? {}).map(([id, job]) => ({ ...workflow, id, job })),
94
+ );
95
+ const candidates = jobs.filter(({ job }) => Array.isArray(job.steps));
96
+ const shared = candidates.find(({ job }) => job.steps.some((s) => s.uses?.startsWith(ACTION)));
97
+ const lint =
98
+ installed &&
99
+ read(join(root, ".oxlintrc.json"))?.includes("@mapringg/standard/oxlint.json") &&
100
+ candidates.find(
101
+ ({ job, data }) =>
102
+ hasPr(data.on) &&
103
+ job.steps.some((s) => /(?:\bpnpm\s+(?:run\s+)?lint\b|\.githooks\/pre-push)/.test(s.run ?? "")),
104
+ );
105
+ const check = shared || lint;
106
+ if (check) {
107
+ const { doc, path, id, job } = check;
108
+ const before = doc.toString();
109
+ enablePrEdits(doc);
110
+ const actionIndex = job.steps.findIndex((s) => s.uses?.startsWith(ACTION));
111
+ if (
112
+ actionIndex !== -1 &&
113
+ job.steps[actionIndex].uses !== `${ACTION}${releaseTag()}` &&
114
+ job.steps[actionIndex].uses !== `${ACTION}${releaseSha()}`
115
+ ) {
116
+ doc.setIn(["jobs", id, "steps", actionIndex, "uses"], `${ACTION}${releaseSha()}`);
117
+ }
118
+ if (doc.toString() !== before) write(path, doc.toString());
119
+ return job.name ?? id;
120
+ }
121
+ const name = jobs.some(({ id, job }) => (job.name ?? id).toLowerCase() === "check") ? "Standard PR" : "Check";
122
+ const path = join(root, ".github", "workflows", "standard-pr.yml");
123
+ if (existsSync(path)) throw new Error("Resolve the existing standard-pr.yml before adopting Standard.");
124
+ write(
125
+ path,
126
+ `name: Standard\n\non:\n pull_request:\n types: [${EVENTS.join(", ")}]\n push:\n branches: [main, develop]\n\npermissions:\n contents: read\n\njobs:\n check:\n name: ${name}\n runs-on: ubuntu-latest\n steps:\n - uses: ${CHECKOUT}\n with:\n persist-credentials: false\n - run: test -s AGENTS.md\n - uses: ${ACTION}${releaseSha()} # ${releaseTag()}\n`,
127
+ );
128
+ return name;
129
+ }
130
+
131
+ function pinBrowser(root) {
132
+ const canonical = join(root, "mise.toml");
133
+ const alternate = join(root, ".mise.toml");
134
+ const path = existsSync(alternate) && !existsSync(canonical) ? alternate : canonical;
135
+ const contents = read(path) ?? "";
136
+ if (contents.includes("agent-browser")) return;
137
+ const tool = '"npm:agent-browser" = "0.43.0"\n';
138
+ const tools = /^\[tools\][ \t]*\n/m;
139
+ write(
140
+ path,
141
+ tools.test(contents)
142
+ ? contents.replace(tools, `$&${tool}`)
143
+ : `${contents ? `${contents.trimEnd()}\n\n` : ""}[tools]\n${tool}`,
144
+ );
145
+ }
146
+
147
+ export function configure(root, name, { kind = "plain", initial = false } = {}) {
148
+ const isNewApp = kind === "app" && initial;
149
+ const path = join(root, "package.json");
150
+ const original = read(path);
151
+ const manifest = original ? JSON.parse(original) : {};
152
+ const current = manifest.devDependencies?.["@mapringg/standard"] ?? manifest.dependencies?.["@mapringg/standard"];
153
+ const installed = typeof current === "string" && current.startsWith(STANDARD);
154
+ const updateLock = installed && current !== `${STANDARD}${releaseTag()}`;
155
+ if (updateLock || isNewApp) {
156
+ let next = original ?? "{}\n";
157
+ if (updateLock) next = next.replaceAll(`"${current}"`, `"${STANDARD}${releaseTag()}"`);
158
+ if (isNewApp) next = next.replace(/"name":\s*"monorepo"/, `"name": ${JSON.stringify(name.toLowerCase())}`);
159
+ write(path, next);
160
+ }
161
+ if (isNewApp) {
162
+ const deploy = join(root, ".github", "workflows", "deploy-production.yml");
163
+ const contents = read(deploy);
164
+ if (contents) {
165
+ const doc = parseDocument(contents);
166
+ doc.set("on", "workflow_dispatch");
167
+ write(deploy, doc.toString());
168
+ }
169
+ }
170
+ if (kind === "app") pinBrowser(root);
171
+ agents(root, installed);
172
+ return { check: configureCheck(root, installed), updateLock };
173
+ }
@@ -0,0 +1,240 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { dirname, join, normalize } from "node:path";
3
+
4
+ import { classify } from "./markdown-lines.mjs";
5
+ import { anchorFor, listFiles, locate } from "./paths.mjs";
6
+
7
+ const SECTIONS = ["Rules", "Words", "Copy", "Decisions", "Traps", "Operations", "Sources"];
8
+ const MAX_LINES = 50;
9
+ const ROOT_README_LINES = 60;
10
+ const CODE = /\.[cm]?[jt]sx?$/;
11
+ const HEADING = /^ {0,3}(#{1,6})(?:[ \t]+(.*))?$/;
12
+ const SPAN = /(?<!`)(`+)(?!`)([\s\S]+?)(?<!`)\1(?!`)/g;
13
+ const INLINE_LINK =
14
+ /!?\[(?:[^\]\n]|\][^(])*?\]\(\s*(<[^>\n]*>|[^\s()]+(?:\([^\s()]*\)[^\s()]*)*)(?:\s+(?:"[^"\n]*"|'[^'\n]*'|\([^)\n]*\)))?\s*\)/g;
15
+ const REFERENCE = /^ {0,3}\[[^\]\n]+\]:[ \t]*(<[^>\n]*>|\S+)/gm;
16
+ const DIRS =
17
+ /^(?:\.{1,2}\/)*(?:\.github|\.claude|node_modules|dist|src|apps|packages|lib|scripts|infra|test|e2e|components|features)\//;
18
+ const EXTENSION = /\/[^/]*\.[a-z\d]+$/i;
19
+ const VERSION = /(?<![\d.])v?\d+\.\d+\.\d+(?!\.?\d)/g;
20
+ const STANDARD_PACKAGE = "node_modules/@mapringg/standard";
21
+ const AGENT_SKILLS = [
22
+ { name: "pr", label: "PR writing", use: "writing pull requests" },
23
+ { name: "capture", label: "Capture", use: "preparing pull request evidence" },
24
+ ];
25
+ const SINCE_LAST_RUN = "--since-last-run";
26
+ const CACHE_MS = 2000;
27
+ const scans = new Map();
28
+
29
+ function joined(lines) {
30
+ return lines.map((item) => item.line).join("\n");
31
+ }
32
+
33
+ function decode(value) {
34
+ try {
35
+ return decodeURIComponent(value);
36
+ } catch {
37
+ return value;
38
+ }
39
+ }
40
+
41
+ function destination(raw) {
42
+ const bare = raw.startsWith("<") ? raw.slice(1, -1) : raw;
43
+ const hash = bare.indexOf("#");
44
+ const path = (hash === -1 ? bare : bare.slice(0, hash)).split("?")[0];
45
+ return { raw, path: decode(path), anchor: hash === -1 ? undefined : decode(bare.slice(hash + 1)) };
46
+ }
47
+
48
+ function links(lines) {
49
+ const text = joined(lines).replaceAll(SPAN, "");
50
+ return [...text.matchAll(REFERENCE), ...text.matchAll(INLINE_LINK)].map((match) => destination(match[1]));
51
+ }
52
+
53
+ function headingOf(line) {
54
+ const match = HEADING.exec(line);
55
+ if (!match) return null;
56
+ const title = (match[2] ?? "").replace(/(?:^|[ \t]+)#+[ \t]*$/, "").trim();
57
+ return { level: match[1].length, title };
58
+ }
59
+
60
+ function rendered(title) {
61
+ return title
62
+ .replaceAll(/\]\([^)]*\)/g, "]")
63
+ .replaceAll(/\]\[[^\]]*\]/g, "]")
64
+ .replaceAll(/<[^>]+>/g, "")
65
+ .replaceAll("`", "")
66
+ .replaceAll(/(\*{1,3}|_{1,3})(\S(?:.*?\S)?)\1/g, "$2");
67
+ }
68
+
69
+ function slugs(lines) {
70
+ const seen = new Map();
71
+ const result = new Set();
72
+ for (const { line, kind } of lines) {
73
+ if (kind === "fence") continue;
74
+ const heading = headingOf(line);
75
+ if (!heading) continue;
76
+ const base = rendered(heading.title)
77
+ .trim()
78
+ .toLowerCase()
79
+ .replaceAll(/[^\p{L}\p{M}\p{N}\p{Pc} -]/gu, "")
80
+ .replaceAll(" ", "-");
81
+ let count = seen.get(base) ?? 0;
82
+ let slug = count === 0 ? base : `${base}-${count}`;
83
+ while (result.has(slug)) {
84
+ count += 1;
85
+ slug = `${base}-${count}`;
86
+ }
87
+ seen.set(base, count + 1);
88
+ result.add(slug);
89
+ }
90
+ return result;
91
+ }
92
+
93
+ function isPath(word) {
94
+ const token = word.replace(/[.,;:)]+$/, "");
95
+ if (token.startsWith("/") || token.includes("://") || token.endsWith(".md")) return false;
96
+ return DIRS.test(token) || (token.includes("/") && EXTENSION.test(token));
97
+ }
98
+
99
+ function shapeProblems(prose) {
100
+ const found = [];
101
+ const lines = prose.map((item) => item.line);
102
+ while (lines.length > 0 && lines.at(-1).trim() === "") lines.pop();
103
+ const titles = lines.map((line) => headingOf(line)).filter(Boolean);
104
+ if (!/^# \S/.test(lines[0] ?? "")) found.push("Start with one # title naming the app or repo.");
105
+ if (titles.filter((item) => item.level === 1).length > 1)
106
+ found.push("Keep one # title; make the others ## sections.");
107
+ if (titles.some((item) => item.level > 2)) found.push("Use only ## sections; fold deeper headings into bullets.");
108
+ const sections = titles.filter((item) => item.level === 2).map((item) => item.title);
109
+ const unknown = sections.filter((title) => !SECTIONS.includes(title));
110
+ if (unknown.length > 0) found.push(`Rename the section ${unknown.join(", ")} to one of ${SECTIONS.join(", ")}.`);
111
+ const order = sections.filter((title) => SECTIONS.includes(title)).map((title) => SECTIONS.indexOf(title));
112
+ if (order.some((index, at) => at > 0 && index <= order[at - 1]))
113
+ found.push(`Put each section once, in the order ${SECTIONS.join(", ")}.`);
114
+ if (lines.length > MAX_LINES)
115
+ found.push(`Cut it to ${MAX_LINES} lines; keep only what the code and lint cannot tell an agent.`);
116
+ return found;
117
+ }
118
+
119
+ function readmeProblems(prose, maxLines) {
120
+ const found = [];
121
+ const lines = prose.map(({ line }) => line).filter((line) => line.trim());
122
+ const titles = lines.map(headingOf).filter((heading) => heading?.level === 1 && heading.title);
123
+ if (titles.length !== 1) found.push("Use one # title naming the project.");
124
+ if (lines.length > maxLines)
125
+ found.push(`Cut it to ${maxLines} prose lines; keep setup, checks, and operational decisions.`);
126
+ return found;
127
+ }
128
+
129
+ function contentProblems(prose) {
130
+ const found = [];
131
+ const spans = [...joined(prose).matchAll(SPAN)].flatMap((match) => match[2].split(/\s+/));
132
+ const targets = links(prose).map((link) => link.path);
133
+ const paths = [...new Set([...spans, ...targets].filter((token) => isPath(token)))];
134
+ if (paths.length > 0)
135
+ found.push(`Name what ${paths.join(", ")} is instead of where it lives; paths go stale when files move.`);
136
+ const versions = [...new Set(prose.flatMap(({ line }) => line.match(VERSION) ?? []))];
137
+ if (versions.length > 0) found.push(`Drop ${versions.join(", ")}; the lockfile and manifests already pin versions.`);
138
+ return found;
139
+ }
140
+
141
+ function linkProblems(root, rel, prose, documentOf) {
142
+ const found = [];
143
+ for (const { raw, path, anchor } of links(prose)) {
144
+ if (/^[a-z][\w+.-]*:/i.test(path) || (path === "" && anchor === undefined)) continue;
145
+ const file = path ? normalize(join(dirname(rel), path)) : rel;
146
+ if (!existsSync(join(root, file))) {
147
+ found.push(`Fix the link to ${raw}; ${file} does not exist.`);
148
+ continue;
149
+ }
150
+ if (anchor === undefined || anchor === "" || !file.endsWith(".md")) continue;
151
+ if (!documentOf(file).slugs.has(anchor)) found.push(`Fix the link to ${raw}; ${file} has no heading #${anchor}.`);
152
+ }
153
+ return found;
154
+ }
155
+
156
+ function declaresVitest(root, files) {
157
+ return files
158
+ .filter((rel) => rel === "package.json" || rel.endsWith("/package.json"))
159
+ .some((rel) => {
160
+ const manifest = JSON.parse(readFileSync(join(root, rel), "utf8"));
161
+ return Boolean(manifest.dependencies?.vitest ?? manifest.devDependencies?.vitest);
162
+ });
163
+ }
164
+
165
+ function sharedSkillProblems(root, documentOf, files) {
166
+ if (!existsSync(join(root, STANDARD_PACKAGE, "package.json"))) return [];
167
+ const rootDoc = "AGENTS.md";
168
+ const prose = existsSync(join(root, rootDoc)) ? documentOf(rootDoc).prose : [];
169
+ const targets = new Set(links(prose).map(({ path }) => normalize(path)));
170
+ const findings = [];
171
+ for (const { name, label, use } of AGENT_SKILLS) {
172
+ const local = `.claude/skills/${name}/SKILL.md`;
173
+ const installed = `${STANDARD_PACKAGE}/${local}`;
174
+ if (!targets.has(normalize(installed)))
175
+ findings.push(`${rootDoc}: Add [${label}](${installed}) under ## Sources for ${use}.`);
176
+ if (existsSync(join(root, local))) {
177
+ findings.push(`${local}: Remove the local copy and use the installed standard skill linked in AGENTS.md.`);
178
+ }
179
+ }
180
+ if (declaresVitest(root, files) && !prose.some((item) => item.line.includes(SINCE_LAST_RUN)))
181
+ findings.push(
182
+ `${rootDoc}: Add a bullet under ## Rules to run \`pnpm --filter <app> exec vitest run ${SINCE_LAST_RUN}\` after each change and \`pnpm test\` at the end.`,
183
+ );
184
+ return findings;
185
+ }
186
+
187
+ function scan(root) {
188
+ const files = listFiles(root);
189
+ const lintable = files.filter((rel) => CODE.test(rel));
190
+ const monorepo = files.some((rel) => /^apps\/[^/]+\/package\.json$/.test(rel));
191
+ const documents = new Map();
192
+ const documentOf = (rel) => {
193
+ if (!documents.has(rel)) {
194
+ const lines = classify(readFileSync(join(root, rel), "utf8"));
195
+ documents.set(rel, { prose: lines.filter((item) => item.kind === "prose"), slugs: slugs(lines) });
196
+ }
197
+ return documents.get(rel);
198
+ };
199
+ const findings = new Map();
200
+ const rootAnchor = anchorFor("", lintable);
201
+ if (rootAnchor) findings.set(rootAnchor, sharedSkillProblems(root, documentOf, files));
202
+ for (const rel of files.filter((file) => file.endsWith(".md"))) {
203
+ const { prose } = documentOf(rel);
204
+ const name = rel.slice(rel.lastIndexOf("/") + 1);
205
+ const problems = linkProblems(root, rel, prose, documentOf);
206
+ if (name === "AGENTS.md") problems.push(...shapeProblems(prose), ...contentProblems(prose));
207
+ if (monorepo && rel === "README.md") problems.push(...readmeProblems(prose, ROOT_README_LINES));
208
+ const anchor = anchorFor(rel.includes("/") ? rel.slice(0, rel.lastIndexOf("/")) : "", lintable);
209
+ if (!anchor || problems.length === 0) continue;
210
+ findings.set(anchor, [...(findings.get(anchor) ?? []), ...problems.map((message) => `${rel}: ${message}`)]);
211
+ }
212
+ return findings;
213
+ }
214
+
215
+ function findingsFor(root) {
216
+ const cached = scans.get(root);
217
+ if (cached && Date.now() - cached.time < CACHE_MS) return cached.findings;
218
+ const findings = scan(root);
219
+ scans.set(root, { time: Date.now(), findings });
220
+ return findings;
221
+ }
222
+
223
+ export default {
224
+ meta: {
225
+ type: "problem",
226
+ docs: {
227
+ description:
228
+ "AGENTS.md and monorepo READMEs stay short; Markdown links resolve. Findings report on the nearest linted file.",
229
+ },
230
+ },
231
+ create(context) {
232
+ const where = locate(context.filename);
233
+ if (!where) return {};
234
+ return {
235
+ Program(node) {
236
+ for (const message of findingsFor(where.root).get(where.rel) ?? []) context.report({ node, message });
237
+ },
238
+ };
239
+ },
240
+ };
@@ -0,0 +1,75 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { join } from "node:path";
3
+
4
+ import { anchorFor, listFiles, locate } from "./paths.mjs";
5
+
6
+ const CODE = /\.[cm]?[jt]sx?$/;
7
+ const CONFIG = /(?:^|\/)\.?oxlintrc\.jsonc?$/;
8
+ const CACHE_MS = 2000;
9
+ const scans = new Map();
10
+
11
+ function shadcnRules(rules) {
12
+ return Object.entries(rules ?? {}).filter(([name]) => name.startsWith("shadcn/"));
13
+ }
14
+
15
+ function configProblems(config) {
16
+ const found = [];
17
+ if (config.settings?.shadcn !== undefined)
18
+ found.push("Delete settings.shadcn and import components from #/components/ui as Standard expects.");
19
+ for (const [name, value] of shadcnRules(config.rules)) {
20
+ if (value !== "off")
21
+ found.push(
22
+ `Delete the ${name} setting and fix the code with a variant, size, margin or a new component variant.`,
23
+ );
24
+ }
25
+ for (const override of config.overrides ?? []) {
26
+ for (const [name] of shadcnRules(override.rules))
27
+ found.push(`Delete the ${name} override and fix those files, or change the standard.`);
28
+ }
29
+ return found;
30
+ }
31
+
32
+ function scan(root) {
33
+ const files = listFiles(root);
34
+ const lintable = files.filter((rel) => CODE.test(rel));
35
+ const findings = new Map();
36
+ for (const rel of files.filter((file) => CONFIG.test(file))) {
37
+ let config;
38
+ try {
39
+ config = JSON.parse(readFileSync(join(root, rel), "utf8"));
40
+ } catch {
41
+ continue;
42
+ }
43
+ const problems = configProblems(config);
44
+ const anchor = anchorFor(rel.includes("/") ? rel.slice(0, rel.lastIndexOf("/")) : "", lintable);
45
+ if (!anchor || problems.length === 0) continue;
46
+ findings.set(anchor, [...(findings.get(anchor) ?? []), ...problems.map((message) => `${rel}: ${message}`)]);
47
+ }
48
+ return findings;
49
+ }
50
+
51
+ function findingsFor(root) {
52
+ const cached = scans.get(root);
53
+ if (cached && Date.now() - cached.time < CACHE_MS) return cached.findings;
54
+ const findings = scan(root);
55
+ scans.set(root, { time: Date.now(), findings });
56
+ return findings;
57
+ }
58
+
59
+ export default {
60
+ meta: {
61
+ type: "problem",
62
+ docs: {
63
+ description: "Projects keep Standard's design system rules as shipped and may only turn one off while upgrading.",
64
+ },
65
+ },
66
+ create(context) {
67
+ const where = locate(context.filename);
68
+ if (!where) return {};
69
+ return {
70
+ Program(node) {
71
+ for (const message of findingsFor(where.root).get(where.rel) ?? []) context.report({ node, message });
72
+ },
73
+ };
74
+ },
75
+ };
@@ -0,0 +1,38 @@
1
+ import { UI_APPS, locate, moduleVisitors } from "./paths.mjs";
2
+
3
+ const SHARED = /^#\/(?:lib|components)(?:\/|$)/;
4
+ const SHARED_API = /^(?:db|schema)(?:\.ts)?$/;
5
+ const COMPOSED = /^(?:db|schema|service)(?:\.ts)?$/;
6
+
7
+ export default {
8
+ meta: {
9
+ type: "problem",
10
+ docs: { description: "Features import only themselves and shared code; features meet in routes." },
11
+ },
12
+ create(context) {
13
+ const where = locate(context.filename);
14
+ if (!where?.feature || !where.kind) return {};
15
+ const own = `#/features/${where.feature}/`;
16
+ const routes = where.local === `src/features/${where.feature}/routes.ts`;
17
+ return moduleVisitors((source, node) => {
18
+ if (!source.startsWith("#/") || source.startsWith(own)) return;
19
+ const other = /^#\/features\/([^/]+)\/([^/]+)$/.exec(source);
20
+ if (where.kind === "hono") {
21
+ if (!other || (routes ? COMPOSED : SHARED_API).test(other[2])) return;
22
+ context.report({
23
+ node,
24
+ message: routes
25
+ ? "Import only db.ts, schema.ts or service.ts from another feature."
26
+ : "Import only db.ts or schema.ts from another feature, and compose services in routes.ts.",
27
+ });
28
+ return;
29
+ }
30
+ if (UI_APPS.has(where.kind) && !SHARED.test(source)) {
31
+ context.report({
32
+ node,
33
+ message: `Compose ${source} with this feature in a route; a feature imports only itself, #/lib and #/components.`,
34
+ });
35
+ }
36
+ });
37
+ },
38
+ };