@starci/eslint-canon-be 3.8.19 → 3.9.0

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 +12 -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
@@ -1,313 +1,330 @@
1
- /**
2
- * HFS check 3, reachability (knowledge/hfs/slots.yaml rules BE_FEATURE_NOT_COMPOSED, FE_OWNER_REACHABLE):
3
- * BE every feature owner (be.feature) and every capability owner (be.domain, be.integrations, be.platform) must be
4
- * composed into an app root: reachable from an app entry file (apps/<app>/src, the be.app.* owners) through runtime
5
- * imports and re-exports. A type-only import composes nothing. A module reached only through a reached module
6
- * is reached. An owner no root reaches is dead code: no process ever serves it.
7
- * FE every page/layout/overlay feature (fe.feature) must be mounted: reachable by runtime imports from a file of
8
- * its app's route tree (apps/<app>/src/app, slot fe.route); and every string-literal href/redirect/router target
9
- * must resolve to a route of that app (page.tsx / route.ts under src/app, route groups and [locale] transparent).
10
- * Only literals are judged: a computed href is counted as skipped, never guessed at.
11
- */
12
1
  import { byCodeUnit } from '../../lib/list.mjs';
13
-
14
2
  export const REACHABILITY_RULE_IDS = ['BE_FEATURE_NOT_COMPOSED', 'FE_OWNER_REACHABLE', 'FE_HREF_RESOLVES'];
15
-
16
3
  const BE_CAPABILITY_SLOTS = new Set(['be.domain', 'be.integrations', 'be.platform', 'be.platform.logging']);
17
4
  const TEST_FILE = /(?:\.(?:spec|test|stories|e2e-spec)\.[cm]?[jt]sx?$)|(?:(?:^|\/)__tests__\/)/;
18
5
  const ROUTE_FILE = /^(?:page|route)\.(?:tsx|ts|jsx|js)$/;
19
6
  const PLACEHOLDER = '\u0000';
20
7
  const REGEX_SPECIALS = /[.*+?^${}()|[\]\\]/g;
21
- const ESCAPE_MATCH = String.raw`\$&`;
22
-
8
+ const ESCAPE_MATCH = String.raw `\$&`;
23
9
  /** Breadth-first reach over runtime, non-type-only edges (re-exports included) from `roots`. */
24
10
  function reachFrom(graph, roots) {
25
- const forward = new Map();
26
- for (const edge of graph.edges) {
27
- if (!edge.runtime) continue;
28
- if (!forward.has(edge.from)) forward.set(edge.from, []);
29
- forward.get(edge.from).push(edge.to);
30
- }
31
- const reached = new Set(roots);
32
- const queue = [...roots];
33
- while (queue.length) {
34
- for (const next of forward.get(queue.shift()) ?? []) {
35
- if (reached.has(next)) continue;
36
- reached.add(next);
37
- queue.push(next);
11
+ const forward = new Map();
12
+ for (const edge of graph.edges) {
13
+ if (!edge.runtime)
14
+ continue;
15
+ if (!forward.has(edge.from))
16
+ forward.set(edge.from, []);
17
+ forward.get(edge.from)?.push(edge.to);
38
18
  }
39
- }
40
- return reached;
19
+ const reached = new Set(roots);
20
+ const queue = [...roots];
21
+ while (queue.length) {
22
+ for (const next of forward.get(queue.shift()) ?? []) {
23
+ if (reached.has(next))
24
+ continue;
25
+ reached.add(next);
26
+ queue.push(next);
27
+ }
28
+ }
29
+ return reached;
41
30
  }
42
-
43
31
  function ownerFiles(graph) {
44
- const byUnit = new Map();
45
- for (const [rel, node] of graph.files) {
46
- if (!node.owner) continue;
47
- const key = `${node.owner.slot}:${node.owner.root}`;
48
- if (!byUnit.has(key)) byUnit.set(key, []);
49
- byUnit.get(key).push(rel);
50
- }
51
- return byUnit;
32
+ const byUnit = new Map();
33
+ for (const [rel, node] of graph.files) {
34
+ if (!node.owner)
35
+ continue;
36
+ const key = `${node.owner.slot}:${node.owner.root}`;
37
+ if (!byUnit.has(key))
38
+ byUnit.set(key, []);
39
+ byUnit.get(key)?.push(rel);
40
+ }
41
+ return byUnit;
52
42
  }
53
-
54
43
  /** The file that stands for an owner in a finding: its public entry when the graph holds one, else its first file. */
55
44
  function entryOf(root, files) {
56
- const base = root.replace(/\/$/, '');
57
- const entry = new RegExp(String.raw`^${base.replace(REGEX_SPECIALS, ESCAPE_MATCH)}/index\.[tj]sx?$`);
58
- return files.find(rel => entry.test(rel)) ?? [...files].sort(byCodeUnit)[0];
45
+ const base = root.replace(/\/$/, '');
46
+ const entry = new RegExp(String.raw `^${base.replace(REGEX_SPECIALS, ESCAPE_MATCH)}/index\.[tj]sx?$`);
47
+ return files.find(rel => entry.test(rel)) ?? [...files].sort(byCodeUnit)[0];
59
48
  }
60
-
61
49
  function backendAppRoots(byUnit) {
62
- const rootFiles = [];
63
- const appRoots = new Set();
64
- for (const [key, files] of byUnit) {
65
- const slot = key.slice(0, key.indexOf(':'));
66
- if (!slot.startsWith('be.app.')) continue;
67
- appRoots.add(key.slice(key.indexOf(':') + 1));
68
- for (const rel of files) if (!TEST_FILE.test(rel)) rootFiles.push(rel);
69
- }
70
- return { rootFiles, roots: [...appRoots].sort(byCodeUnit) };
50
+ const rootFiles = [];
51
+ const appRoots = new Set();
52
+ for (const [key, files] of byUnit) {
53
+ const slot = key.slice(0, key.indexOf(':'));
54
+ if (!slot.startsWith('be.app.'))
55
+ continue;
56
+ appRoots.add(key.slice(key.indexOf(':') + 1));
57
+ for (const rel of files)
58
+ if (!TEST_FILE.test(rel))
59
+ rootFiles.push(rel);
60
+ }
61
+ return { rootFiles, roots: [...appRoots].sort(byCodeUnit) };
71
62
  }
72
-
73
63
  function reportUncomposedBackendOwners(byUnit, reached, roots, counts, violations) {
74
- for (const [key, files] of [...byUnit].sort(([a], [b]) => a.localeCompare(b))) {
75
- const slot = key.slice(0, key.indexOf(':'));
76
- const root = key.slice(key.indexOf(':') + 1);
77
- const feature = slot === 'be.feature';
78
- if (!feature && !BE_CAPABILITY_SLOTS.has(slot)) continue;
79
- counts[feature ? 'features' : 'modules'] += 1;
80
- if (files.some(rel => reached.has(rel))) continue;
81
- counts.notComposed += 1;
82
- const label = root.replace(/\/$/, '');
83
- violations.push({
84
- ruleId: 'BE_FEATURE_NOT_COMPOSED',
85
- path: entryOf(root, files), owner: label, slot, appRoots: roots,
86
- message: `${feature ? 'Feature' : 'Module'} ${label} is not composed into any app: no runtime import path leads from ${roots.join(', ')} to it (a type-only import composes nothing), so it is dead code that no process serves.`,
87
- });
88
- }
64
+ for (const [key, files] of [...byUnit].sort(([a], [b]) => a.localeCompare(b))) {
65
+ const slot = key.slice(0, key.indexOf(':'));
66
+ const root = key.slice(key.indexOf(':') + 1);
67
+ const feature = slot === 'be.feature';
68
+ if (!feature && !BE_CAPABILITY_SLOTS.has(slot))
69
+ continue;
70
+ counts[feature ? 'features' : 'modules'] += 1;
71
+ if (files.some(rel => reached.has(rel)))
72
+ continue;
73
+ counts.notComposed += 1;
74
+ const label = root.replace(/\/$/, '');
75
+ violations.push({
76
+ ruleId: 'BE_FEATURE_NOT_COMPOSED',
77
+ path: entryOf(root, files), owner: label, slot, appRoots: roots,
78
+ message: `${feature ? 'Feature' : 'Module'} ${label} is not composed into any app: no runtime import path leads from ${roots.join(', ')} to it (a type-only import composes nothing), so it is dead code that no process serves.`,
79
+ });
80
+ }
89
81
  }
90
-
91
82
  function checkBackend(graph) {
92
- const byUnit = ownerFiles(graph);
93
- const { rootFiles, roots } = backendAppRoots(byUnit);
94
- const counts = { features: 0, modules: 0, appRoots: roots.length, notComposed: 0 };
95
- if (!roots.length) return { violations: [], coverage: { status: 'unavailable', reason: 'no be.app.* owner instance holds a source file, so there is no app root to compose into', ...counts } };
96
- const reached = reachFrom(graph, rootFiles);
97
- const violations = [];
98
- reportUncomposedBackendOwners(byUnit, reached, roots, counts, violations);
99
- reportUncomposedTransports(graph, reached, roots, counts, violations);
100
- return { violations, coverage: { status: 'checked', ...counts } };
83
+ const byUnit = ownerFiles(graph);
84
+ const { rootFiles, roots } = backendAppRoots(byUnit);
85
+ const counts = { features: 0, modules: 0, appRoots: roots.length, notComposed: 0 };
86
+ if (!roots.length)
87
+ return { violations: [], coverage: { status: 'unavailable', reason: 'no be.app.* owner instance holds a source file, so there is no app root to compose into', ...counts } };
88
+ const reached = reachFrom(graph, rootFiles);
89
+ const violations = [];
90
+ reportUncomposedBackendOwners(byUnit, reached, roots, counts, violations);
91
+ reportUncomposedTransports(graph, reached, roots, counts, violations);
92
+ return { violations, coverage: { status: 'checked', ...counts } };
101
93
  }
102
-
103
94
  /** A reached feature does not compose its other transport modules. Judge each module's runtime path. */
104
95
  function reportUncomposedTransports(graph, reached, roots, counts, violations) {
105
- for (const [rel, node] of graph.files) {
106
- if (!node.owner || !rel.startsWith('src/features/') || TEST_FILE.test(rel)) continue;
107
- if (!/\/transport\/[^/]+\/[^/]+\.module\.[cm]?[jt]sx?$/.test(rel) || reached.has(rel)) continue;
108
- counts.notComposed += 1;
109
- violations.push({
110
- ruleId: 'BE_FEATURE_NOT_COMPOSED', path: rel, owner: node.owner.root, slot: node.slot, appRoots: roots,
111
- message: `Transport module ${rel} is not composed into any app: no runtime import path leads from ${roots.join(', ')} to it (a type-only import composes nothing).`,
112
- });
113
- }
96
+ for (const [rel, node] of graph.files) {
97
+ if (!node.owner || !rel.startsWith('src/features/') || TEST_FILE.test(rel))
98
+ continue;
99
+ if (!/\/transport\/[^/]+\/[^/]+\.module\.[cm]?[jt]sx?$/.test(rel) || reached.has(rel))
100
+ continue;
101
+ counts.notComposed += 1;
102
+ violations.push({
103
+ ruleId: 'BE_FEATURE_NOT_COMPOSED', path: rel, owner: node.owner.root, slot: node.slot, appRoots: roots,
104
+ message: `Transport module ${rel} is not composed into any app: no runtime import path leads from ${roots.join(', ')} to it (a type-only import composes nothing).`,
105
+ });
106
+ }
114
107
  }
115
-
116
108
  /** Route table of one app: arrays of segments, each {kind:'static'|'dyn'|'catch'|'optcatch', text}. */
117
109
  function routeSegmentsOf(parts) {
118
- const segments = [];
119
- let usable = true;
120
- for (const part of parts) {
121
- if (/^\([^.)][^)]*\)$/.test(part)) continue; // route group
122
- if (part.startsWith('@')) continue; // parallel slot: no URL segment
123
- if (part.startsWith('_') || /^\(\.+\)/.test(part)) { usable = false; break; } // private folder, intercepting route
124
- segments.push(part);
125
- }
126
- if (!usable) return null;
127
- if (segments[0] === '[locale]') segments.shift();
128
- return segments;
110
+ const segments = [];
111
+ let usable = true;
112
+ for (const part of parts) {
113
+ if (/^\([^.)][^)]*\)$/.test(part))
114
+ continue; // route group
115
+ if (part.startsWith('@'))
116
+ continue; // parallel slot: no URL segment
117
+ if (part.startsWith('_') || /^\(\.+\)/.test(part)) {
118
+ usable = false;
119
+ break;
120
+ } // private folder, intercepting route
121
+ segments.push(part);
122
+ }
123
+ if (!usable)
124
+ return null;
125
+ if (segments[0] === '[locale]')
126
+ segments.shift();
127
+ return segments;
129
128
  }
130
-
131
129
  function routeSegmentOf(part) {
132
- if (/^\[\[\.\.\..+\]\]$/.test(part)) return { kind: 'optcatch', text: part };
133
- if (/^\[\.\.\..+\]$/.test(part)) return { kind: 'catch', text: part };
134
- if (/^\[.+\]$/.test(part)) return { kind: 'dyn', text: part };
135
- return { kind: 'static', text: part };
130
+ if (/^\[\[\.\.\..+\]\]$/.test(part))
131
+ return { kind: 'optcatch', text: part };
132
+ if (/^\[\.\.\..+\]$/.test(part))
133
+ return { kind: 'catch', text: part };
134
+ if (/^\[.+\]$/.test(part))
135
+ return { kind: 'dyn', text: part };
136
+ return { kind: 'static', text: part };
136
137
  }
137
-
138
138
  function routeTable(graph, app) {
139
- const prefix = `apps/${app}/src/app/`;
140
- const routes = [];
141
- for (const rel of graph.files.keys()) {
142
- if (!rel.startsWith(prefix)) continue;
143
- const parts = rel.slice(prefix.length).split('/');
144
- if (!ROUTE_FILE.test(parts.at(-1))) continue;
145
- const segments = routeSegmentsOf(parts.slice(0, -1));
146
- if (segments === null) continue;
147
- routes.push(segments.map(routeSegmentOf));
148
- }
149
- return routes;
139
+ const prefix = `apps/${app}/src/app/`;
140
+ const routes = [];
141
+ for (const rel of graph.files.keys()) {
142
+ if (!rel.startsWith(prefix))
143
+ continue;
144
+ const parts = rel.slice(prefix.length).split('/');
145
+ if (!ROUTE_FILE.test(parts.at(-1)))
146
+ continue;
147
+ const segments = routeSegmentsOf(parts.slice(0, -1));
148
+ if (segments === null)
149
+ continue;
150
+ routes.push(segments.map(routeSegmentOf));
151
+ }
152
+ return routes;
150
153
  }
151
-
152
154
  /** One href segment (may contain PLACEHOLDER for a template expression) against one route segment. */
153
155
  function segmentMatches(hrefSegment, routeSegment) {
154
- if (!hrefSegment.includes(PLACEHOLDER)) return routeSegment.kind === 'dyn' || routeSegment.text === hrefSegment;
155
- if (routeSegment.kind === 'dyn' || routeSegment.kind === 'catch' || routeSegment.kind === 'optcatch') return true;
156
- const parts = hrefSegment.split(PLACEHOLDER).map(part => part.replace(/[.*+?^${}()|[\]\\]/g, String.raw`\$&`));
157
- return new RegExp(`^${parts.join('.*')}$`).test(routeSegment.text);
156
+ if (!hrefSegment.includes(PLACEHOLDER))
157
+ return routeSegment.kind === 'dyn' || routeSegment.text === hrefSegment;
158
+ if (routeSegment.kind === 'dyn' || routeSegment.kind === 'catch' || routeSegment.kind === 'optcatch')
159
+ return true;
160
+ const parts = hrefSegment.split(PLACEHOLDER).map(part => part.replace(/[.*+?^${}()|[\]\\]/g, String.raw `\$&`));
161
+ return new RegExp(`^${parts.join('.*')}$`).test(routeSegment.text);
158
162
  }
159
-
160
163
  function matchRoute(hrefSegments, route, at = 0, from = 0) {
161
- if (from === route.length) return at === hrefSegments.length;
162
- const routeSegment = route[from];
163
- if (routeSegment.kind === 'optcatch' && matchRoute(hrefSegments, route, at, from + 1)) return true;
164
- if (routeSegment.kind === 'catch' || routeSegment.kind === 'optcatch') {
165
- for (let take = 1; at + take <= hrefSegments.length; take += 1) if (matchRoute(hrefSegments, route, at + take, from + 1)) return true;
166
- return false;
167
- }
168
- if (at >= hrefSegments.length || !segmentMatches(hrefSegments[at], routeSegment)) return false;
169
- return matchRoute(hrefSegments, route, at + 1, from + 1);
164
+ if (from === route.length)
165
+ return at === hrefSegments.length;
166
+ const routeSegment = route[from];
167
+ if (routeSegment.kind === 'optcatch' && matchRoute(hrefSegments, route, at, from + 1))
168
+ return true;
169
+ if (routeSegment.kind === 'catch' || routeSegment.kind === 'optcatch') {
170
+ for (let take = 1; at + take <= hrefSegments.length; take += 1)
171
+ if (matchRoute(hrefSegments, route, at + take, from + 1))
172
+ return true;
173
+ return false;
174
+ }
175
+ if (at >= hrefSegments.length || !segmentMatches(hrefSegments[at], routeSegment))
176
+ return false;
177
+ return matchRoute(hrefSegments, route, at + 1, from + 1);
170
178
  }
171
-
172
179
  function hrefResolves(href, routes) {
173
- const cut = href.search(/[?#]/);
174
- const pathOnly = cut === -1 ? href : href.slice(0, cut);
175
- const segments = pathOnly.split('/').slice(1).filter(segment => segment !== '');
176
- const candidates = [segments];
177
- // A leading locale (a literal `en`/`vi-VN` or a bare template expression) is what [locale] carries: try without it too.
178
- if (segments.length && (/^[a-z]{2}(?:-[a-zA-Z]{2})?$/.test(segments[0]) || segments[0] === PLACEHOLDER)) candidates.push(segments.slice(1));
179
- return candidates.some(candidate => routes.some(route => matchRoute(candidate, route)));
180
+ const cut = href.search(/[?#]/);
181
+ const pathOnly = cut === -1 ? href : href.slice(0, cut);
182
+ const segments = pathOnly.split('/').slice(1).filter(segment => segment !== '');
183
+ const candidates = [segments];
184
+ // A leading locale (a literal `en`/`vi-VN` or a bare template expression) is what [locale] carries: try without it too.
185
+ if (segments.length && (/^[a-z]{2}(?:-[a-zA-Z]{2})?$/.test(segments[0]) || segments[0] === PLACEHOLDER))
186
+ candidates.push(segments.slice(1));
187
+ return candidates.some(candidate => routes.some(route => matchRoute(candidate, route)));
180
188
  }
181
-
182
189
  /** The text of a string-ish expression with PLACEHOLDER for each ${...}; null when it is not a literal we can read. */
183
190
  function literalText(ts, node) {
184
- if (!node) return null;
185
- while (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isNonNullExpression?.(node)) node = node.expression;
186
- if (ts.isStringLiteralLike(node)) return node.text; // includes NoSubstitutionTemplateLiteral
187
- if (ts.isTemplateExpression(node)) return node.head.text + node.templateSpans.map(span => PLACEHOLDER + span.literal.text).join('');
188
- return null;
191
+ if (!node)
192
+ return null;
193
+ while (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isNonNullExpression?.(node))
194
+ node = node.expression;
195
+ if (ts.isStringLiteralLike(node))
196
+ return node.text; // includes NoSubstitutionTemplateLiteral
197
+ if (ts.isTemplateExpression(node))
198
+ return node.head.text + node.templateSpans.map(span => PLACEHOLDER + span.literal.text).join('');
199
+ return null;
189
200
  }
190
-
191
201
  const NAVIGATION_CALLS = new Set(['redirect', 'permanentRedirect']);
192
202
  const ROUTER_METHODS = new Set(['push', 'replace', 'prefetch']);
193
-
194
203
  /** Every href-like target in a source file: {node, text|null (null = computed)}. */
195
204
  function jsxHrefTarget(ts, node) {
196
- if (!ts.isJsxAttribute(node) || !ts.isIdentifier(node.name) || node.name.text !== 'href' || !node.initializer) return null;
197
- const value = ts.isJsxExpression(node.initializer) ? node.initializer.expression : node.initializer;
198
- return { node: value ?? node, text: value ? literalText(ts, value) : null };
205
+ if (!ts.isJsxAttribute(node) || !ts.isIdentifier(node.name) || node.name.text !== 'href' || !node.initializer)
206
+ return null;
207
+ const value = ts.isJsxExpression(node.initializer) ? node.initializer.expression : node.initializer;
208
+ return { node: value ?? node, text: value ? literalText(ts, value) : null };
199
209
  }
200
-
201
210
  function routerNameOf(ts, callee) {
202
- if (ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression)) return callee.expression.text;
203
- if (ts.isPropertyAccessExpression(callee) && ts.isPropertyAccessExpression(callee.expression)) return callee.expression.name.text;
204
- return '';
211
+ if (ts.isPropertyAccessExpression(callee) && ts.isIdentifier(callee.expression))
212
+ return callee.expression.text;
213
+ if (ts.isPropertyAccessExpression(callee) && ts.isPropertyAccessExpression(callee.expression))
214
+ return callee.expression.name.text;
215
+ return '';
205
216
  }
206
-
207
217
  function isNavigationTarget(ts, callee) {
208
- const routerName = routerNameOf(ts, callee);
209
- return (ts.isIdentifier(callee) && NAVIGATION_CALLS.has(callee.text))
210
- || (ts.isPropertyAccessExpression(callee) && ROUTER_METHODS.has(callee.name.text) && /router$/i.test(routerName));
218
+ const routerName = routerNameOf(ts, callee);
219
+ return (ts.isIdentifier(callee) && NAVIGATION_CALLS.has(callee.text))
220
+ || (ts.isPropertyAccessExpression(callee) && ROUTER_METHODS.has(callee.name.text) && /router$/i.test(routerName));
211
221
  }
212
-
213
222
  function callHrefTarget(ts, node) {
214
- if (!ts.isCallExpression(node) || !node.arguments.length) return null;
215
- const callee = node.expression;
216
- if (!isNavigationTarget(ts, callee)) return null;
217
- return { node: node.arguments[0], text: literalText(ts, node.arguments[0]) };
223
+ if (!ts.isCallExpression(node) || !node.arguments.length)
224
+ return null;
225
+ const callee = node.expression;
226
+ if (!isNavigationTarget(ts, callee))
227
+ return null;
228
+ return { node: node.arguments[0], text: literalText(ts, node.arguments[0]) };
218
229
  }
219
-
220
230
  function hrefTargetOf(ts, node) {
221
- return jsxHrefTarget(ts, node) ?? callHrefTarget(ts, node);
231
+ return jsxHrefTarget(ts, node) ?? callHrefTarget(ts, node);
222
232
  }
223
-
224
233
  function hrefTargets(ts, sourceFile) {
225
- const found = [];
226
- const visit = node => {
227
- const target = hrefTargetOf(ts, node);
228
- if (target) found.push(target);
229
- ts.forEachChild(node, visit);
230
- };
231
- visit(sourceFile);
232
- return found;
234
+ const found = [];
235
+ const visit = (node) => {
236
+ const target = hrefTargetOf(ts, node);
237
+ if (target)
238
+ found.push(target);
239
+ ts.forEachChild(node, visit);
240
+ };
241
+ visit(sourceFile);
242
+ return found;
233
243
  }
234
-
235
244
  function appRouteRoots(graph) {
236
- const apps = new Map();
237
- for (const [rel, node] of graph.files) {
238
- if (node.slot !== 'fe.route') continue;
239
- const app = /^apps\/([^/]+)\/src\/app\//.exec(rel)?.[1];
240
- if (!app) continue;
241
- if (!apps.has(app)) apps.set(app, []);
242
- apps.get(app).push(rel);
243
- }
244
- return apps;
245
+ const apps = new Map();
246
+ for (const [rel, node] of graph.files) {
247
+ if (node.slot !== 'fe.route')
248
+ continue;
249
+ const app = /^apps\/([^/]+)\/src\/app\//.exec(rel)?.[1];
250
+ if (!app)
251
+ continue;
252
+ if (!apps.has(app))
253
+ apps.set(app, []);
254
+ apps.get(app)?.push(rel);
255
+ }
256
+ return apps;
245
257
  }
246
-
247
258
  function reportUnreachableFrontendFeatures(byUnit, reachedByApp, counts, violations) {
248
- for (const [key, files] of [...byUnit].sort(([a], [b]) => a.localeCompare(b))) {
249
- if (!key.startsWith('fe.feature:')) continue;
250
- const root = key.slice('fe.feature:'.length);
251
- const app = /^apps\/([^/]+)\//.exec(root)?.[1];
252
- counts.pages += 1;
253
- const reached = reachedByApp.get(app);
254
- if (reached && files.some(rel => reached.has(rel))) { counts.mounted += 1; continue; }
255
- const label = root.replace(/\/$/, '');
256
- violations.push({
257
- ruleId: 'FE_OWNER_REACHABLE', path: entryOf(root, files), owner: label, app,
258
- message: `${label} is not mounted: no runtime import path leads from a route file under apps/${app}/src/app to it (a type-only import mounts nothing), so the page is never shown.`,
259
- });
260
- }
259
+ for (const [key, files] of [...byUnit].sort(([a], [b]) => a.localeCompare(b))) {
260
+ if (!key.startsWith('fe.feature:'))
261
+ continue;
262
+ const root = key.slice('fe.feature:'.length);
263
+ const app = /^apps\/([^/]+)\//.exec(root)?.[1];
264
+ counts.pages += 1;
265
+ const reached = reachedByApp.get(app);
266
+ if (reached && files.some(rel => reached.has(rel))) {
267
+ counts.mounted += 1;
268
+ continue;
269
+ }
270
+ const label = root.replace(/\/$/, '');
271
+ violations.push({
272
+ ruleId: 'FE_OWNER_REACHABLE', path: entryOf(root, files), owner: label, app,
273
+ message: `${label} is not mounted: no runtime import path leads from a route file under apps/${app}/src/app to it (a type-only import mounts nothing), so the page is never shown.`,
274
+ });
275
+ }
261
276
  }
262
-
263
277
  function routeApps(graph, apps) {
264
- return [...new Set([...apps.keys(), ...[...graph.files.keys()].map(rel => /^apps\/([^/]+)\/src\//.exec(rel)?.[1]).filter(Boolean)])].sort(byCodeUnit);
278
+ return [...new Set([...apps.keys(), ...[...graph.files.keys()].map(rel => /^apps\/([^/]+)\/src\//.exec(rel)?.[1]).filter((app) => Boolean(app))])].sort(byCodeUnit);
265
279
  }
266
-
267
280
  function hrefNeedsSkipping(text, routes) {
268
- if (text === null || !text.startsWith('/') || text.startsWith('//') || !routes.length) return true;
269
- const hrefPath = text.split(/[?#]/)[0];
270
- return /\.[A-Za-z0-9]{1,6}$/.test(hrefPath.split('/').at(-1)); // static asset
281
+ if (text === null || !text.startsWith('/') || text.startsWith('//') || !routes.length)
282
+ return true;
283
+ const hrefPath = text.split(/[?#]/)[0];
284
+ return /\.[A-Za-z0-9]{1,6}$/.test(hrefPath.split('/').at(-1)); // static asset
271
285
  }
272
-
273
286
  function reportUnresolvedHref(app, rel, node, target, prefix, violations) {
274
- const point = node.sourceFile.getLineAndCharacterOfPosition(target.node.getStart(node.sourceFile));
275
- const shown = target.text.split(PLACEHOLDER).join('${…}');
276
- violations.push({
277
- ruleId: 'FE_HREF_RESOLVES', path: rel, line: point.line + 1, column: point.character + 1, app, href: shown,
278
- message: `href "${shown}" matches no route of app ${app}: no page.tsx or route.ts under ${prefix}app serves that path.`,
279
- });
287
+ const point = node.sourceFile.getLineAndCharacterOfPosition(target.node.getStart(node.sourceFile));
288
+ const shown = target.text.split(PLACEHOLDER).join('${…}');
289
+ violations.push({
290
+ ruleId: 'FE_HREF_RESOLVES', path: rel, line: point.line + 1, column: point.character + 1, app, href: shown,
291
+ message: `href "${shown}" matches no route of app ${app}: no page.tsx or route.ts under ${prefix}app serves that path.`,
292
+ });
280
293
  }
281
-
282
294
  function inspectAppHrefTargets(app, graph, ts, routes, counts, violations) {
283
- const prefix = `apps/${app}/src/`;
284
- for (const [rel, node] of graph.files) {
285
- if (!rel.startsWith(prefix) || TEST_FILE.test(rel)) continue;
286
- for (const target of hrefTargets(ts, node.sourceFile)) {
287
- counts.hrefs += 1;
288
- if (hrefNeedsSkipping(target.text, routes)) { counts.hrefsSkipped += 1; continue; }
289
- if (hrefResolves(target.text, routes)) { counts.hrefsResolved += 1; continue; }
290
- reportUnresolvedHref(app, rel, node, target, prefix, violations);
295
+ const prefix = `apps/${app}/src/`;
296
+ for (const [rel, node] of graph.files) {
297
+ if (!rel.startsWith(prefix) || TEST_FILE.test(rel))
298
+ continue;
299
+ for (const target of hrefTargets(ts, node.sourceFile)) {
300
+ counts.hrefs += 1;
301
+ if (hrefNeedsSkipping(target.text, routes)) {
302
+ counts.hrefsSkipped += 1;
303
+ continue;
304
+ }
305
+ if (hrefResolves(target.text, routes)) {
306
+ counts.hrefsResolved += 1;
307
+ continue;
308
+ }
309
+ reportUnresolvedHref(app, rel, node, target, prefix, violations);
310
+ }
291
311
  }
292
- }
293
312
  }
294
-
295
- function checkFrontend(config, context, graph) {
296
- const ts = context.ts ?? context.loaded.ts;
297
- const byUnit = ownerFiles(graph);
298
- const apps = appRouteRoots(graph);
299
- const counts = { pages: 0, mounted: 0, hrefs: 0, hrefsResolved: 0, hrefsSkipped: 0, routes: 0 };
300
- const violations = [];
301
- const reachedByApp = new Map([...apps].map(([app, roots]) => [app, reachFrom(graph, roots)]));
302
- reportUnreachableFrontendFeatures(byUnit, reachedByApp, counts, violations);
303
- for (const app of routeApps(graph, apps)) {
304
- const routes = routeTable(graph, app);
305
- counts.routes += routes.length;
306
- inspectAppHrefTargets(app, graph, ts, routes, counts, violations);
307
- }
308
- return { violations, coverage: { status: 'checked', ...counts } };
313
+ function checkFrontend(_config, context, graph) {
314
+ const ts = context.ts ?? context.loaded.ts;
315
+ const byUnit = ownerFiles(graph);
316
+ const apps = appRouteRoots(graph);
317
+ const counts = { pages: 0, mounted: 0, hrefs: 0, hrefsResolved: 0, hrefsSkipped: 0, routes: 0 };
318
+ const violations = [];
319
+ const reachedByApp = new Map([...apps].map(([app, roots]) => [app, reachFrom(graph, roots)]));
320
+ reportUnreachableFrontendFeatures(byUnit, reachedByApp, counts, violations);
321
+ for (const app of routeApps(graph, apps)) {
322
+ const routes = routeTable(graph, app);
323
+ counts.routes += routes.length;
324
+ inspectAppHrefTargets(app, graph, ts, routes, counts, violations);
325
+ }
326
+ return { violations, coverage: { status: 'checked', ...counts } };
309
327
  }
310
-
311
- export function checkReachability({ config, context, graph } = {}) {
312
- return graph.profile === 'be' ? checkBackend(graph) : checkFrontend(config, context, graph);
328
+ export function checkReachability({ config, context, graph }) {
329
+ return graph.profile === 'be' ? checkBackend(graph) : checkFrontend(config, context, graph);
313
330
  }