@sdxc/kit 2026.10.25 → 2026.10.26

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 (72) hide show
  1. package/README.md +28 -15
  2. package/changelog.jsonl +40 -5
  3. package/dist/architecture/graph.d.ts +16 -3
  4. package/dist/architecture/graph.js +37 -19
  5. package/dist/architecture/layers.d.ts +10 -3
  6. package/dist/architecture/layers.js +38 -9
  7. package/dist/commands/destroy.d.ts +1 -1
  8. package/dist/commands/make.d.ts +5 -5
  9. package/dist/commands/make.js +11 -8
  10. package/dist/commands/scaffold.d.ts +1 -1
  11. package/dist/contract.d.ts +3 -3
  12. package/dist/doctor/checks.d.ts +2 -2
  13. package/dist/doctor/checks.js +14 -2
  14. package/dist/doctor/constant-names.d.ts +17 -0
  15. package/dist/doctor/constant-names.js +106 -0
  16. package/dist/doctor/dependencies.d.ts +3 -3
  17. package/dist/doctor/dependencies.js +3 -3
  18. package/dist/doctor/fan-out.d.ts +3 -2
  19. package/dist/doctor/fan-out.js +4 -3
  20. package/dist/doctor/fetch-param.d.ts +15 -0
  21. package/dist/doctor/fetch-param.js +37 -0
  22. package/dist/doctor/files.d.ts +2 -0
  23. package/dist/doctor/files.js +4 -0
  24. package/dist/doctor/local-const.d.ts +15 -0
  25. package/dist/doctor/local-const.js +54 -0
  26. package/dist/doctor/logger.d.ts +15 -0
  27. package/dist/doctor/logger.js +41 -0
  28. package/dist/doctor/orphans.d.ts +3 -3
  29. package/dist/doctor/orphans.js +33 -7
  30. package/dist/doctor/process-env.d.ts +15 -0
  31. package/dist/doctor/process-env.js +39 -0
  32. package/dist/doctor/project.js +17 -13
  33. package/dist/doctor/result-throws.d.ts +5 -4
  34. package/dist/doctor/result-throws.js +6 -5
  35. package/dist/doctor/source-rule.d.ts +35 -0
  36. package/dist/doctor/source-rule.js +52 -0
  37. package/dist/doctor/stack-imports.d.ts +15 -0
  38. package/dist/doctor/stack-imports.js +60 -0
  39. package/dist/doctor/syntax.d.ts +31 -0
  40. package/dist/doctor/syntax.js +56 -0
  41. package/dist/make/binding.d.ts +13 -8
  42. package/dist/make/binding.js +96 -64
  43. package/dist/make/from-model.js +2 -7
  44. package/dist/make/index.js +2 -7
  45. package/dist/package-manager.d.ts +6 -0
  46. package/dist/package-manager.js +25 -2
  47. package/dist/scaffold/index.js +2 -7
  48. package/dist/ui/commands.js +2 -5
  49. package/dist/ui/registry.d.ts +2 -2
  50. package/dist/upgrade/changelog.d.ts +2 -0
  51. package/dist/upgrade/changelog.js +2 -0
  52. package/dist/upgrade/project.d.ts +2 -2
  53. package/dist/upgrade/prompt.d.ts +3 -2
  54. package/dist/upgrade/prompt.js +43 -2
  55. package/package.json +3 -3
  56. package/stubs/scaffold.test-mcp.stub +5 -1
  57. package/templates/app/AGENTS.md +3 -1
  58. package/templates/app/app/commands/db/fresh.ts +20 -13
  59. package/templates/app/app/commands/db/migrate.ts +42 -32
  60. package/templates/app/app/http/controllers/api/openapi.test.ts +29 -0
  61. package/templates/app/app/http/controllers/api/openapi.tsx +8 -2
  62. package/templates/app/app/http/controllers/mcp.test.ts +16 -0
  63. package/templates/app/app/http/middleware/access.ts +6 -3
  64. package/templates/app/app/http/middleware/page.ts +3 -4
  65. package/templates/app/app/initializers/database.test.ts +6 -1
  66. package/templates/app/app/initializers/openapi.ts +5 -4
  67. package/templates/app/app/initializers/router.tsx +3 -4
  68. package/templates/app/app/test/cloudflare-workers.test.ts +27 -0
  69. package/templates/app/app/test/cloudflare-workers.ts +17 -4
  70. package/templates/app/app/test/database.ts +33 -0
  71. package/templates/app/app/test/mcp.ts +96 -0
  72. package/templates/app/resources/layouts/document.tsx +2 -3
@@ -1,43 +1,61 @@
1
1
  /**
2
2
  * The app-layout layers Clean Architecture's dependency rule maps onto: outer kinds may import
3
3
  * inner ones, never the reverse, so a model never reaches a controller and a view never pulls a
4
- * job. Ranks are the only rule; same-rank edges stay allowed.
4
+ * job. Route contracts and handler declarations are data every layer may read.
5
5
  *
6
6
  * @author [Sergio Xalambrí](https://sergiodxa.com)
7
7
  * @copyright Sergio Xalambrí 2026
8
8
  */
9
- /** Higher rank is more inward; an import may only reach a layer at this rank or higher. */
9
+ /**
10
+ * Higher rank is more inward; an import may only reach a layer at this rank or higher. Route
11
+ * contracts are innermost, since controllers, views and the router all read them, and views sit
12
+ * between the handlers that render them and the instances they read.
13
+ */
10
14
  export const LAYER_RANK = {
15
+ routes: 50,
11
16
  models: 40,
12
17
  policies: 30,
13
18
  services: 30,
14
19
  initializers: 30,
20
+ resources: 25,
15
21
  http: 20,
16
22
  jobs: 20,
17
23
  mcp: 20,
18
24
  emails: 20,
19
25
  commands: 20,
20
26
  test: 20,
21
- resources: 10,
22
- routes: 10,
23
27
  bootstrap: 10,
24
28
  };
25
29
  /** Display order for architecture diagrams, outer first. */
26
30
  export const LAYER_ORDER = [
27
31
  "bootstrap",
28
- "routes",
29
- "resources",
30
32
  "http",
31
33
  "jobs",
32
34
  "mcp",
33
35
  "emails",
34
36
  "commands",
35
37
  "test",
38
+ "resources",
36
39
  "initializers",
37
40
  "services",
38
41
  "policies",
39
42
  "models",
43
+ "routes",
40
44
  ];
45
+ /**
46
+ * The modules that declare what a runtime offers: jobs, commands, emails, MCP tools and
47
+ * resources. Each holds names and schemas only, so the initializer that maps them and the
48
+ * handlers that enqueue or send through them both read it.
49
+ */
50
+ const DECLARATIONS = new Set([
51
+ "app/jobs/index.ts",
52
+ "app/commands/index.ts",
53
+ "app/emails/index.ts",
54
+ "app/mcp/tools/index.ts",
55
+ "app/mcp/resources/index.ts",
56
+ ]);
57
+ /** Where an app's own middleware lives, which the router initializer composes into its chain. */
58
+ const MIDDLEWARE = "app/http/middleware/";
41
59
  /** Prefixes that assign a path to a layer, most specific first. */
42
60
  const LAYER_PREFIXES = [
43
61
  ["app/http/", "http"],
@@ -61,7 +79,7 @@ const LAYER_PREFIXES = [
61
79
  * @param path - Project-relative path with `/` separators.
62
80
  */
63
81
  export function layerOf(path) {
64
- let normalized = path.split("\\").join("/");
82
+ let normalized = normalize(path);
65
83
  for (let [prefix, layer] of LAYER_PREFIXES) {
66
84
  if (normalized === prefix.slice(0, -1) || normalized.startsWith(prefix))
67
85
  return layer;
@@ -70,12 +88,23 @@ export function layerOf(path) {
70
88
  }
71
89
  /**
72
90
  * Whether an import from `from` to `to` obeys the dependency rule. Unranked endpoints are left
73
- * alone so config and packages stay free to import.
91
+ * alone so config and packages stay free to import, any layer reads a declaration module, and
92
+ * an initializer reads the middleware its router's global chain lists.
74
93
  */
75
94
  export function allowsDependency(from, to) {
76
95
  let source = layerOf(from);
77
96
  let target = layerOf(to);
78
- if (source === null || target === null)
97
+ if (source === null || target === null || isDeclaration(to))
98
+ return true;
99
+ if (source === "initializers" && normalize(to).startsWith(MIDDLEWARE))
79
100
  return true;
80
101
  return LAYER_RANK[source] <= LAYER_RANK[target];
81
102
  }
103
+ /** Whether `path` is a module that declares a runtime's jobs, commands, emails or MCP handlers. */
104
+ export function isDeclaration(path) {
105
+ return DECLARATIONS.has(normalize(path));
106
+ }
107
+ /** `path` with `/` separators. */
108
+ function normalize(path) {
109
+ return path.split("\\").join("/");
110
+ }
@@ -8,7 +8,7 @@
8
8
  */
9
9
  /** Removes what `sdxc make` wrote for one kind and name, after one confirmation. */
10
10
  declare const _default: import("@sdxc/cli").CommandAction<import("@sdxc/cli").Command<{
11
- readonly kind: import("@sdxc/cli").Argument<"email" | "command" | "model" | "service" | "controller" | "middleware" | "validator" | "job" | "factory" | "initializer" | "mcp">;
11
+ readonly kind: import("@sdxc/cli").Argument<"email" | "command" | "controller" | "middleware" | "validator" | "job" | "model" | "factory" | "service" | "initializer" | "mcp">;
12
12
  readonly name: import("@sdxc/cli").Argument<string>;
13
13
  }, {
14
14
  readonly yes: import("@sdxc/cli").Flag<boolean>;
@@ -14,7 +14,7 @@ export declare const controller: import("@sdxc/cli").CommandAction<import("@sdxc
14
14
  readonly path: import("@sdxc/cli").ValueFlag<string, false, false, false>;
15
15
  readonly routes: import("@sdxc/cli").ValueFlag<string, false, false, false>;
16
16
  readonly resource: import("@sdxc/cli").ValueFlag<string, false, false, false>;
17
- readonly actions: import("@sdxc/cli").ValueFlag<"index" | "new" | "all" | "show" | "edit" | "create" | "update" | "destroy", false, true, false>;
17
+ readonly actions: import("@sdxc/cli").ValueFlag<"index" | "new" | "create" | "update" | "all" | "show" | "edit" | "destroy", false, true, false>;
18
18
  readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
19
19
  readonly spec: import("@sdxc/cli").Flag<boolean | undefined>;
20
20
  readonly dryRun: import("@sdxc/cli").Flag<boolean>;
@@ -257,7 +257,7 @@ export declare const stubs: import("@sdxc/cli").CommandAction<import("@sdxc/cli"
257
257
  value: string;
258
258
  property: "packageRoot";
259
259
  }>]>;
260
- /** `sdxc make secret`. */
260
+ /** `sdxc make secret`, which declares the secret and lists it in `.env.example`. */
261
261
  export declare const secret: import("@sdxc/cli").CommandAction<import("@sdxc/cli").Command<{
262
262
  readonly name: import("@sdxc/cli").Argument<string>;
263
263
  }, {
@@ -272,7 +272,7 @@ export declare const secret: import("@sdxc/cli").CommandAction<import("@sdxc/cli
272
272
  value: string;
273
273
  property: "packageRoot";
274
274
  }>]>;
275
- /** `sdxc make binding`. */
275
+ /** `sdxc make binding`, which declares one `bindings.<kind>()` entry in the Worker's `env`. */
276
276
  export declare const binding: import("@sdxc/cli").CommandAction<import("@sdxc/cli").Command<{
277
277
  readonly kind: import("@sdxc/cli").Argument<"secret" | "kv" | "d1" | "r2" | "queue" | "rateLimit" | "sendEmail" | "durableObject">;
278
278
  readonly name: import("@sdxc/cli").Argument<string>;
@@ -288,7 +288,7 @@ export declare const binding: import("@sdxc/cli").CommandAction<import("@sdxc/cl
288
288
  value: string;
289
289
  property: "packageRoot";
290
290
  }>]>;
291
- /** `sdxc make do`. */
291
+ /** `sdxc make do`, which writes a Durable Object class with its export and binding. */
292
292
  export declare const durableObject: import("@sdxc/cli").CommandAction<import("@sdxc/cli").Command<{
293
293
  readonly name: import("@sdxc/cli").Argument<string>;
294
294
  }, {
@@ -329,7 +329,7 @@ export declare const group: import("@sdxc/cli").CommandAction<import("@sdxc/cli"
329
329
  readonly path: import("@sdxc/cli").ValueFlag<string, false, false, false>;
330
330
  readonly routes: import("@sdxc/cli").ValueFlag<string, false, false, false>;
331
331
  readonly resource: import("@sdxc/cli").ValueFlag<string, false, false, false>;
332
- readonly actions: import("@sdxc/cli").ValueFlag<"index" | "new" | "all" | "show" | "edit" | "create" | "update" | "destroy", false, true, false>;
332
+ readonly actions: import("@sdxc/cli").ValueFlag<"index" | "new" | "create" | "update" | "all" | "show" | "edit" | "destroy", false, true, false>;
333
333
  readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
334
334
  readonly spec: import("@sdxc/cli").Flag<boolean | undefined>;
335
335
  readonly dryRun: import("@sdxc/cli").Flag<boolean>;
@@ -11,7 +11,7 @@ import { isFailure } from "@sdxc/result";
11
11
  import { METHODS, SDXC_COMMANDS } from "../contract.js";
12
12
  import { makeActions } from "../make/actions.js";
13
13
  import { makeBinding, makeDo, makeSecret } from "../make/binding.js";
14
- import { make } from "../make/index.js";
14
+ import { finish, make } from "../make/index.js";
15
15
  import { copyStubs } from "../make/stubs.js";
16
16
  import { makeTest } from "../make/test.js";
17
17
  import { packageRoot, project } from "../middleware.js";
@@ -233,9 +233,10 @@ export const stubs = createCommand(SDXC_COMMANDS.make.stubs, {
233
233
  return success();
234
234
  },
235
235
  });
236
- /** `sdxc make secret`. */
236
+ /** `sdxc make secret`, which declares the secret and lists it in `.env.example`. */
237
237
  export const secret = createCommand(SDXC_COMMANDS.make.secret, {
238
238
  middleware: MAKE_MIDDLEWARE,
239
+ /** Formats what it edited, as every kind does, then notes `sdxc run typegen`. */
239
240
  async handler(ctx) {
240
241
  let made = await makeSecret(ctx, ctx.project.root, {
241
242
  name: ctx.arguments.name,
@@ -244,12 +245,13 @@ export const secret = createCommand(SDXC_COMMANDS.make.secret, {
244
245
  });
245
246
  if (isFailure(made))
246
247
  return made;
247
- return success();
248
+ return finish(ctx, ctx.project, made.data);
248
249
  },
249
250
  });
250
- /** `sdxc make binding`. */
251
+ /** `sdxc make binding`, which declares one `bindings.<kind>()` entry in the Worker's `env`. */
251
252
  export const binding = createCommand(SDXC_COMMANDS.make.binding, {
252
253
  middleware: MAKE_MIDDLEWARE,
254
+ /** Formats what it edited, as every kind does, then notes `sdxc run typegen`. */
253
255
  async handler(ctx) {
254
256
  let made = await makeBinding(ctx, ctx.project.root, {
255
257
  kind: ctx.arguments.kind,
@@ -259,14 +261,15 @@ export const binding = createCommand(SDXC_COMMANDS.make.binding, {
259
261
  });
260
262
  if (isFailure(made))
261
263
  return made;
262
- return success();
264
+ return finish(ctx, ctx.project, made.data);
263
265
  },
264
266
  });
265
- /** `sdxc make do`. */
267
+ /** `sdxc make do`, which writes a Durable Object class with its export and binding. */
266
268
  export const durableObject = createCommand(SDXC_COMMANDS.make.do, {
267
269
  middleware: MAKE_MIDDLEWARE,
270
+ /** Formats what it wrote and edited, as every kind does, then notes `sdxc run typegen`. */
268
271
  async handler(ctx) {
269
- let made = await makeDo(ctx, ctx.project.root, ctx.packageRoot, {
272
+ let made = await makeDo(ctx, ctx.project.root, {
270
273
  name: ctx.arguments.name,
271
274
  role: ctx.flags.role,
272
275
  binding: ctx.flags.binding,
@@ -275,7 +278,7 @@ export const durableObject = createCommand(SDXC_COMMANDS.make.do, {
275
278
  });
276
279
  if (isFailure(made))
277
280
  return made;
278
- return success();
281
+ return finish(ctx, ctx.project, made.data);
279
282
  },
280
283
  });
281
284
  /**
@@ -14,7 +14,7 @@ declare const _default: import("@sdxc/cli").CommandAction<import("@sdxc/cli").Co
14
14
  readonly mcp: import("@sdxc/cli").Flag<boolean>;
15
15
  readonly command: import("@sdxc/cli").Flag<boolean>;
16
16
  readonly api: import("@sdxc/cli").Flag<boolean>;
17
- readonly skip: import("@sdxc/cli").ValueFlag<"model" | "validator" | "migration" | "factory" | "policy" | "pages", false, true, false>;
17
+ readonly skip: import("@sdxc/cli").ValueFlag<"validator" | "model" | "migration" | "factory" | "policy" | "pages", false, true, false>;
18
18
  readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
19
19
  readonly spec: import("@sdxc/cli").Flag<boolean | undefined>;
20
20
  readonly dryRun: import("@sdxc/cli").Flag<boolean>;
@@ -22,7 +22,7 @@ export declare const SDXC_COMMANDS: import("@sdxc/cli").Group<Omit<{
22
22
  readonly skip: import("@sdxc/cli").ValueFlag<"build" | "migrate" | "deploy", false, true, false>;
23
23
  }>;
24
24
  readonly destroy: import("@sdxc/cli").Command<{
25
- readonly kind: import("@sdxc/cli").Argument<"email" | "command" | "model" | "service" | "controller" | "middleware" | "validator" | "job" | "factory" | "initializer" | "mcp">;
25
+ readonly kind: import("@sdxc/cli").Argument<"email" | "command" | "controller" | "middleware" | "validator" | "job" | "model" | "factory" | "service" | "initializer" | "mcp">;
26
26
  readonly name: import("@sdxc/cli").Argument<string>;
27
27
  }, {
28
28
  readonly yes: import("@sdxc/cli").Flag<boolean>;
@@ -76,7 +76,7 @@ export declare const SDXC_COMMANDS: import("@sdxc/cli").Group<Omit<{
76
76
  readonly path: import("@sdxc/cli").ValueFlag<string, false, false, false>;
77
77
  readonly routes: import("@sdxc/cli").ValueFlag<string, false, false, false>;
78
78
  readonly resource: import("@sdxc/cli").ValueFlag<string, false, false, false>;
79
- readonly actions: import("@sdxc/cli").ValueFlag<"index" | "new" | "all" | "show" | "edit" | "create" | "update" | "destroy", false, true, false>;
79
+ readonly actions: import("@sdxc/cli").ValueFlag<"index" | "new" | "create" | "update" | "all" | "show" | "edit" | "destroy", false, true, false>;
80
80
  readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
81
81
  readonly spec: import("@sdxc/cli").Flag<boolean | undefined>;
82
82
  readonly dryRun: import("@sdxc/cli").Flag<boolean>;
@@ -247,7 +247,7 @@ export declare const SDXC_COMMANDS: import("@sdxc/cli").Group<Omit<{
247
247
  readonly mcp: import("@sdxc/cli").Flag<boolean>;
248
248
  readonly command: import("@sdxc/cli").Flag<boolean>;
249
249
  readonly api: import("@sdxc/cli").Flag<boolean>;
250
- readonly skip: import("@sdxc/cli").ValueFlag<"model" | "validator" | "migration" | "factory" | "policy" | "pages", false, true, false>;
250
+ readonly skip: import("@sdxc/cli").ValueFlag<"validator" | "model" | "migration" | "factory" | "policy" | "pages", false, true, false>;
251
251
  readonly test: import("@sdxc/cli").Flag<boolean | undefined>;
252
252
  readonly spec: import("@sdxc/cli").Flag<boolean | undefined>;
253
253
  readonly dryRun: import("@sdxc/cli").Flag<boolean>;
@@ -9,8 +9,8 @@
9
9
  import type { Check, CheckReport } from "./check.js";
10
10
  /**
11
11
  * Every built-in check: release drift, the install and the `remix` peer first, then the
12
- * Worker's secrets and types, then the app's own code, layout and quality metrics, then
13
- * copied components.
12
+ * Worker's secrets and types, then the app's own code, layout, quality metrics and source
13
+ * conventions, then copied components.
14
14
  */
15
15
  export declare const CHECKS: readonly Check[];
16
16
  /** Whether any check failed, which makes `sdxc doctor` exit 1. */
@@ -7,6 +7,7 @@
7
7
  * @copyright Sergio Xalambrí 2026
8
8
  */
9
9
  import { complexityCheck } from "./complexity.js";
10
+ import { constantNamesCheck } from "./constant-names.js";
10
11
  import { crapCheck } from "./crap.js";
11
12
  import { dependenciesCheck } from "./dependencies.js";
12
13
  import { duplicationCheck } from "./duplication.js";
@@ -14,25 +15,30 @@ import { emailsCheck } from "./emails.js";
14
15
  import { envCheck } from "./env.js";
15
16
  import { fanOutCheck } from "./fan-out.js";
16
17
  import { featureScatterCheck } from "./feature-scatter.js";
18
+ import { fetchParamCheck } from "./fetch-param.js";
17
19
  import { installedCheck } from "./installed.js";
18
20
  import { jsdocCheck } from "./jsdoc.js";
19
21
  import { layoutCheck } from "./layout.js";
22
+ import { localConstCheck } from "./local-const.js";
23
+ import { loggerCheck } from "./logger.js";
20
24
  import { migrationsCheck } from "./migrations.js";
21
25
  import { modelsCheck } from "./models.js";
22
26
  import { moduleSizeCheck } from "./module-size.js";
23
27
  import { mutationCheck } from "./mutation.js";
24
28
  import { orphansCheck } from "./orphans.js";
25
29
  import { pinsCheck } from "./pins.js";
30
+ import { processEnvCheck } from "./process-env.js";
26
31
  import { remixCheck } from "./remix.js";
27
32
  import { resultThrowsCheck } from "./result-throws.js";
28
33
  import { routesCheck } from "./routes.js";
34
+ import { stackImportsCheck } from "./stack-imports.js";
29
35
  import { testRatioCheck } from "./test-ratio.js";
30
36
  import { typegenCheck } from "./typegen.js";
31
37
  import { uiCheck } from "./ui.js";
32
38
  /**
33
39
  * Every built-in check: release drift, the install and the `remix` peer first, then the
34
- * Worker's secrets and types, then the app's own code, layout and quality metrics, then
35
- * copied components.
40
+ * Worker's secrets and types, then the app's own code, layout, quality metrics and source
41
+ * conventions, then copied components.
36
42
  */
37
43
  export const CHECKS = [
38
44
  pinsCheck,
@@ -54,6 +60,12 @@ export const CHECKS = [
54
60
  featureScatterCheck,
55
61
  duplicationCheck,
56
62
  resultThrowsCheck,
63
+ localConstCheck,
64
+ constantNamesCheck,
65
+ stackImportsCheck,
66
+ processEnvCheck,
67
+ fetchParamCheck,
68
+ loggerCheck,
57
69
  testRatioCheck,
58
70
  crapCheck,
59
71
  mutationCheck,
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The `constant-names` check: a module-level `const` holding a value is named in
3
+ * `UPPER_SNAKE_CASE`, so a reader tells a module's data from its functions at the use site.
4
+ * Exports are public names chosen for callers, and a call's result may be a service, so both are left out.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { SourceFinding, SourceRule } from "./source-rule.js";
10
+ /** Every non-exported module-level `const` whose value is a literal, named in another case. */
11
+ export declare const CONSTANT_NAMES_RULE: SourceRule;
12
+ /** Warns on each module-level constant value whose name is not `UPPER_SNAKE_CASE`. */
13
+ export declare const constantNamesCheck: import("./check.js").Check;
14
+ /** Each top-level, non-exported `const` in `source` holding a literal value under another case. */
15
+ export declare function findConstantNames(file: string, source: string): SourceFinding[];
16
+ /** `name` in `UPPER_SNAKE_CASE`: `maxRetries` is `MAX_RETRIES`. */
17
+ export declare function toUpperSnake(name: string): string;
@@ -0,0 +1,106 @@
1
+ /**
2
+ * The `constant-names` check: a module-level `const` holding a value is named in
3
+ * `UPPER_SNAKE_CASE`, so a reader tells a module's data from its functions at the use site.
4
+ * Exports are public names chosen for callers, and a call's result may be a service, so both are left out.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { sourceCheck } from "./source-rule.js";
10
+ import { isNode, lineAt, parseModule } from "./syntax.js";
11
+ /** A name in `UPPER_SNAKE_CASE`. */
12
+ const UPPER_SNAKE = /^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)*$/;
13
+ /** Constructors whose instance is a value the module holds, as a literal is. */
14
+ const VALUE_CONSTRUCTORS = new Set(["Set", "Map", "WeakSet", "WeakMap", "RegExp", "URL", "Date"]);
15
+ /** Expressions that only annotate the value they wrap. */
16
+ const WRAPPERS = new Set(["TSAsExpression", "TSSatisfiesExpression", "ParenthesizedExpression"]);
17
+ /** Function expressions, which make a property a member function rather than data. */
18
+ const FUNCTIONS = new Set(["FunctionExpression", "ArrowFunctionExpression"]);
19
+ /** Every non-exported module-level `const` whose value is a literal, named in another case. */
20
+ export const CONSTANT_NAMES_RULE = {
21
+ name: "constant-names",
22
+ tests: true,
23
+ find: findConstantNames,
24
+ passed: "Every module-level constant value is named in UPPER_SNAKE_CASE",
25
+ noun: ["constant not in UPPER_SNAKE_CASE", "constants not in UPPER_SNAKE_CASE"],
26
+ fix: "Rename it in UPPER_SNAKE_CASE; functions and objects of functions keep camelCase",
27
+ };
28
+ /** Warns on each module-level constant value whose name is not `UPPER_SNAKE_CASE`. */
29
+ export const constantNamesCheck = sourceCheck(CONSTANT_NAMES_RULE);
30
+ /** Each top-level, non-exported `const` in `source` holding a literal value under another case. */
31
+ export function findConstantNames(file, source) {
32
+ let parsed = parseModule(file, source);
33
+ if (parsed === null)
34
+ return [];
35
+ let findings = [];
36
+ for (let statement of nodes(parsed.program.body)) {
37
+ if (statement.type !== "VariableDeclaration" || statement.kind !== "const")
38
+ continue;
39
+ if (statement.declare === true)
40
+ continue;
41
+ for (let declarator of nodes(statement.declarations)) {
42
+ let id = declarator.id;
43
+ if (!isNode(id) || id.type !== "Identifier" || typeof id.name !== "string")
44
+ continue;
45
+ if (UPPER_SNAKE.test(id.name) || !isValue(declarator.init))
46
+ continue;
47
+ findings.push({
48
+ line: lineAt(source, declarator.start),
49
+ message: `${id.name} holds a value; name it ${toUpperSnake(id.name)}`,
50
+ });
51
+ }
52
+ }
53
+ return findings;
54
+ }
55
+ /** `name` in `UPPER_SNAKE_CASE`: `maxRetries` is `MAX_RETRIES`. */
56
+ export function toUpperSnake(name) {
57
+ return name
58
+ .replace(/([a-z0-9])([A-Z])/g, "$1_$2")
59
+ .replace(/[^A-Za-z0-9]+/g, "_")
60
+ .replace(/^_+|_+$/g, "")
61
+ .toUpperCase();
62
+ }
63
+ /**
64
+ * Whether `init` is data: a literal, template, array, object of non-function members, or a
65
+ * `Set`, `Map`, `RegExp`, `URL` or `Date` built in place.
66
+ */
67
+ function isValue(init) {
68
+ let node = unwrap(init);
69
+ if (node === null)
70
+ return false;
71
+ switch (node.type) {
72
+ case "Literal":
73
+ case "TemplateLiteral":
74
+ case "ArrayExpression":
75
+ return true;
76
+ case "UnaryExpression":
77
+ return isNode(node.argument) && node.argument.type === "Literal";
78
+ case "ObjectExpression":
79
+ return nodes(node.properties).every(isDataMember);
80
+ case "NewExpression":
81
+ return isNode(node.callee) && VALUE_CONSTRUCTORS.has(String(node.callee.name));
82
+ default:
83
+ return false;
84
+ }
85
+ }
86
+ /** An object member that holds data: a spread, or a property whose value is not a function. */
87
+ function isDataMember(member) {
88
+ if (member.type === "SpreadElement")
89
+ return true;
90
+ if (member.type !== "Property" || member.method === true || member.kind !== "init")
91
+ return false;
92
+ let value = unwrap(member.value);
93
+ return value !== null && !FUNCTIONS.has(value.type);
94
+ }
95
+ /** `value` without the type assertions and parentheses around it. */
96
+ function unwrap(value) {
97
+ let node = isNode(value) ? value : null;
98
+ while (node !== null && WRAPPERS.has(node.type)) {
99
+ node = isNode(node.expression) ? node.expression : null;
100
+ }
101
+ return node;
102
+ }
103
+ /** The nodes in a list field of a node. */
104
+ function nodes(value) {
105
+ return Array.isArray(value) ? value.filter(isNode) : [];
106
+ }
@@ -1,7 +1,7 @@
1
1
  /**
2
- * The `dependencies` check: import cycles and Clean Architecture breaches against the app-layout
3
- * layers — models stay inward of services and http, resources stay outward of delivery code.
4
- * Oxlint has no project-wide dependency-rule or cycle check for this layout.
2
+ * The `dependencies` check: static import cycles and Clean Architecture breaches against the
3
+ * app-layout layers, so models stay inward of services and http. A `lazy()` mapping or another
4
+ * deferred `import()` loads after startup, so it closes no cycle and breaches no layer.
5
5
  *
6
6
  * @author [Sergio Xalambrí](https://sergiodxa.com)
7
7
  * @copyright Sergio Xalambrí 2026
@@ -1,7 +1,7 @@
1
1
  /**
2
- * The `dependencies` check: import cycles and Clean Architecture breaches against the app-layout
3
- * layers — models stay inward of services and http, resources stay outward of delivery code.
4
- * Oxlint has no project-wide dependency-rule or cycle check for this layout.
2
+ * The `dependencies` check: static import cycles and Clean Architecture breaches against the
3
+ * app-layout layers, so models stay inward of services and http. A `lazy()` mapping or another
4
+ * deferred `import()` loads after startup, so it closes no cycle and breaches no layer.
5
5
  *
6
6
  * @author [Sergio Xalambrí](https://sergiodxa.com)
7
7
  * @copyright Sergio Xalambrí 2026
@@ -1,12 +1,13 @@
1
1
  /**
2
- * The `fan-out` check: no module imports more distinct project modules than
2
+ * The `fan-out` check: no module statically imports more distinct project modules than
3
3
  * `doctor.fanOut.max` (default 15), so one file cannot become a hub that couples half the app.
4
+ * A `lazy()` mapping is a deferred import, so a router grows with its routes freely.
4
5
  *
5
6
  * @author [Sergio Xalambrí](https://sergiodxa.com)
6
7
  * @copyright Sergio Xalambrí 2026
7
8
  */
8
9
  import type { Check } from "./check.js";
9
10
  /**
10
- * Warns on each module whose distinct import targets exceed the configured maximum.
11
+ * Warns on each module whose distinct static import targets exceed the configured maximum.
11
12
  */
12
13
  export declare const fanOutCheck: Check;
@@ -1,6 +1,7 @@
1
1
  /**
2
- * The `fan-out` check: no module imports more distinct project modules than
2
+ * The `fan-out` check: no module statically imports more distinct project modules than
3
3
  * `doctor.fanOut.max` (default 15), so one file cannot become a hub that couples half the app.
4
+ * A `lazy()` mapping is a deferred import, so a router grows with its routes freely.
4
5
  *
5
6
  * @author [Sergio Xalambrí](https://sergiodxa.com)
6
7
  * @copyright Sergio Xalambrí 2026
@@ -8,7 +9,7 @@
8
9
  import { projectGraph } from "../architecture/graph.js";
9
10
  import { passed, skipped } from "./check.js";
10
11
  /**
11
- * Warns on each module whose distinct import targets exceed the configured maximum.
12
+ * Warns on each module whose distinct static import targets exceed the configured maximum.
12
13
  */
13
14
  export const fanOutCheck = {
14
15
  name: "fan-out",
@@ -18,7 +19,7 @@ export const fanOutCheck = {
18
19
  if (graph.modules.length === 0)
19
20
  return skipped("No app source to measure fan-out");
20
21
  let counts = new Map();
21
- for (let edge of graph.edges) {
22
+ for (let edge of graph.edges.filter((candidate) => !candidate.deferred)) {
22
23
  let set = counts.get(edge.from) ?? new Set();
23
24
  set.add(edge.to);
24
25
  counts.set(edge.from, set);
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The `fetch-param` check: code calls the global `fetch`, and tests intercept it with MSW. A
3
+ * `typeof fetch` parameter or option threads a second way to reach the network through every
4
+ * caller, and lets a test pass against a stub that answers differently from the real client.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { SourceFinding, SourceRule } from "./source-rule.js";
10
+ /** Every `typeof fetch` type in app code, the shape an injected fetch is declared with. */
11
+ export declare const FETCH_PARAM_RULE: SourceRule;
12
+ /** Warns on each `typeof fetch` in app code. */
13
+ export declare const fetchParamCheck: import("./check.js").Check;
14
+ /** Each `typeof fetch` type query in `source`. */
15
+ export declare function findFetchParams(file: string, source: string): SourceFinding[];
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The `fetch-param` check: code calls the global `fetch`, and tests intercept it with MSW. A
3
+ * `typeof fetch` parameter or option threads a second way to reach the network through every
4
+ * caller, and lets a test pass against a stub that answers differently from the real client.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import { sourceCheck } from "./source-rule.js";
10
+ import { isNode, lineAt, parseModule, walk } from "./syntax.js";
11
+ /** Every `typeof fetch` type in app code, the shape an injected fetch is declared with. */
12
+ export const FETCH_PARAM_RULE = {
13
+ name: "fetch-param",
14
+ tests: false,
15
+ find: findFetchParams,
16
+ passed: "App code calls the global fetch",
17
+ noun: ["injected fetch", "injected fetches"],
18
+ fix: "Call the global fetch directly and mock it in tests with MSW",
19
+ };
20
+ /** Warns on each `typeof fetch` in app code. */
21
+ export const fetchParamCheck = sourceCheck(FETCH_PARAM_RULE);
22
+ /** Each `typeof fetch` type query in `source`. */
23
+ export function findFetchParams(file, source) {
24
+ let parsed = parseModule(file, source);
25
+ if (parsed === null)
26
+ return [];
27
+ let findings = [];
28
+ walk(parsed.program, (node) => {
29
+ if (node.type !== "TSTypeQuery")
30
+ return;
31
+ let name = node.exprName;
32
+ if (!isNode(name) || name.type !== "Identifier" || name.name !== "fetch")
33
+ return;
34
+ findings.push({ line: lineAt(source, node.start), message: "typeof fetch" });
35
+ });
36
+ return findings;
37
+ }
@@ -10,5 +10,7 @@
10
10
  * lists nothing.
11
11
  */
12
12
  export declare function listFiles(root: string, folder: string): Promise<string[]>;
13
+ /** Whether `path` is a module, tests included and declaration files left out. */
14
+ export declare function isModule(path: string): boolean;
13
15
  /** Whether `path` is a module the app runs, its tests and declaration files left out. */
14
16
  export declare function isAppSource(path: string): boolean;
@@ -28,6 +28,10 @@ export async function listFiles(root, folder) {
28
28
  .map((path) => `${folder}/${path}`)
29
29
  .sort();
30
30
  }
31
+ /** Whether `path` is a module, tests included and declaration files left out. */
32
+ export function isModule(path) {
33
+ return SOURCE.test(path) && !/\.d\.[cm]?ts$/.test(path);
34
+ }
31
35
  /** Whether `path` is a module the app runs, its tests and declaration files left out. */
32
36
  export function isAppSource(path) {
33
37
  return SOURCE.test(path) && !NOT_APP_CODE.test(path);
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The `local-const` check: `const` declares module-level constants only, and every binding inside
3
+ * a function or block is `let`. A reader then knows a `const` is shared by the whole module and
4
+ * named for it, and a local binding reads the same whether or not it is reassigned.
5
+ *
6
+ * @author [Sergio Xalambrí](https://sergiodxa.com)
7
+ * @copyright Sergio Xalambrí 2026
8
+ */
9
+ import type { SourceFinding, SourceRule } from "./source-rule.js";
10
+ /** Every `const` below the module's top level, tests included; ambient declarations are left out. */
11
+ export declare const LOCAL_CONST_RULE: SourceRule;
12
+ /** Warns on each `const` declared inside a function or block. */
13
+ export declare const localConstCheck: import("./check.js").Check;
14
+ /** Each `const` declaration nested in a function, class or block of `source`. */
15
+ export declare function findLocalConsts(file: string, source: string): SourceFinding[];