@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,428 @@
1
+ import { matchesGlob } from "node:path";
2
+
3
+ import { UI_APPS, exportedIds, importedName, isTestSupport, locate, moduleVisitors, testedStem } from "./paths.mjs";
4
+
5
+ const UI = [...UI_APPS];
6
+ const API = ["hono"];
7
+ const APPS = [...API, ...UI];
8
+ const PARAMS = ["src/features/*/*-params.ts"];
9
+ const URL_PARAMS = [...PARAMS, "src/lib/**/*-params.ts"];
10
+ const ROUTES = ["src/app/**", "src/pages/**"];
11
+ const TESTS = ["**/*.test.ts", "**/*.test.tsx", "**/*.test-utils.ts", "e2e/*.test.ts"];
12
+ const OAUTH = "src/features/oauth/**";
13
+ const VIA = new Set(["window", "globalThis", "self"]);
14
+ const DRIVERS =
15
+ /^(?:pg|postgres|mysql2|mariadb|redis|ioredis|mongodb|mongoose|better-sqlite3|kysely|drizzle-orm|bun:sqlite|node:sqlite|@prisma\/client|@neondatabase\/.+|@libsql\/.+|@planetscale\/.+|@upstash\/.+|@aws-sdk\/.+|@google-cloud\/.+)(?:\/.*)?$/;
16
+
17
+ const TABLE = [
18
+ {
19
+ ban: { react: ["useState"] },
20
+ kinds: UI,
21
+ use: "Use one useReducer with its reducer in <feature>-state.ts, or useActionState, useOptimistic, useTransition.",
22
+ },
23
+ {
24
+ ban: { react: ["forwardRef"] },
25
+ kinds: UI,
26
+ use: "Take ref as a prop; React 19 passes it to function components.",
27
+ },
28
+ {
29
+ ban: { react: ["useEffect", "useLayoutEffect", "useInsertionEffect"] },
30
+ kinds: UI,
31
+ owner: ["src/components/ui/**", "src/lib/notifications.ts"],
32
+ use: "Derive the value while rendering, use a ref callback or a key reset, or wrap the library in components/ui.",
33
+ },
34
+ {
35
+ ban: { react: ["useSyncExternalStore"] },
36
+ kinds: UI,
37
+ owner: ["src/lib/**"],
38
+ use: "Put the store in src/lib/ and import its hook.",
39
+ },
40
+ {
41
+ ban: { react: ["Suspense"] },
42
+ kinds: ["next"],
43
+ owner: ["src/components/boundary/section.tsx"],
44
+ use: "Wrap the section in <Section fallback> from #/components/boundary/section.",
45
+ },
46
+ {
47
+ ban: { module: /^@tanstack\/react-query$/, names: ["useQuery", "useInfiniteQuery", "useQueries"] },
48
+ kinds: UI,
49
+ use: "Read with useSuspenseQuery or useSuspenseInfiniteQuery.",
50
+ },
51
+ {
52
+ ban: { module: /^@tanstack\/react-query(?:\/|$)/ },
53
+ kinds: UI,
54
+ owner: ["src/lib/query.ts"],
55
+ use: "Import TanStack Query through #/lib/query.",
56
+ },
57
+ {
58
+ ban: { module: /^#\/lib\/query$/, names: ["queryOptions", "infiniteQueryOptions"] },
59
+ kinds: UI,
60
+ owner: ["src/features/*/*-queries.ts"],
61
+ use: "Define query keys and queryOptions in <feature>-queries.ts.",
62
+ },
63
+ {
64
+ ban: { module: /^hono\/client$/, global: "fetch" },
65
+ kinds: UI,
66
+ owner: ["src/lib/api/**"],
67
+ use: "Call the API through the typed client in #/lib/api.",
68
+ },
69
+ {
70
+ ban: { literal: /^set-cookie$/i, method: ["getSetCookie"] },
71
+ kinds: UI,
72
+ owner: ["src/lib/api/**"],
73
+ use: "Forward the API's Set-Cookie only in #/lib/api.",
74
+ },
75
+ {
76
+ ban: { property: ["document", "cookie"] },
77
+ kinds: UI,
78
+ owner: ["src/lib/cookie.browser.ts"],
79
+ use: "Read and write cookies through the helper in #/lib/cookie.browser.",
80
+ },
81
+ {
82
+ ban: { global: "fetch" },
83
+ kinds: API,
84
+ owner: ["src/upstreams/**"],
85
+ except: { in: TESTS, imports: /^express$/, localServer: true },
86
+ use: "Call outside services through src/upstreams/<vendor>.ts with a timeout; a test may fetch a server it starts with .listen(port).",
87
+ },
88
+ {
89
+ ban: { module: /^(?:ai|@ai-sdk\/[^/]+)(?:\/|$)/ },
90
+ kinds: APPS,
91
+ owner: ["src/lib/ai.ts"],
92
+ use: "Call models through #/lib/ai.",
93
+ },
94
+ {
95
+ ban: { module: /^(?:@base-ui-components|@base-ui|@rn-primitives|@ui-sdk)\// },
96
+ kinds: UI,
97
+ owner: ["src/components/ui/**"],
98
+ use: "Use the primitives from #/components/ui.",
99
+ },
100
+ {
101
+ ban: { property: ["process", "env"] },
102
+ except: { env: true },
103
+ kinds: APPS,
104
+ owner: ["src/lib/env.ts", "src/env.ts", "*.config.*"],
105
+ use: "Read env vars through #/lib/env.",
106
+ },
107
+ {
108
+ ban: { meta: "env" },
109
+ kinds: APPS,
110
+ owner: ["src/lib/env.ts", "*.config.*"],
111
+ use: "Read env vars through #/lib/env.",
112
+ },
113
+ {
114
+ ban: { module: /^astro:env(?:\/|$)/ },
115
+ kinds: ["astro"],
116
+ owner: ["src/lib/env.ts"],
117
+ use: "Read env vars through #/lib/env.",
118
+ },
119
+ { ban: { global: "console" }, kinds: APPS, owner: ["src/lib/log.ts"], use: "Log through #/lib/log." },
120
+ { ban: { global: "JSON" }, kinds: APPS, owner: ["src/lib/json.ts"], use: "Parse and serialise through #/lib/json." },
121
+ {
122
+ ban: { global: "Intl", method: ["toLocaleString", "toLocaleDateString", "toLocaleTimeString"] },
123
+ kinds: APPS,
124
+ owner: ["src/lib/format.ts"],
125
+ use: "Format through #/lib/format.",
126
+ },
127
+ {
128
+ ban: { global: ["setTimeout", "setInterval", "clearTimeout", "clearInterval"] },
129
+ kinds: APPS,
130
+ owner: ["src/lib/timer.ts"],
131
+ use: "Schedule through #/lib/timer.",
132
+ },
133
+ {
134
+ ban: { global: "URLSearchParams" },
135
+ kinds: UI,
136
+ owner: URL_PARAMS,
137
+ use: "Read search params in a *-params.ts module with parse().",
138
+ },
139
+ {
140
+ ban: { property: [null, "searchParams"] },
141
+ kinds: UI,
142
+ owner: [...URL_PARAMS, "src/app/**/page.tsx"],
143
+ use: "Pass searchParams to parse() from a *-params.ts module.",
144
+ },
145
+ {
146
+ ban: { property: [null, "useSearch"], module: /^@tanstack\/react-router$/, names: ["useSearch"] },
147
+ kinds: ["vite"],
148
+ owner: PARAMS,
149
+ use: "Read search params in <feature>-params.ts.",
150
+ },
151
+ {
152
+ ban: { module: /^expo-router$/, names: ["useLocalSearchParams", "useGlobalSearchParams"] },
153
+ kinds: ["expo"],
154
+ owner: PARAMS,
155
+ use: "Read params in <feature>-params.ts.",
156
+ },
157
+ {
158
+ ban: { module: /^next\/navigation$/, names: ["useSearchParams"] },
159
+ kinds: ["next"],
160
+ owner: ["src/lib/next-route-params.ts"],
161
+ use: "Parse searchParams on the server and pass props, or use src/lib/next-route-params.ts in a persistent layout.",
162
+ },
163
+ {
164
+ ban: { property: ["router", "refresh"] },
165
+ kinds: UI,
166
+ use: "Update the cache in the Server Action with updateTag or refresh().",
167
+ },
168
+ {
169
+ ban: { module: /^(?:expo-router|@react-navigation\/native)$/, names: ["useFocusEffect"] },
170
+ kinds: ["expo"],
171
+ use: "Let TanStack Query refetch on focus.",
172
+ },
173
+ {
174
+ ban: { module: /^react-native$/, names: ["SafeAreaView"] },
175
+ kinds: ["expo"],
176
+ use: "Import SafeAreaView from react-native-safe-area-context.",
177
+ },
178
+ { ban: { property: ["Keyboard", "addListener"] }, kinds: ["expo"], use: "Use react-native-keyboard-controller." },
179
+ { ban: { property: ["StyleSheet", "create"] }, kinds: ["expo"], use: "Style with Uniwind classes." },
180
+ {
181
+ ban: { module: /^next\/headers$/ },
182
+ kinds: ["next"],
183
+ in: ROUTES,
184
+ use: "Read session and data in a feature component inside <Section>.",
185
+ },
186
+ {
187
+ ban: { module: /^#\/lib\/api(?:\/|$)|\.server$/ },
188
+ except: { module: /^#\/lib\/i18n\.server(?:\.ts)?$/ },
189
+ kinds: UI,
190
+ in: ROUTES,
191
+ owner: ["src/app/**/route.ts"],
192
+ use: "Import a feature component that loads its own data.",
193
+ },
194
+ {
195
+ ban: { module: /^#\/features\// },
196
+ kinds: APPS,
197
+ in: ["src/lib/**", "src/components/**"],
198
+ use: "Compose features in routes; lib and components stay feature-free.",
199
+ },
200
+ {
201
+ ban: { module: /^hono(?:\/tiny|\/quick)?$/, names: ["Hono"] },
202
+ kinds: API,
203
+ owner: ["src/factory.ts"],
204
+ use: "Build routers with factory.createApp() from #/factory.",
205
+ },
206
+ { ban: { module: /^hono\/factory$/ }, kinds: API, owner: ["src/factory.ts"], use: "Import factory from #/factory." },
207
+ {
208
+ ban: { module: /^(?:hono\/validator|@hono\/[a-z-]+-validator)$/ },
209
+ kinds: API,
210
+ owner: ["src/lib/validate.ts"],
211
+ use: "Validate input with v() from #/lib/validate.",
212
+ },
213
+ {
214
+ ban: { module: /^hono-openapi$/, names: ["validator"] },
215
+ kinds: API,
216
+ owner: ["src/lib/validate.ts"],
217
+ use: "Validate input with v() from #/lib/validate.",
218
+ },
219
+ {
220
+ ban: { module: DRIVERS },
221
+ kinds: API,
222
+ owner: ["src/features/*/db.ts", "src/infra/**"],
223
+ use: "Query through the feature's db.ts.",
224
+ },
225
+ {
226
+ ban: { property: [null, "onError"] },
227
+ kinds: API,
228
+ owner: ["src/app.ts", OAUTH],
229
+ use: "Throw ApiError; src/app.ts maps errors through lib/errors.ts.",
230
+ },
231
+ {
232
+ ban: { property: [null, "notFound"] },
233
+ kinds: API,
234
+ owner: ["src/app.ts", OAUTH],
235
+ use: 'Throw ApiError("not_found").',
236
+ },
237
+ {
238
+ ban: { property: [null, "put"] },
239
+ kinds: API,
240
+ in: ["src/features/*/routes.ts"],
241
+ use: "Use PATCH /:id with a partial body.",
242
+ },
243
+ {
244
+ ban: { export: ["publicRoutes", "PUBLIC_ROUTES", "publicPaths"] },
245
+ kinds: API,
246
+ owner: ["src/middleware/public-routes.ts"],
247
+ use: "List public routes in src/middleware/public-routes.ts.",
248
+ },
249
+ {
250
+ ban: { property: ["app", "request"] },
251
+ kinds: API,
252
+ in: TESTS,
253
+ except: { path: /^\/(?!api(?:\/|$))/ },
254
+ use: "Call /api routes through testClient().",
255
+ },
256
+ { ban: { property: ["expect", "poll"] }, in: TESTS, use: "Await the real event instead of polling." },
257
+ { ban: { property: ["jest", "setTimeout"] }, in: TESTS, use: "Make the test fast instead of raising its timeout." },
258
+ {
259
+ ban: { module: /^@testing-library\/react(?:-native)?$/, names: ["waitFor", "waitForElementToBeRemoved"] },
260
+ in: TESTS,
261
+ use: "Await findBy* queries or advance fake timers.",
262
+ },
263
+ ];
264
+
265
+ const matches = (local, globs) => globs.some((glob) => matchesGlob(local, glob));
266
+ const list = (value) => (Array.isArray(value) ? value : [value]);
267
+
268
+ function subjects(local) {
269
+ const tested = testedStem(local);
270
+ return tested ? [local, `${tested}.ts`, `${tested}.tsx`] : [local];
271
+ }
272
+
273
+ function applies(entry, where) {
274
+ if (entry.kinds && !entry.kinds.includes(where.kind)) return false;
275
+ if (entry.in && !matches(where.local, entry.in)) return false;
276
+ return !subjects(where.local).some((local) => matches(local, entry.owner ?? []));
277
+ }
278
+
279
+ function firstPath(node) {
280
+ const call = node.parent;
281
+ const arg = call?.type === "CallExpression" && call.callee === node ? call.arguments[0] : null;
282
+ if (arg?.type === "Literal" && typeof arg.value === "string") return arg.value;
283
+ if (arg?.type === "TemplateLiteral" && arg.expressions.length === 0) return arg.quasis[0].value.cooked;
284
+ return null;
285
+ }
286
+
287
+ function importBinding(scope, name) {
288
+ for (let current = scope; current; current = current.upper) {
289
+ const variable = current.set.get(name);
290
+ if (variable) return variable.defs[0]?.type === "ImportBinding";
291
+ }
292
+ return false;
293
+ }
294
+
295
+ export default {
296
+ meta: {
297
+ type: "problem",
298
+ docs: { description: "Owner files are the only users of the globals, modules and hooks they own." },
299
+ },
300
+ create(context) {
301
+ const where = locate(context.filename);
302
+ if (!where?.base) return {};
303
+ const rules = TABLE.filter((entry) => applies(entry, where));
304
+ if (rules.length === 0) return {};
305
+ const sources = [];
306
+ let localServer = false;
307
+ const pending = [];
308
+ const report = (node, entry) => pending.push({ node, entry });
309
+ const excepted = ({ node, entry }) => {
310
+ const rule = entry.except;
311
+ if (!rule) return false;
312
+ if (rule.module) return rule.module.test(node.source?.value ?? "");
313
+ if (rule.env) {
314
+ const parent = node.parent;
315
+ return (
316
+ (where.kind === "next" &&
317
+ where.local === "src/instrumentation.ts" &&
318
+ parent?.type === "MemberExpression" &&
319
+ !parent.computed &&
320
+ parent.property.name === "NEXT_RUNTIME") ||
321
+ (/\.(?:test-utils|fixture)\.[cm]?[jt]sx?$/.test(where.name) &&
322
+ parent?.type === "SpreadElement" &&
323
+ parent.parent?.type === "ObjectExpression")
324
+ );
325
+ }
326
+ if (rule.localServer && localServer && isTestSupport(where.name)) return true;
327
+ if (rule.in && !matches(where.local, rule.in)) return false;
328
+ if (rule.imports && !sources.some((source) => rule.imports.test(source))) return false;
329
+ return !rule.path || rule.path.test(firstPath(node) ?? "");
330
+ };
331
+ const globals = new Map(
332
+ rules.flatMap((entry) => (entry.ban.global ? list(entry.ban.global).map((name) => [name, entry]) : [])),
333
+ );
334
+ const hooks = new Map(rules.flatMap((entry) => (entry.ban.react ?? []).map((name) => [name, entry])));
335
+ const property = (object, name) =>
336
+ rules.find(
337
+ (entry) =>
338
+ entry.ban.property &&
339
+ entry.ban.property[1] === name &&
340
+ (entry.ban.property[0] === null || entry.ban.property[0] === object),
341
+ );
342
+ const namespaces = new Set();
343
+ const modules = moduleVisitors((source, node, specifiers) => {
344
+ sources.push(source);
345
+ if (source === "react")
346
+ for (const specifier of specifiers)
347
+ if (specifier.type === "ImportNamespaceSpecifier" || specifier.type === "ImportDefaultSpecifier")
348
+ namespaces.add(specifier.local.name);
349
+ for (const entry of rules) {
350
+ if (source === "react" && entry.ban.react) {
351
+ for (const specifier of specifiers)
352
+ if (entry.ban.react.includes(importedName(specifier))) report(specifier, entry);
353
+ }
354
+ if (!entry.ban.module?.test(source)) continue;
355
+ if (!entry.ban.names) report(node, entry);
356
+ else
357
+ for (const specifier of specifiers)
358
+ if (entry.ban.names.includes(importedName(specifier))) report(specifier, entry);
359
+ }
360
+ });
361
+ return {
362
+ ...modules,
363
+ CallExpression(node) {
364
+ if (
365
+ node.callee.type === "MemberExpression" &&
366
+ !node.callee.computed &&
367
+ node.callee.property.name === "listen" &&
368
+ typeof node.arguments[0]?.value === "number"
369
+ )
370
+ localServer = true;
371
+ },
372
+ MemberExpression(node) {
373
+ if (node.computed) return;
374
+ const name = node.property.name;
375
+ const object = node.object.type === "Identifier" ? node.object.name : null;
376
+ if (namespaces.has(object) && hooks.has(name) && importBinding(context.sourceCode.getScope(node), object))
377
+ report(node, hooks.get(name));
378
+ if (object && VIA.has(object) && globals.has(name)) report(node, globals.get(name));
379
+ if (node.object.type === "MetaProperty" && name === "env") {
380
+ const entry = rules.find((candidate) => candidate.ban.meta === "env");
381
+ if (entry) report(node, entry);
382
+ }
383
+ const factoryApp =
384
+ node.object.type === "CallExpression" &&
385
+ node.object.callee.type === "Identifier" &&
386
+ node.object.callee.name === "createApp";
387
+ const banned = property(factoryApp && name === "request" ? "app" : object, name);
388
+ if (banned) report(node, banned);
389
+ if (node.parent?.type === "CallExpression" && node.parent.callee === node) {
390
+ const entry = rules.find((candidate) => candidate.ban.method?.includes(name));
391
+ if (entry) report(node, entry);
392
+ }
393
+ },
394
+ JSXMemberExpression(node) {
395
+ const object = node.object.type === "JSXIdentifier" ? node.object.name : null;
396
+ const name = node.property.name;
397
+ if (namespaces.has(object) && hooks.has(name) && importBinding(context.sourceCode.getScope(node), object))
398
+ report(node, hooks.get(name));
399
+ },
400
+ Literal(node) {
401
+ if (typeof node.value !== "string") return;
402
+ const call = node.parent;
403
+ if (
404
+ call?.type === "CallExpression" &&
405
+ call.callee.type === "MemberExpression" &&
406
+ call.callee.property.name === "has"
407
+ )
408
+ return;
409
+ const entry = rules.find((candidate) => candidate.ban.literal?.test(node.value));
410
+ if (entry) report(node, entry);
411
+ },
412
+ ExportNamedDeclaration(node) {
413
+ modules.ExportNamedDeclaration(node);
414
+ const names = exportedIds(node).map((id) => id.name ?? id.value);
415
+ for (const entry of rules)
416
+ if (entry.ban.export && names.some((name) => entry.ban.export.includes(name))) report(node, entry);
417
+ },
418
+ "Program:exit"(program) {
419
+ if (globals.size > 0)
420
+ for (const reference of context.sourceCode.getScope(program).through) {
421
+ const entry = globals.get(reference.identifier.name);
422
+ if (entry) report(reference.identifier, entry);
423
+ }
424
+ for (const item of pending) if (!excepted(item)) context.report({ node: item.node, message: item.entry.use });
425
+ },
426
+ };
427
+ },
428
+ };
@@ -0,0 +1,75 @@
1
+ import { locate, stem } from "./paths.mjs";
2
+
3
+ const FIXED = new Set(["q", "sort", "cursor", "from", "to", "range"]);
4
+ const SYNONYMS = new Set([
5
+ "page",
6
+ "skip",
7
+ "offset",
8
+ "limit",
9
+ "search",
10
+ "query",
11
+ "keyword",
12
+ "term",
13
+ "sortBy",
14
+ "sortOrder",
15
+ "order",
16
+ "orderBy",
17
+ "direction",
18
+ "start",
19
+ "end",
20
+ "startDate",
21
+ "endDate",
22
+ "since",
23
+ "until",
24
+ "before",
25
+ "after",
26
+ "preset",
27
+ "period",
28
+ ]);
29
+ const CAMEL = /^[a-z][a-zA-Z0-9]*$/;
30
+
31
+ function allowed(key) {
32
+ return FIXED.has(key) || (key.length > 1 && CAMEL.test(key) && !SYNONYMS.has(key));
33
+ }
34
+
35
+ function keyName(property) {
36
+ return property.key?.name ?? property.key?.value;
37
+ }
38
+
39
+ export default {
40
+ meta: {
41
+ type: "problem",
42
+ docs: { description: "Params schemas use the standard names; LIFF routes validate search with them." },
43
+ },
44
+ create(context) {
45
+ const where = locate(context.filename);
46
+ const imports = new Map();
47
+ const visitors = {
48
+ ImportDeclaration(node) {
49
+ for (const specifier of node.specifiers) imports.set(specifier.local.name, node.source.value);
50
+ },
51
+ Property(node) {
52
+ if (where?.kind !== "vite" || keyName(node) !== "validateSearch") return;
53
+ const value = node.value.type === "MemberExpression" ? node.value.object : node.value;
54
+ const source = value.type === "Identifier" ? imports.get(value.name) : null;
55
+ if (!source || !source.replace(/\.[cm]?[jt]sx?$/, "").endsWith("-params"))
56
+ context.report({ node, message: "Set validateSearch to the params schema from <feature>-params.ts." });
57
+ },
58
+ };
59
+ if (stem(context.filename).endsWith("-params")) {
60
+ visitors.CallExpression = (node) => {
61
+ if (node.callee.type !== "MemberExpression" || node.callee.property.name !== "object") return;
62
+ for (const property of node.arguments[0]?.properties ?? []) {
63
+ const key = keyName(property);
64
+ if (key && !allowed(key)) {
65
+ context.report({
66
+ node: property,
67
+ message: `Rename ${key} to a standard param name: q, sort, cursor, from, to, range, <field>From, <field>To or a camelCase field name.`,
68
+ });
69
+ }
70
+ }
71
+ };
72
+ }
73
+ return visitors;
74
+ },
75
+ };
@@ -0,0 +1,192 @@
1
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
2
+ import { dirname, join, matchesGlob, relative, sep } from "node:path";
3
+
4
+ const SKIP = new Set([".git", "node_modules"]);
5
+
6
+ const roots = new Map();
7
+ const kinds = new Map();
8
+
9
+ function repoRoot(filename) {
10
+ const start = dirname(filename);
11
+ if (roots.has(start)) return roots.get(start);
12
+ let root = null;
13
+ for (let dir = start; ; dir = dirname(dir)) {
14
+ if (existsSync(join(dir, ".git"))) {
15
+ root = dir;
16
+ break;
17
+ }
18
+ if (dirname(dir) === dir) break;
19
+ }
20
+ roots.set(start, root);
21
+ return root;
22
+ }
23
+
24
+ export function locate(filename) {
25
+ const root = repoRoot(filename);
26
+ if (!root) return null;
27
+ return describe(relative(root, filename).split(sep).join("/"), root);
28
+ }
29
+
30
+ function appKind(root, base) {
31
+ const key = `${root}\0${base}`;
32
+ if (kinds.has(key)) return kinds.get(key);
33
+ const dir = join(root ?? "", base);
34
+ const path = join(dir, "package.json");
35
+ const manifest = existsSync(path) ? JSON.parse(readFileSync(path, "utf8")) : {};
36
+ const deps = { ...manifest.dependencies, ...manifest.devDependencies };
37
+ const kind =
38
+ ["next", "astro", "expo", "vite"].find((name) => deps[name]) ?? (manifest.dependencies?.hono ? "hono" : null);
39
+ kinds.set(key, kind);
40
+ return kind;
41
+ }
42
+
43
+ export function describe(rel, root = null) {
44
+ const parts = rel.split("/");
45
+ const grouped = (parts[0] === "apps" || parts[0] === "packages") && parts.length > 2;
46
+ const base = grouped ? `${parts[0]}/${parts[1]}` : null;
47
+ const local = grouped ? parts.slice(2).join("/") : rel;
48
+ const app = parts[0] === "apps" && grouped ? parts[1] : null;
49
+ return {
50
+ root,
51
+ rel,
52
+ name: parts.at(-1),
53
+ app,
54
+ kind: app ? appKind(root, base) : null,
55
+ pkg: parts[0] === "packages" && grouped ? parts[1] : null,
56
+ base,
57
+ local,
58
+ feature: /^src\/features\/([^/]+)\//.exec(local)?.[1] ?? null,
59
+ };
60
+ }
61
+
62
+ export const UI_APPS = new Set(["next", "vite", "expo", "astro"]);
63
+
64
+ export function stem(name) {
65
+ return name.replace(/\.(?:[cm]?[jt]sx?|astro)$/, "");
66
+ }
67
+
68
+ export function inside(local, prefix) {
69
+ return local === prefix || local.startsWith(`${prefix}/`);
70
+ }
71
+
72
+ export function isTest(name) {
73
+ return /\.test\.[cm]?[jt]sx?$/.test(name);
74
+ }
75
+
76
+ export const DATABASE_SUITE = /\.(mongo|redis)\.test\.[cm]?[jt]sx?$/;
77
+
78
+ export function testedStem(name) {
79
+ return /^(.+?)(?:\.(?:browser|mongo|redis))?\.test\.[cm]?[jt]sx?$/.exec(name)?.[1] ?? null;
80
+ }
81
+
82
+ export function isTestSupport(name) {
83
+ return isTest(name) || /\.(?:fixture|test-utils)\.[cm]?[jt]sx?$/.test(name);
84
+ }
85
+
86
+ export function isGenerated(name) {
87
+ return /\.d\.[cm]?ts$/.test(name) || /\.gen\.[cm]?[jt]sx?$/.test(name);
88
+ }
89
+
90
+ function moduleName(node) {
91
+ return node?.type === "Literal" && typeof node.value === "string" ? node.value : null;
92
+ }
93
+
94
+ function aliasPath(source) {
95
+ return source.startsWith("#/") ? source.replace(/\.(?:[cm]?[jt]s|[jt]sx)$/, "") : source;
96
+ }
97
+
98
+ export function moduleVisitors(callback) {
99
+ return {
100
+ ImportDeclaration(node) {
101
+ callback(aliasPath(node.source.value), node, node.specifiers);
102
+ },
103
+ ExportNamedDeclaration(node) {
104
+ if (node.source) callback(aliasPath(node.source.value), node, node.specifiers);
105
+ },
106
+ ExportAllDeclaration(node) {
107
+ callback(aliasPath(node.source.value), node, []);
108
+ },
109
+ ImportExpression(node) {
110
+ const name = moduleName(node.source);
111
+ if (name) callback(aliasPath(name), node, []);
112
+ },
113
+ };
114
+ }
115
+
116
+ export function importedName(specifier) {
117
+ if (specifier.type === "ImportSpecifier") return specifier.imported.name ?? specifier.imported.value;
118
+ if (specifier.type === "ExportSpecifier") return specifier.local.name ?? specifier.local.value;
119
+ return null;
120
+ }
121
+
122
+ function patternIds(pattern) {
123
+ if (!pattern) return [];
124
+ if (pattern.type === "Identifier") return [pattern];
125
+ if (pattern.type === "ObjectPattern")
126
+ return pattern.properties.flatMap((item) => patternIds(item.type === "RestElement" ? item.argument : item.value));
127
+ if (pattern.type === "ArrayPattern") return pattern.elements.flatMap((item) => patternIds(item));
128
+ if (pattern.type === "RestElement") return patternIds(pattern.argument);
129
+ if (pattern.type === "AssignmentPattern") return patternIds(pattern.left);
130
+ return [];
131
+ }
132
+
133
+ export function exportedIds(node) {
134
+ if (node.declaration?.type === "VariableDeclaration")
135
+ return node.declaration.declarations.flatMap((item) => patternIds(item.id));
136
+ if (node.declaration?.id) return [node.declaration.id];
137
+ return (node.specifiers ?? []).map((specifier) => specifier.exported);
138
+ }
139
+
140
+ function ignoreRules(root, dir, file) {
141
+ const path = join(root, dir, file);
142
+ if (!existsSync(path)) return [];
143
+ const rules = [];
144
+ for (const raw of readFileSync(path, "utf8").split("\n")) {
145
+ const line = raw.replace(/\s+$/, "");
146
+ if (!line || line.startsWith("#")) continue;
147
+ const negate = line.startsWith("!");
148
+ let pattern = negate ? line.slice(1) : line;
149
+ const dirOnly = pattern.endsWith("/");
150
+ pattern = pattern.replace(/\/$/, "");
151
+ const anchored = pattern.includes("/");
152
+ rules.push({ dir, pattern: pattern.replace(/^\//, ""), negate, dirOnly, anchored });
153
+ }
154
+ return rules;
155
+ }
156
+
157
+ function ignored(rules, rel, isDir) {
158
+ let result = false;
159
+ for (const rule of rules) {
160
+ if (rule.dirOnly && !isDir) continue;
161
+ if (rule.dir && !rel.startsWith(`${rule.dir}/`)) continue;
162
+ const local = rule.dir ? rel.slice(rule.dir.length + 1) : rel;
163
+ const target = rule.anchored ? local : local.slice(local.lastIndexOf("/") + 1);
164
+ if (matchesGlob(target, rule.pattern)) result = !rule.negate;
165
+ }
166
+ return result;
167
+ }
168
+
169
+ export function listFiles(root) {
170
+ const files = [];
171
+ const walk = (dir, inherited) => {
172
+ const rules = [...inherited, ...ignoreRules(root, dir, ".gitignore")];
173
+ for (const entry of readdirSync(join(root, dir), { withFileTypes: true })) {
174
+ if (SKIP.has(entry.name)) continue;
175
+ const rel = dir ? `${dir}/${entry.name}` : entry.name;
176
+ if (ignored(rules, rel, entry.isDirectory())) continue;
177
+ if (entry.isDirectory()) walk(rel, rules);
178
+ else if (entry.isFile()) files.push(rel);
179
+ }
180
+ };
181
+ walk("", ignoreRules(root, ".git/info", "exclude"));
182
+ return files.sort();
183
+ }
184
+
185
+ export function anchorFor(path, lintable) {
186
+ for (let dir = path; ; dir = dir.includes("/") ? dir.slice(0, dir.lastIndexOf("/")) : "") {
187
+ const prefix = dir ? `${dir}/` : "";
188
+ const hit = lintable.find((file) => file.startsWith(prefix));
189
+ if (hit) return hit;
190
+ if (!dir) return null;
191
+ }
192
+ }