@starci/eslint-canon-be 3.8.20 → 3.9.2

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 (164) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +1 -1
  3. package/runtime/bundle.json +192 -0
  4. package/runtime/engine/by-code-unit.mjs +6 -6
  5. package/runtime/engine/model-config.mjs +98 -76
  6. package/runtime/engine/orca-config.mjs +22 -17
  7. package/runtime/engine/release-config.mjs +22 -18
  8. package/runtime/engine/removed-vocabulary.mjs +21 -20
  9. package/runtime/engine/resources-config.mjs +42 -35
  10. package/runtime/engine/runtime-root.mjs +11 -13
  11. package/runtime/engine/secrets.mjs +170 -102
  12. package/runtime/engine/sonar-config.mjs +16 -13
  13. package/runtime/engine/temp-root.mjs +3 -9
  14. package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
  15. package/runtime/knowledge/hfs/rules.yaml +6 -6
  16. package/runtime/knowledge/hfs/slots.yaml +2 -2
  17. package/runtime/knowledge/sonar-gate.yaml +1 -1
  18. package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
  19. package/runtime/scripts/api/git/cat-file.mjs +0 -1
  20. package/runtime/scripts/api/git/config-get.mjs +1 -2
  21. package/runtime/scripts/api/git/diff.mjs +0 -1
  22. package/runtime/scripts/api/git/lib.mjs +32 -32
  23. package/runtime/scripts/api/git/ls-files.mjs +0 -1
  24. package/runtime/scripts/api/git/ls-tree.mjs +0 -1
  25. package/runtime/scripts/api/git/merge-base.mjs +2 -3
  26. package/runtime/scripts/api/git/remote.mjs +0 -1
  27. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
  28. package/runtime/scripts/api/git/show.mjs +0 -1
  29. package/runtime/scripts/hfs/allows.mjs +37 -38
  30. package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
  31. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
  32. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
  33. package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
  34. package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
  35. package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
  36. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
  37. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
  38. package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
  39. package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
  40. package/runtime/scripts/hfs/architecture/config.mjs +302 -268
  41. package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
  42. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
  43. package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
  44. package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
  45. package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
  46. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
  47. package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
  48. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
  49. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
  50. package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
  51. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
  52. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
  53. package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
  54. package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
  55. package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
  56. package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
  57. package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
  58. package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
  59. package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
  60. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
  61. package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
  62. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
  63. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
  64. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
  65. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
  66. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
  67. package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
  68. package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
  69. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
  70. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
  71. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
  72. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
  73. package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
  74. package/runtime/scripts/hfs/architecture/index.mjs +272 -272
  75. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
  76. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
  77. package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
  78. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
  79. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
  80. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
  81. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
  82. package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
  83. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
  84. package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
  85. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
  86. package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
  87. package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
  88. package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
  89. package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
  90. package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
  91. package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
  92. package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
  93. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
  94. package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
  95. package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
  96. package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
  97. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
  98. package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
  99. package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
  100. package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
  101. package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
  102. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
  103. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
  104. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
  105. package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
  106. package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
  107. package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
  108. package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
  109. package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
  110. package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
  111. package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
  112. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
  113. package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
  114. package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
  115. package/runtime/scripts/hfs/edition-slots.mjs +43 -40
  116. package/runtime/scripts/hfs/linear-text.mjs +20 -20
  117. package/runtime/scripts/hfs/param-names.mjs +6 -11
  118. package/runtime/scripts/hfs/path-findings.mjs +120 -100
  119. package/runtime/scripts/hfs/repo-identity.mjs +55 -42
  120. package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
  121. package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
  122. package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
  123. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
  124. package/runtime/scripts/hfs/rules/read.mjs +19 -15
  125. package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
  126. package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
  127. package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
  128. package/runtime/scripts/hfs/slot-classify.mjs +42 -38
  129. package/runtime/scripts/hfs/slot-errors.mjs +8 -7
  130. package/runtime/scripts/hfs/slot-imports.mjs +70 -63
  131. package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
  132. package/runtime/scripts/hfs/slot-match.mjs +122 -111
  133. package/runtime/scripts/hfs/slot-path.mjs +0 -2
  134. package/runtime/scripts/hfs/slot-required.mjs +65 -59
  135. package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
  136. package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
  137. package/runtime/scripts/hfs/slots.mjs +175 -152
  138. package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
  139. package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
  140. package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
  141. package/runtime/scripts/hfs/view.mjs +38 -40
  142. package/runtime/scripts/lib/dockerfile.mjs +131 -114
  143. package/runtime/scripts/lib/env.mjs +3 -6
  144. package/runtime/scripts/lib/event-contract.mjs +73 -78
  145. package/runtime/scripts/lib/git.mjs +15 -16
  146. package/runtime/scripts/lib/glob.mjs +23 -14
  147. package/runtime/scripts/lib/grammar-lint.mjs +33 -37
  148. package/runtime/scripts/lib/i18n.mjs +32 -35
  149. package/runtime/scripts/lib/in-order.mjs +57 -38
  150. package/runtime/scripts/lib/json-clone.mjs +45 -36
  151. package/runtime/scripts/lib/json.mjs +26 -14
  152. package/runtime/scripts/lib/language.mjs +133 -129
  153. package/runtime/scripts/lib/list.mjs +9 -14
  154. package/runtime/scripts/lib/mutation-fence.mjs +10 -5
  155. package/runtime/scripts/lib/path-key.mjs +53 -38
  156. package/runtime/scripts/lib/read-text.mjs +30 -17
  157. package/runtime/scripts/lib/regex.mjs +1 -2
  158. package/runtime/scripts/lib/same-text.mjs +0 -1
  159. package/runtime/scripts/lib/sops-envelope.mjs +148 -120
  160. package/runtime/scripts/lib/stack-services.mjs +128 -129
  161. package/runtime/scripts/lib/ts-analysis.mjs +28 -26
  162. package/runtime/scripts/lib/ts-ast.mjs +36 -42
  163. package/runtime/scripts/lib/walk.mjs +33 -27
  164. package/runtime/scripts/lib/yaml-cached.mjs +4 -4
@@ -5,7 +5,6 @@ import { revParseQuery } from '../../api/git/rev-parse-query.mjs';
5
5
  import { gitOutputOf } from '../../lib/git.mjs';
6
6
  import { trimTrailingSlashes } from '../trailing-slashes.mjs';
7
7
  import { requiredFileApplies } from '../slot-required.mjs';
8
-
9
8
  /**
10
9
  * HFS check 5: the files and directories the slot manifest requires (knowledge/hfs/slots.yaml `requires`,
11
10
  * `requiredInstances`, `minInstances`, required app kinds) must exist in the repository tree. Everything is read through the
@@ -21,212 +20,218 @@ import { requiredFileApplies } from '../slot-required.mjs';
21
20
  * on disk), else the filesystem without node_modules, .git, dist and .next.
22
21
  */
23
22
  export const REQUIRED_FILE_RULE_IDS = ['FE_ERROR_BOUNDARY_MISSING', 'HFS_REQUIRED_FILE_MISSING'];
24
-
25
23
  const SKIPPED_DIRECTORIES = new Set(['node_modules', '.git', 'dist', '.next']);
26
24
  const ERROR_BOUNDARY_FILE = /^(?:global-error|error|not-found|loading)\.tsx$/u;
27
25
  const ALSO_JUDGED_TIER_NONE = new Set(['fe.app.next']);
28
-
29
26
  function gitFiles(root) {
30
- try {
31
- const run = (call, args) => gitOutputOf(call(args, { cwd: root, maxBuffer: 256 * 1024 * 1024 }));
32
- run(revParseQuery, ['--is-inside-work-tree']);
33
- const deleted = new Set(run(lsFiles, ['--deleted', '-z', '--', '.']).split('\0').filter(Boolean));
34
- return run(lsFiles, ['--cached', '-z', '--', '.']).split('\0').filter(file => file && !deleted.has(file));
35
- } catch {
36
- return null;
37
- }
38
- }
39
-
27
+ try {
28
+ // gitOutputOf threw unless git exited 0, whose stdout is text
29
+ const run = (call, args) => gitOutputOf(call(args, { cwd: root, maxBuffer: 256 * 1024 * 1024 }));
30
+ run(revParseQuery, ['--is-inside-work-tree']);
31
+ const deleted = new Set(run(lsFiles, ['--deleted', '-z', '--', '.']).split('\0').filter(Boolean));
32
+ return run(lsFiles, ['--cached', '-z', '--', '.']).split('\0').filter(file => file && !deleted.has(file));
33
+ }
34
+ catch {
35
+ return null;
36
+ }
37
+ }
40
38
  function diskFiles(root, relative = '') {
41
- const out = [];
42
- let entries;
43
- try { entries = fs.readdirSync(path.join(root, ...relative.split('/').filter(Boolean)), { withFileTypes: true }); } catch { return out; }
44
- for (const entry of entries) {
45
- if (SKIPPED_DIRECTORIES.has(entry.name)) continue;
46
- const child = relative ? `${relative}/${entry.name}` : entry.name;
47
- if (entry.isDirectory()) out.push(...diskFiles(root, child));
48
- else out.push(child);
49
- }
50
- return out;
51
- }
52
-
39
+ const out = [];
40
+ let entries;
41
+ try {
42
+ entries = fs.readdirSync(path.join(root, ...relative.split('/').filter(Boolean)), { withFileTypes: true });
43
+ }
44
+ catch {
45
+ return out;
46
+ }
47
+ for (const entry of entries) {
48
+ if (SKIPPED_DIRECTORIES.has(entry.name))
49
+ continue;
50
+ const child = relative ? `${relative}/${entry.name}` : entry.name;
51
+ if (entry.isDirectory())
52
+ out.push(...diskFiles(root, child));
53
+ else
54
+ out.push(child);
55
+ }
56
+ return out;
57
+ }
53
58
  let runTrees = null;
54
-
55
59
  /** Runs `run` with one tree read per root: every checker of one machine run shares the repository listing instead of spawning git again. */
56
60
  export function withTreeCache(run) {
57
- const outer = runTrees;
58
- runTrees = outer ?? new Map();
59
- try {
60
- return run();
61
- } finally {
62
- runTrees = outer;
63
- }
64
- }
65
-
61
+ const outer = runTrees;
62
+ runTrees = outer ?? new Map();
63
+ try {
64
+ return run();
65
+ }
66
+ finally {
67
+ runTrees = outer;
68
+ }
69
+ }
66
70
  function readTree(root) {
67
- const list = gitFiles(root) ?? diskFiles(root);
68
- const files = new Set(list);
69
- const directories = new Set();
70
- for (const file of list) {
71
- const parts = file.split('/');
72
- for (let i = 1; i < parts.length; i += 1) directories.add(parts.slice(0, i).join('/'));
73
- }
74
- return { files, directories };
75
- }
76
-
71
+ const list = gitFiles(root) ?? diskFiles(root);
72
+ const files = new Set(list);
73
+ const directories = new Set();
74
+ for (const file of list) {
75
+ const parts = file.split('/');
76
+ for (let i = 1; i < parts.length; i += 1)
77
+ directories.add(parts.slice(0, i).join('/'));
78
+ }
79
+ return { files, directories };
80
+ }
77
81
  /** The repository tree as file and directory sets over posix relatives. */
78
82
  export function treeOf(root) {
79
- if (!runTrees) return readTree(root);
80
- if (!runTrees.has(root)) runTrees.set(root, readTree(root));
81
- return runTrees.get(root);
83
+ if (!runTrees)
84
+ return readTree(root);
85
+ let tree = runTrees.get(root);
86
+ if (!tree) {
87
+ tree = readTree(root);
88
+ runTrees.set(root, tree);
89
+ }
90
+ return tree;
82
91
  }
83
-
84
92
  /**
85
93
  * The prelude every tree-walking architecture checker shares: the input's config/graph/context, the compiler,
86
94
  * the slot resolver and the tracked repository tree.
87
95
  */
88
96
  export function checkerScope({ config, graph, context }) {
89
- return { config, graph, context, ts: context.ts, resolver: graph.resolver, tree: treeOf(config.root) };
97
+ return { config, graph, context, ts: context.ts, resolver: graph.resolver, tree: treeOf(config.root) };
90
98
  }
91
-
92
- const rootOfTarget = target => {
93
- if (target.endsWith('/')) return trimTrailingSlashes(target);
94
- const parent = path.posix.dirname(target);
95
- return parent === '.' ? '' : parent;
99
+ const rootOfTarget = (target) => {
100
+ if (target.endsWith('/'))
101
+ return trimTrailingSlashes(target);
102
+ const parent = path.posix.dirname(target);
103
+ return parent === '.' ? '' : parent;
96
104
  };
97
-
98
105
  function ruleFor(slotId, target, rootExists) {
99
- if (slotId === 'fe.app.next' && rootExists && ERROR_BOUNDARY_FILE.test(path.posix.basename(trimTrailingSlashes(target)))) return 'FE_ERROR_BOUNDARY_MISSING';
100
- return 'HFS_REQUIRED_FILE_MISSING';
106
+ if (slotId === 'fe.app.next' && rootExists && ERROR_BOUNDARY_FILE.test(path.posix.basename(trimTrailingSlashes(target))))
107
+ return 'FE_ERROR_BOUNDARY_MISSING';
108
+ return 'HFS_REQUIRED_FILE_MISSING';
101
109
  }
102
-
103
110
  function slotIsJudged(resolver, slotId) {
104
- const slot = resolver.slot(slotId);
105
- return Boolean(slot) && (slot.tier !== 'none' || ALSO_JUDGED_TIER_NONE.has(slotId));
111
+ const slot = resolver.slot(slotId);
112
+ return slot != null && (slot.tier !== 'none' || ALSO_JUDGED_TIER_NONE.has(slotId));
106
113
  }
107
-
108
114
  function addRequirement(requirements, slot, target, root) {
109
- if (!requirements.has(target)) requirements.set(target, { slot, target, root });
115
+ if (!requirements.has(target))
116
+ requirements.set(target, { slot, target, root });
110
117
  }
111
-
112
118
  function collectDeclaredRequirements(declared, requirements, instances, judged) {
113
- const currentRoot = new Map();
114
- for (const item of declared.paths) {
115
- if (!judged(item.slot)) continue;
116
- if (item.via !== 'requires') {
117
- const root = rootOfTarget(item.path);
118
- currentRoot.set(item.slot, root);
119
- instances.add(`${item.slot}|${root}`);
120
- addRequirement(requirements, item.slot, item.path, root);
121
- } else {
122
- addRequirement(requirements, item.slot, item.path, currentRoot.get(item.slot) ?? '');
119
+ const currentRoot = new Map();
120
+ for (const item of declared.paths) {
121
+ if (!judged(item.slot))
122
+ continue;
123
+ if (item.via !== 'requires') {
124
+ const root = rootOfTarget(item.path);
125
+ currentRoot.set(item.slot, root);
126
+ instances.add(`${item.slot}|${root}`);
127
+ addRequirement(requirements, item.slot, item.path, root);
128
+ }
129
+ else {
130
+ addRequirement(requirements, item.slot, item.path, currentRoot.get(item.slot) ?? '');
131
+ }
123
132
  }
124
- }
125
133
  }
126
-
127
134
  function addInstanceRequirements(resolver, classified, representative, requirements, instances, seenInstances, judged) {
128
- const { slot: slotId, root } = classified;
129
- const key = `${slotId}|${root}`;
130
- if (seenInstances.has(key) || !judged(slotId)) return;
131
- seenInstances.add(key);
132
- instances.add(key);
133
- for (const target of resolver.requiredFiles(representative)) addRequirement(requirements, slotId, target, root);
134
- }
135
-
135
+ const { slot: slotId, root } = classified;
136
+ const key = `${slotId}|${root}`;
137
+ if (seenInstances.has(key) || !judged(slotId))
138
+ return;
139
+ seenInstances.add(key);
140
+ instances.add(key);
141
+ for (const target of resolver.requiredFiles(representative))
142
+ addRequirement(requirements, slotId, target, root);
143
+ }
136
144
  function addOwnerRequirements(resolver, owner, requirements, instances, seenInstances, judged) {
137
- const key = `${owner.slot}|${owner.root}`;
138
- if (seenInstances.has(key) || !judged(owner.slot) || !resolver.slotEnabled(resolver.slot(owner.slot))) return;
139
- seenInstances.add(key);
140
- instances.add(key);
141
- for (const entry of resolver.slot(owner.slot).requires ?? []) {
142
- const rooted = entry.startsWith('/');
143
- const filled = (rooted ? entry.slice(1) : entry).replace(/<([A-Za-z][A-Za-z0-9-]*)>/g, (whole, name) => owner.bindings[name] ?? whole);
144
- addRequirement(requirements, owner.slot, rooted || !owner.root ? filled : `${owner.root}/${filled}`, owner.root);
145
- }
146
- }
147
-
145
+ const key = `${owner.slot}|${owner.root}`;
146
+ const ownerSlot = resolver.slot(owner.slot);
147
+ // judged() already answered false for a slot the resolver does not know
148
+ if (seenInstances.has(key) || !judged(owner.slot) || !ownerSlot || !resolver.slotEnabled(ownerSlot))
149
+ return;
150
+ seenInstances.add(key);
151
+ instances.add(key);
152
+ for (const entry of ownerSlot.requires ?? []) {
153
+ const rooted = entry.startsWith('/');
154
+ const filled = (rooted ? entry.slice(1) : entry).replace(/<([A-Za-z][A-Za-z0-9-]*)>/g, (whole, name) => owner.bindings[name] ?? whole);
155
+ addRequirement(requirements, owner.slot, rooted || !owner.root ? filled : `${owner.root}/${filled}`, owner.root);
156
+ }
157
+ }
148
158
  function noteInstance(found, slotId, root) {
149
- if (!found.has(slotId)) found.set(slotId, new Set());
150
- found.get(slotId).add(root);
159
+ let roots = found.get(slotId);
160
+ if (!roots) {
161
+ roots = new Set();
162
+ found.set(slotId, roots);
163
+ }
164
+ roots.add(root);
151
165
  }
152
-
153
166
  function collectTreeRequirements(tree, resolver, requirements, instances, judged) {
154
- const seenInstances = new Set();
155
- const found = new Map(); // slot -> Set(root) of instances seen while walking
156
- for (const file of tree.files) {
157
- const classified = resolver.classifyPath(file);
158
- if (classified.status === 'owned' && classified.slot) {
159
- noteInstance(found, classified.slot, classified.root);
160
- addInstanceRequirements(resolver, classified, file, requirements, instances, seenInstances, judged);
167
+ const seenInstances = new Set();
168
+ const found = new Map(); // slot -> Set(root) of instances seen while walking
169
+ for (const file of tree.files) {
170
+ const classified = resolver.classifyPath(file);
171
+ if (classified.status === 'owned' && classified.slot) {
172
+ noteInstance(found, classified.slot, classified.root);
173
+ addInstanceRequirements(resolver, { slot: classified.slot, root: classified.root }, file, requirements, instances, seenInstances, judged);
174
+ }
175
+ const owner = resolver.ownerOf(file);
176
+ if (owner) {
177
+ noteInstance(found, owner.slot, owner.root);
178
+ // an owner root may classify to a more specific slot (modules/i18n) or a nested one, so expand the owner slot's own requires
179
+ addOwnerRequirements(resolver, owner, requirements, instances, seenInstances, judged);
180
+ }
161
181
  }
162
- const owner = resolver.ownerOf(file);
163
- if (owner) {
164
- noteInstance(found, owner.slot, owner.root);
165
- // an owner root may classify to a more specific slot (modules/i18n) or a nested one, so expand the owner slot's own requires
166
- addOwnerRequirements(resolver, owner, requirements, instances, seenInstances, judged);
167
- }
168
- }
169
- return found;
182
+ return found;
170
183
  }
171
-
172
184
  function requirementExists(tree, target) {
173
- return target.endsWith('/') ? tree.directories.has(trimTrailingSlashes(target)) : tree.files.has(target);
185
+ return target.endsWith('/') ? tree.directories.has(trimTrailingSlashes(target)) : tree.files.has(target);
174
186
  }
175
-
176
187
  function reportMissingRequirement(requirement, tree, report) {
177
- if (requirementExists(tree, requirement.target) || !requiredFileApplies(requirement.slot, requirement.target, tree.files)) return;
178
- const rootExists = !requirement.root || tree.directories.has(requirement.root);
179
- if (!rootExists) {
180
- report(ruleFor(requirement.slot, requirement.target, false), requirement.root, requirement.slot, requirement.root, { kind: 'directory' },
181
- `Required directory ${requirement.root} (slot ${requirement.slot}) does not exist; the slot manifest requires it, along with what it holds.`);
182
- return;
183
- }
184
- const kind = requirement.target.endsWith('/') ? 'directory' : 'file';
185
- const rootNote = requirement.root ? ` (${requirement.root})` : '';
186
- report(ruleFor(requirement.slot, requirement.target, true), trimTrailingSlashes(requirement.target), requirement.slot, requirement.root, { kind },
187
- `Required ${kind} ${trimTrailingSlashes(requirement.target)} is missing; slot ${requirement.slot} requires it in every instance${rootNote}.`);
188
- }
189
-
188
+ if (requirementExists(tree, requirement.target) || !requiredFileApplies(requirement.slot, requirement.target, tree.files))
189
+ return;
190
+ const rootExists = !requirement.root || tree.directories.has(requirement.root);
191
+ if (!rootExists) {
192
+ report(ruleFor(requirement.slot, requirement.target, false), requirement.root, requirement.slot, requirement.root, { kind: 'directory' }, `Required directory ${requirement.root} (slot ${requirement.slot}) does not exist; the slot manifest requires it, along with what it holds.`);
193
+ return;
194
+ }
195
+ const kind = requirement.target.endsWith('/') ? 'directory' : 'file';
196
+ const rootNote = requirement.root ? ` (${requirement.root})` : '';
197
+ report(ruleFor(requirement.slot, requirement.target, true), trimTrailingSlashes(requirement.target), requirement.slot, requirement.root, { kind }, `Required ${kind} ${trimTrailingSlashes(requirement.target)} is missing; slot ${requirement.slot} requires it in every instance${rootNote}.`);
198
+ }
190
199
  function reportMissingRequirements(requirements, tree, report) {
191
- for (const requirement of requirements.values()) reportMissingRequirement(requirement, tree, report);
200
+ for (const requirement of requirements.values())
201
+ reportMissingRequirement(requirement, tree, report);
192
202
  }
193
-
194
203
  function reportMinimumRequirements(minimums, resolver, judged, found, report) {
195
- for (const minimum of minimums) {
196
- if (!judged(minimum.slot)) continue;
197
- const count = minimum.appKind !== undefined
198
- ? resolver.repo.apps.filter(app => app.kind === minimum.appKind).length
199
- : (found.get(minimum.slot)?.size ?? 0);
200
- if (count >= minimum.min) continue;
201
- const appKindNote = minimum.appKind ? ' (an app of kind ' + minimum.appKind + ' declared in hfs.json)' : '';
202
- report('HFS_REQUIRED_FILE_MISSING', 'hfs.json', minimum.slot, '', { minimum: minimum.min, found: count },
203
- `Slot ${minimum.slot} needs at least ${minimum.min} instance${minimum.min === 1 ? '' : 's'}${appKindNote}; the repository has ${count}.`);
204
- }
205
- }
206
-
204
+ for (const minimum of minimums) {
205
+ if (!judged(minimum.slot))
206
+ continue;
207
+ const count = minimum.appKind !== undefined
208
+ ? resolver.repo.apps.filter(app => app.kind === minimum.appKind).length
209
+ : (found.get(minimum.slot)?.size ?? 0);
210
+ if (count >= minimum.min)
211
+ continue;
212
+ const appKindNote = minimum.appKind ? ' (an app of kind ' + minimum.appKind + ' declared in hfs.json)' : '';
213
+ report('HFS_REQUIRED_FILE_MISSING', 'hfs.json', minimum.slot, '', { minimum: minimum.min, found: count }, `Slot ${minimum.slot} needs at least ${minimum.min} instance${minimum.min === 1 ? '' : 's'}${appKindNote}; the repository has ${count}.`);
214
+ }
215
+ }
207
216
  export function checkRequiredFiles({ config, graph }) {
208
- const resolver = graph?.resolver ?? config.hfs;
209
- const tree = treeOf(config.root);
210
- const judged = slotId => slotIsJudged(resolver, slotId);
211
-
212
- const requirements = new Map(); // repository-relative target (as written, dirs end with /) -> {slot, target, root}
213
- const instances = new Set();
214
- const declared = resolver.requiredPaths();
215
- collectDeclaredRequirements(declared, requirements, instances, judged);
216
-
217
- const found = collectTreeRequirements(tree, resolver, requirements, instances, judged);
218
-
219
- const violations = [];
220
- const reported = new Set();
221
- const report = (ruleId, target, slotId, root, extra, message) => {
222
- const key = `${ruleId}|${target}`;
223
- if (reported.has(key)) return;
224
- reported.add(key);
225
- violations.push({ ruleId, path: target, slot: slotId, ...(root ? { root } : {}), ...extra, message });
226
- };
227
- reportMissingRequirements(requirements, tree, report);
228
-
229
- reportMinimumRequirements(declared.minimums, resolver, judged, found, report);
230
-
231
- return { violations, coverage: { status: 'checked', instances: instances.size, requirements: requirements.size, missing: violations.length } };
217
+ const resolver = graph?.resolver ?? config.hfs;
218
+ const tree = treeOf(config.root);
219
+ const judged = slotId => slotIsJudged(resolver, slotId);
220
+ const requirements = new Map(); // repository-relative target (as written, dirs end with /) -> {slot, target, root}
221
+ const instances = new Set();
222
+ const declared = resolver.requiredPaths();
223
+ collectDeclaredRequirements(declared, requirements, instances, judged);
224
+ const found = collectTreeRequirements(tree, resolver, requirements, instances, judged);
225
+ const violations = [];
226
+ const reported = new Set();
227
+ const report = (ruleId, target, slotId, root, extra, message) => {
228
+ const key = `${ruleId}|${target}`;
229
+ if (reported.has(key))
230
+ return;
231
+ reported.add(key);
232
+ violations.push({ ruleId, path: target, slot: slotId, ...(root ? { root } : {}), ...extra, message });
233
+ };
234
+ reportMissingRequirements(requirements, tree, report);
235
+ reportMinimumRequirements(declared.minimums, resolver, judged, found, report);
236
+ return { violations, coverage: { status: 'checked', instances: instances.size, requirements: requirements.size, missing: violations.length } };
232
237
  }
@@ -1,6 +1,5 @@
1
1
  import path from 'node:path';
2
2
  import { machineKit } from './machine-ast.mjs';
3
-
4
3
  /**
5
4
  * R54 `route-files-thin` (FE_ROUTE_FILES_THIN, knowledge/hfs/README.md 6.2). A route file only mounts an owner: it holds no
6
5
  * inline component, no drawing and no hook. For every file of the route slot (fe.route, apps/<app>/src/app) named
@@ -16,110 +15,119 @@ import { machineKit } from './machine-ast.mjs';
16
15
  * FE_ROUTE_CLIENT_BOUNDARY and FE_ROUTE_CLIENT_HOOK checks of frontend.mjs and are not judged a second time here.
17
16
  */
18
17
  export const ROUTE_FILES_THIN_RULE_IDS = ['FE_ROUTE_FILES_THIN'];
19
-
20
18
  const RULE = 'FE_ROUTE_FILES_THIN';
21
19
  const ROUTE_SLOT = 'fe.route';
22
20
  const MOUNTING_ROUTES = new Set(['layout', 'template', 'loading', 'not-found']);
23
21
  const HOOK_ROUTES = new Set([...MOUNTING_ROUTES, 'page']);
24
22
  const HOOK_NAME = /^use[A-Z0-9]/u;
25
23
  const HOOKS_SLOT = 'fe.hooks';
26
-
27
24
  /** The client providers (fe.components.providers) wrap the mounted owner like a package shell; they are not a second owner. */
28
25
  const PROVIDERS_SLOT = 'fe.components.providers';
29
- const isFeatureOwner = target => target?.tier === 'feature' && target.slot !== PROVIDERS_SLOT;
26
+ const isFeatureOwner = (target) => target?.tier === 'feature' && target.slot !== PROVIDERS_SLOT;
30
27
  const isFunction = (ts, node) => ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node);
31
28
  const jsxOf = (ts, node) => ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node) || ts.isJsxFragment(node);
32
-
33
29
  function tagOf(ts, node) {
34
- if (ts.isJsxElement(node)) return node.openingElement.tagName;
35
- if (ts.isJsxSelfClosingElement(node)) return node.tagName;
36
- return null;
30
+ if (ts.isJsxElement(node))
31
+ return node.openingElement.tagName;
32
+ if (ts.isJsxSelfClosingElement(node))
33
+ return node.tagName;
34
+ return null;
37
35
  }
38
-
39
36
  function addExportAssignmentDefaults(ts, statement, kit, checker, defaults) {
40
- const target = statement.expression;
41
- if (!ts.isIdentifier(target)) { defaults.add(target); return; }
42
- for (const declaration of kit.declarationsOf(checker, target)) defaults.add(ts.isVariableDeclaration(declaration) ? declaration.initializer ?? declaration : declaration);
37
+ const target = statement.expression;
38
+ if (!ts.isIdentifier(target)) {
39
+ defaults.add(target);
40
+ return;
41
+ }
42
+ for (const declaration of kit.declarationsOf(checker, target))
43
+ defaults.add(ts.isVariableDeclaration(declaration) ? declaration.initializer ?? declaration : declaration);
43
44
  }
44
-
45
45
  function routeDefaults(ts, file, kit, checker) {
46
- const defaults = new Set();
47
- for (const statement of file.sourceFile.statements) {
48
- if (ts.isFunctionDeclaration(statement) && statement.modifiers?.some(item => item.kind === ts.SyntaxKind.DefaultKeyword)) defaults.add(statement);
49
- if (ts.isExportAssignment(statement) && !statement.isExportEquals) addExportAssignmentDefaults(ts, statement, kit, checker, defaults);
50
- }
51
- return defaults;
46
+ const defaults = new Set();
47
+ for (const statement of file.sourceFile.statements) {
48
+ if (ts.isFunctionDeclaration(statement) && statement.modifiers?.some((item) => item.kind === ts.SyntaxKind.DefaultKeyword))
49
+ defaults.add(statement);
50
+ if (ts.isExportAssignment(statement) && !statement.isExportEquals)
51
+ addExportAssignmentDefaults(ts, statement, kit, checker, defaults);
52
+ }
53
+ return defaults;
52
54
  }
53
-
54
55
  /** True when the function contains JSX that is not inside a nested function. */
55
56
  function drawsDirectly(ts, fn) {
56
- let found = false;
57
- const visit = node => {
58
- if (found) return;
59
- if (node !== fn && isFunction(ts, node)) return;
60
- if (jsxOf(ts, node)) { found = true; return; }
61
- ts.forEachChild(node, visit);
62
- };
63
- visit(fn);
64
- return found;
57
+ let found = false;
58
+ const visit = (node) => {
59
+ if (found)
60
+ return;
61
+ if (node !== fn && isFunction(ts, node))
62
+ return;
63
+ if (jsxOf(ts, node)) {
64
+ found = true;
65
+ return;
66
+ }
67
+ ts.forEachChild(node, visit);
68
+ };
69
+ visit(fn);
70
+ return found;
65
71
  }
66
-
67
72
  function reportRoute(violations, kit, file, stem, node, message, extra = {}) {
68
- violations.push({ ruleId: RULE, path: file.rel, ...kit.at(file.rel, file.sourceFile, node), message, route: stem, ...extra });
73
+ violations.push({ ruleId: RULE, ...kit.at(file.rel, file.sourceFile, node), message, route: stem, ...extra });
69
74
  }
70
-
71
75
  function inspectMountingTag(tag, { graph, kit, ts, file, stem, checker, violations, state }) {
72
- if (ts.isIdentifier(tag) && /^[a-z]/u.test(tag.text)) {
73
- reportRoute(violations, kit, file, stem, tag, `<${tag.text}> is drawing in a ${stem} route file; a route file mounts one feature and draws nothing. Move the markup into the feature.`);
74
- } else if (kit.declarationsOf(checker, ts.isPropertyAccessExpression(tag) ? tag.name : tag).some(declaration => isFeatureOwner(graph.files.get(kit.graphPath(declaration) ?? '')))) {
75
- state.owners += 1;
76
- }
76
+ if (ts.isIdentifier(tag) && /^[a-z]/u.test(tag.text)) {
77
+ reportRoute(violations, kit, file, stem, tag, `<${tag.text}> is drawing in a ${stem} route file; a route file mounts one feature and draws nothing. Move the markup into the feature.`);
78
+ }
79
+ else if (kit.declarationsOf(checker, ts.isPropertyAccessExpression(tag) ? tag.name : tag).some(declaration => isFeatureOwner(graph.files.get(kit.graphPath(declaration) ?? '')))) {
80
+ state.owners += 1;
81
+ }
77
82
  }
78
-
79
83
  function inspectHookCall(node, { graph, kit, ts, file, stem, checker, violations }) {
80
- const callee = ts.isIdentifier(node.expression) ? node.expression : null;
81
- if (!callee || !HOOK_NAME.test(callee.text)) return;
82
- const binding = kit.importBinding(checker, callee);
83
- const inHooks = kit.declarationsOf(checker, callee).some(declaration => graph.files.get(kit.graphPath(declaration) ?? '')?.slot === HOOKS_SLOT);
84
- if (binding || inHooks) reportRoute(violations, kit, file, stem, callee, `${callee.text} is a hook called in a ${stem} route file; a route file is a server adapter and holds no hook. Read the data in the feature it mounts.`);
84
+ const callee = ts.isIdentifier(node.expression) ? node.expression : null;
85
+ if (!callee || !HOOK_NAME.test(callee.text))
86
+ return;
87
+ const binding = kit.importBinding(checker, callee);
88
+ const inHooks = kit.declarationsOf(checker, callee).some(declaration => graph.files.get(kit.graphPath(declaration) ?? '')?.slot === HOOKS_SLOT);
89
+ if (binding || inHooks)
90
+ reportRoute(violations, kit, file, stem, callee, `${callee.text} is a hook called in a ${stem} route file; a route file is a server adapter and holds no hook. Read the data in the feature it mounts.`);
85
91
  }
86
-
87
92
  function inspectRouteNode(node, context) {
88
- const { kit, ts, file, stem, mounting, defaults, violations, state } = context;
89
- if (jsxOf(ts, node)) state.hasJsx = true;
90
- const tag = tagOf(ts, node);
91
- if (mounting && tag) inspectMountingTag(tag, context);
92
- if (mounting && isFunction(ts, node) && !defaults.has(node) && drawsDirectly(ts, node)) {
93
- reportRoute(violations, kit, file, stem, node, `A function other than the default export draws JSX in a ${stem} route file; that is an inline component. Move it into the feature the route mounts.`);
94
- }
95
- if (ts.isCallExpression(node)) inspectHookCall(node, context);
96
- return true;
93
+ const { kit, ts, file, stem, mounting, defaults, violations, state } = context;
94
+ if (jsxOf(ts, node))
95
+ state.hasJsx = true;
96
+ const tag = tagOf(ts, node);
97
+ if (mounting && tag)
98
+ inspectMountingTag(tag, context);
99
+ if (mounting && isFunction(ts, node) && !defaults.has(node) && drawsDirectly(ts, node)) {
100
+ reportRoute(violations, kit, file, stem, node, `A function other than the default export draws JSX in a ${stem} route file; that is an inline component. Move it into the feature the route mounts.`);
101
+ }
102
+ if (ts.isCallExpression(node))
103
+ inspectHookCall(node, context);
104
+ return true;
97
105
  }
98
-
99
106
  function inspectRouteFile(graph, kit, file, stem, violations) {
100
- const { ts } = kit;
101
- const mounting = MOUNTING_ROUTES.has(stem);
102
- const checker = kit.checkerOf(file.sourceFile);
103
- const defaults = routeDefaults(ts, file, kit, checker);
104
- const state = { hasJsx: false, owners: 0 };
105
- kit.walk(file.sourceFile, node => inspectRouteNode(node, { graph, kit, ts, file, stem, mounting, checker, defaults, violations, state }));
106
- if (mounting && state.hasJsx && state.owners !== 1) {
107
- violations.push({ ruleId: RULE, path: file.rel, line: 1, column: 1, route: stem, owners: state.owners,
108
- message: `${file.rel} mounts ${state.owners} feature owners; a ${stem} route file mounts exactly one feature (a layouts- or pages-tier component of the app), optionally inside a package shell.` });
109
- }
107
+ const { ts } = kit;
108
+ const mounting = MOUNTING_ROUTES.has(stem);
109
+ const checker = kit.checkerOf(file.sourceFile);
110
+ const defaults = routeDefaults(ts, file, kit, checker);
111
+ const state = { hasJsx: false, owners: 0 };
112
+ kit.walk(file.sourceFile, (node) => inspectRouteNode(node, { graph, kit, ts, file, stem, mounting, checker, defaults, violations, state }));
113
+ if (mounting && state.hasJsx && state.owners !== 1) {
114
+ violations.push({ ruleId: RULE, path: file.rel, line: 1, column: 1, route: stem, owners: state.owners,
115
+ message: `${file.rel} mounts ${state.owners} feature owners; a ${stem} route file mounts exactly one feature (a layouts- or pages-tier component of the app), optionally inside a package shell.` });
116
+ }
110
117
  }
111
-
112
118
  export function checkRouteFilesThin(input) {
113
- const { graph } = input;
114
- const kit = machineKit(input);
115
- const violations = [];
116
- let routes = 0;
117
- for (const file of graph.files.values()) {
118
- if (file.slot !== ROUTE_SLOT) continue;
119
- const stem = path.posix.basename(file.rel).replace(/\.[cm]?[jt]sx?$/u, '');
120
- if (!HOOK_ROUTES.has(stem)) continue;
121
- routes += 1;
122
- inspectRouteFile(graph, kit, file, stem, violations);
123
- }
124
- return { violations, coverage: { status: 'checked', routes } };
119
+ const { graph } = input;
120
+ const kit = machineKit(input);
121
+ const violations = [];
122
+ let routes = 0;
123
+ for (const file of graph.files.values()) {
124
+ if (file.slot !== ROUTE_SLOT)
125
+ continue;
126
+ const stem = path.posix.basename(file.rel).replace(/\.[cm]?[jt]sx?$/u, '');
127
+ if (!HOOK_ROUTES.has(stem))
128
+ continue;
129
+ routes += 1;
130
+ inspectRouteFile(graph, kit, file, stem, violations);
131
+ }
132
+ return { violations, coverage: { status: 'checked', routes } };
125
133
  }