@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,186 +1,198 @@
1
1
  import path from 'node:path';
2
2
  import { reachableViolation, relativePath } from './typescript.mjs';
3
-
4
3
  function hasClientDirective(ts, sourceFile) {
5
- return sourceFile.statements.find(statement => ts.isExpressionStatement(statement)
6
- && ts.isStringLiteral(statement.expression) && statement.expression.text === 'use client');
4
+ return sourceFile.statements.find(statement => ts.isExpressionStatement(statement)
5
+ && ts.isStringLiteral(statement.expression) && statement.expression.text === 'use client');
7
6
  }
8
-
9
7
  function bindImportClause(ts, clause, edge, bindings) {
10
- if (clause.name && !clause.isTypeOnly) bindings.set(clause.name.text, edge);
11
- if (!clause.namedBindings) return;
12
- if (ts.isNamespaceImport(clause.namedBindings)) bindings.set(clause.namedBindings.name.text, edge);
13
- if (!ts.isNamedImports(clause.namedBindings)) return;
14
- for (const element of clause.namedBindings.elements) {
15
- if (!element.isTypeOnly && !clause.isTypeOnly) bindings.set(element.name.text, edge);
16
- }
17
- }
18
-
8
+ if (clause.name && !clause.isTypeOnly)
9
+ bindings.set(clause.name.text, edge);
10
+ if (!clause.namedBindings)
11
+ return;
12
+ if (ts.isNamespaceImport(clause.namedBindings))
13
+ bindings.set(clause.namedBindings.name.text, edge);
14
+ if (!ts.isNamedImports(clause.namedBindings))
15
+ return;
16
+ for (const element of clause.namedBindings.elements) {
17
+ if (!element.isTypeOnly && !clause.isTypeOnly)
18
+ bindings.set(element.name.text, edge);
19
+ }
20
+ }
19
21
  function importBindings(ts, sourceFile, edges) {
20
- const byStart = new Map(edges.map(edge => [edge.node.getStart(sourceFile), edge]));
21
- const bindings = new Map();
22
- for (const statement of sourceFile.statements) {
23
- if (!ts.isImportDeclaration(statement) || !statement.importClause || !ts.isStringLiteralLike(statement.moduleSpecifier)) continue;
24
- const edge = byStart.get(statement.moduleSpecifier.getStart(sourceFile));
25
- if (!edge) continue;
26
- bindImportClause(ts, statement.importClause, edge, bindings);
27
- }
28
- return bindings;
29
- }
30
-
22
+ const byStart = new Map(edges.map((edge) => [edge.node.getStart(sourceFile), edge]));
23
+ const bindings = new Map();
24
+ for (const statement of sourceFile.statements) {
25
+ if (!ts.isImportDeclaration(statement) || !statement.importClause || !ts.isStringLiteralLike(statement.moduleSpecifier))
26
+ continue;
27
+ const edge = byStart.get(statement.moduleSpecifier.getStart(sourceFile));
28
+ if (!edge)
29
+ continue;
30
+ bindImportClause(ts, statement.importClause, edge, bindings);
31
+ }
32
+ return bindings;
33
+ }
31
34
  function importedNames(ts, sourceFile, moduleName) {
32
- const names = new Map();
33
- for (const statement of sourceFile.statements) {
34
- if (!ts.isImportDeclaration(statement) || statement.moduleSpecifier.text !== moduleName || !statement.importClause || statement.importClause.isTypeOnly) continue;
35
- const named = statement.importClause.namedBindings;
36
- if (!named || !ts.isNamedImports(named)) continue;
37
- for (const element of named.elements) if (!element.isTypeOnly) names.set(element.name.text, element.propertyName?.text ?? element.name.text);
38
- }
39
- return names;
40
- }
41
-
35
+ const names = new Map();
36
+ for (const statement of sourceFile.statements) {
37
+ if (!ts.isImportDeclaration(statement) || !ts.isStringLiteralLike(statement.moduleSpecifier) || statement.moduleSpecifier.text !== moduleName || !statement.importClause || statement.importClause.isTypeOnly)
38
+ continue;
39
+ const named = statement.importClause.namedBindings;
40
+ if (!named || !ts.isNamedImports(named))
41
+ continue;
42
+ for (const element of named.elements)
43
+ if (!element.isTypeOnly)
44
+ names.set(element.name.text, element.propertyName?.text ?? element.name.text);
45
+ }
46
+ return names;
47
+ }
42
48
  function jsxRootName(ts, tagName) {
43
- if (ts.isIdentifier(tagName)) return tagName.text;
44
- if (ts.isPropertyAccessExpression(tagName)) {
45
- let current = tagName;
46
- while (ts.isPropertyAccessExpression(current)) current = current.expression;
47
- return ts.isIdentifier(current) ? current.text : null;
48
- }
49
- return null;
50
- }
51
-
49
+ if (ts.isIdentifier(tagName))
50
+ return tagName.text;
51
+ if (ts.isPropertyAccessExpression(tagName)) {
52
+ let current = tagName;
53
+ while (ts.isPropertyAccessExpression(current))
54
+ current = current.expression;
55
+ return ts.isIdentifier(current) ? current.text : null;
56
+ }
57
+ return null;
58
+ }
52
59
  function addRouteVariableFunctions(ts, statement, variables) {
53
- for (const declaration of statement.declarationList.declarations) {
54
- if (ts.isIdentifier(declaration.name) && declaration.initializer
55
- && (ts.isArrowFunction(declaration.initializer) || ts.isFunctionExpression(declaration.initializer))) variables.set(declaration.name.text, declaration.initializer);
56
- }
60
+ for (const declaration of statement.declarationList.declarations) {
61
+ if (ts.isIdentifier(declaration.name) && declaration.initializer
62
+ && (ts.isArrowFunction(declaration.initializer) || ts.isFunctionExpression(declaration.initializer)))
63
+ variables.set(declaration.name.text, declaration.initializer);
64
+ }
57
65
  }
58
-
59
66
  function recordRouteStatement(ts, statement, state) {
60
- if (ts.isVariableStatement(statement)) addRouteVariableFunctions(ts, statement, state.variables);
61
- if (ts.isFunctionDeclaration(statement) && statement.name) state.functions.set(statement.name.text, statement);
62
- if (ts.isFunctionDeclaration(statement) && statement.modifiers?.some(item => item.kind === ts.SyntaxKind.DefaultKeyword)) state.directDefault = statement;
63
- if (ts.isExportAssignment(statement) && !statement.isExportEquals) state.exportNode = statement;
67
+ if (ts.isVariableStatement(statement))
68
+ addRouteVariableFunctions(ts, statement, state.variables);
69
+ if (ts.isFunctionDeclaration(statement) && statement.name)
70
+ state.functions.set(statement.name.text, statement);
71
+ if (ts.isFunctionDeclaration(statement) && statement.modifiers?.some(item => item.kind === ts.SyntaxKind.DefaultKeyword))
72
+ state.directDefault = statement;
73
+ if (ts.isExportAssignment(statement) && !statement.isExportEquals)
74
+ state.exportNode = statement;
64
75
  }
65
-
66
76
  function routeFunction(ts, sourceFile) {
67
- const state = { variables: new Map(), functions: new Map(), directDefault: null, exportNode: null };
68
- for (const statement of sourceFile.statements) recordRouteStatement(ts, statement, state);
69
- if (state.directDefault) return { fn: state.directDefault, exportNode: state.directDefault };
70
- if (!state.exportNode || !ts.isIdentifier(state.exportNode.expression)) return { fn: null, exportNode: state.exportNode };
71
- return { fn: state.variables.get(state.exportNode.expression.text) ?? state.functions.get(state.exportNode.expression.text) ?? null, exportNode: state.exportNode };
77
+ const state = { variables: new Map(), functions: new Map(), directDefault: null, exportNode: null };
78
+ for (const statement of sourceFile.statements)
79
+ recordRouteStatement(ts, statement, state);
80
+ if (state.directDefault)
81
+ return { fn: state.directDefault, exportNode: state.directDefault };
82
+ if (!state.exportNode || !ts.isIdentifier(state.exportNode.expression))
83
+ return { fn: null, exportNode: state.exportNode };
84
+ return { fn: state.variables.get(state.exportNode.expression.text) ?? state.functions.get(state.exportNode.expression.text) ?? null, exportNode: state.exportNode };
72
85
  }
73
-
74
86
  function routePageRoots(context, sourceFile, featureRoots) {
75
- const workspace = context.workspaceOf(sourceFile.fileName);
76
- if (!workspace) return featureRoots.map(root => path.join(root, 'pages'));
77
- const local = featureRoots.filter(root => context.workspaceOf(root) === workspace);
78
- return (local.length ? local : featureRoots).map(root => path.join(root, 'pages'));
87
+ const workspace = context.workspaceOf(sourceFile.fileName);
88
+ if (!workspace)
89
+ return featureRoots.map(root => path.join(root, 'pages'));
90
+ const local = featureRoots.filter(root => context.workspaceOf(root) === workspace);
91
+ return (local.length ? local : featureRoots).map(root => path.join(root, 'pages'));
79
92
  }
80
-
81
93
  function routingTermination(ts, statement, navigation) {
82
- if (ts.isThrowStatement(statement)) return true;
83
- if (ts.isBlock(statement)) return statement.statements.length > 0 && routingTermination(ts, statement.statements.at(-1), navigation);
84
- const expression = ts.isExpressionStatement(statement) ? statement.expression : (ts.isReturnStatement(statement) && statement.expression) || null;
85
- return Boolean(expression && ts.isCallExpression(expression) && ts.isIdentifier(expression.expression)
86
- && ['redirect', 'notFound'].includes(navigation.get(expression.expression.text)));
94
+ if (ts.isThrowStatement(statement))
95
+ return true;
96
+ if (ts.isBlock(statement)) {
97
+ const last = statement.statements.at(-1);
98
+ return statement.statements.length > 0 && last !== undefined && routingTermination(ts, last, navigation);
99
+ }
100
+ const expression = ts.isExpressionStatement(statement) ? statement.expression : (ts.isReturnStatement(statement) && statement.expression) || null;
101
+ return Boolean(expression && ts.isCallExpression(expression) && ts.isIdentifier(expression.expression)
102
+ && ['redirect', 'notFound'].includes(navigation.get(expression.expression.text) ?? ''));
87
103
  }
88
-
89
104
  function routingGuard(ts, node, navigation) {
90
- return ts.isIfStatement(node) && !node.elseStatement && routingTermination(ts, node.thenStatement, navigation);
105
+ return ts.isIfStatement(node) && !node.elseStatement && routingTermination(ts, node.thenStatement, navigation);
91
106
  }
92
-
93
107
  function routeNavigationCall(ts, node, navigation) {
94
- return ts.isCallExpression(node) && ts.isIdentifier(node.expression)
95
- && ['redirect', 'notFound'].includes(navigation.get(node.expression.text));
108
+ return ts.isCallExpression(node) && ts.isIdentifier(node.expression)
109
+ && ['redirect', 'notFound'].includes(navigation.get(node.expression.text) ?? '');
96
110
  }
97
-
98
111
  function recordRouteNode(ts, node, state, insideNavigationArgument) {
99
- if (ts.isJsxSelfClosingElement(node) || ts.isJsxElement(node)) state.jsx.push(node);
100
- if (ts.isIfStatement(node) || ts.isSwitchStatement(node) || (ts.isConditionalExpression(node) && !insideNavigationArgument)) state.decisions.push(node);
112
+ if (ts.isJsxSelfClosingElement(node) || ts.isJsxElement(node))
113
+ state.jsx.push(node);
114
+ if (ts.isIfStatement(node) || ts.isSwitchStatement(node) || (ts.isConditionalExpression(node) && !insideNavigationArgument))
115
+ state.decisions.push(node);
101
116
  }
102
-
103
117
  function visitRouteNode(ts, node, state, insideNavigationArgument = false) {
104
- recordRouteNode(ts, node, state, insideNavigationArgument);
105
- if (routeNavigationCall(ts, node, state.navigation)) {
106
- state.adapterCalls.push(node);
107
- for (const argument of node.arguments) visitRouteNode(ts, argument, state, true);
108
- return;
109
- }
110
- ts.forEachChild(node, child => visitRouteNode(ts, child, state, insideNavigationArgument));
111
- }
112
-
118
+ recordRouteNode(ts, node, state, insideNavigationArgument);
119
+ if (routeNavigationCall(ts, node, state.navigation)) {
120
+ state.adapterCalls.push(node);
121
+ for (const argument of node.arguments)
122
+ visitRouteNode(ts, argument, state, true);
123
+ return;
124
+ }
125
+ ts.forEachChild(node, child => visitRouteNode(ts, child, state, insideNavigationArgument));
126
+ }
113
127
  function collectRouteNodes(ts, routeFunction, navigation) {
114
- const state = { jsx: [], adapterCalls: [], decisions: [], navigation };
115
- visitRouteNode(ts, routeFunction, state);
116
- return state;
128
+ const state = { jsx: [], adapterCalls: [], decisions: [], navigation };
129
+ visitRouteNode(ts, routeFunction, state);
130
+ return state;
117
131
  }
118
-
119
132
  function mountedRoutePages(ts, context, sourceFile, featureRoots, bindings, jsx, insideAny) {
120
- const pages = routePageRoots(context, sourceFile, featureRoots);
121
- return jsx.filter(node => {
122
- const opening = ts.isJsxElement(node) ? node.openingElement : node;
123
- const local = jsxRootName(ts, opening.tagName);
124
- const edge = local ? bindings.get(local) : null;
125
- return edge && Boolean(reachableViolation(context.edges, edge, target => insideAny(pages, target), { follow: candidate => candidate.reexport && candidate.runtime }));
126
- });
127
- }
128
-
129
- function reportRouteComposition(at, route, scan, mountedPages) {
130
- const { config, context, sourceFile, violations, violation } = at;
131
- const navigationOnly = scan.jsx.length === 0 && scan.adapterCalls.length === 1;
132
- if (!navigationOnly && (mountedPages.length !== 1 || scan.jsx.length !== 1)) {
133
- violations.push(violation(config, sourceFile, route.fn, 'FE_ROUTE_ONE_PAGE', 'A page.tsx route must mount exactly one pages-tier component, or be a zero-JSX redirect/notFound adapter.', { ts: context.ts }));
134
- }
135
- return navigationOnly;
136
- }
137
-
133
+ const pages = routePageRoots(context, sourceFile, featureRoots);
134
+ return jsx.filter(node => {
135
+ const opening = ts.isJsxElement(node) ? node.openingElement : node;
136
+ const local = jsxRootName(ts, opening.tagName);
137
+ const edge = local ? bindings.get(local) : null;
138
+ return edge && Boolean(reachableViolation(context.edges, edge, target => insideAny(pages, target), { follow: candidate => candidate.reexport && candidate.runtime }));
139
+ });
140
+ }
141
+ function reportRouteComposition(at, fn, scan, mountedPages) {
142
+ const { config, context, sourceFile, violations, violation } = at;
143
+ const navigationOnly = scan.jsx.length === 0 && scan.adapterCalls.length === 1;
144
+ if (!navigationOnly && (mountedPages.length !== 1 || scan.jsx.length !== 1)) {
145
+ violations.push(violation(config, sourceFile, fn, 'FE_ROUTE_ONE_PAGE', 'A page.tsx route must mount exactly one pages-tier component, or be a zero-JSX redirect/notFound adapter.', { ts: context.ts }));
146
+ }
147
+ return navigationOnly;
148
+ }
138
149
  function reportRouteDecisions(at, decisions, navigation, navigationOnly) {
139
- if (navigationOnly) return;
140
- const { config, context, sourceFile, violations, violation } = at;
141
- for (const decision of decisions) if (!routingGuard(context.ts, decision, navigation)) {
142
- violations.push(violation(config, sourceFile, decision, 'FE_ROUTE_DRAWING_DECISION', 'Visual route files may use terminal redirect/notFound guards but cannot select or omit visual composition.', { ts: context.ts }));
143
- }
150
+ if (navigationOnly)
151
+ return;
152
+ const { config, context, sourceFile, violations, violation } = at;
153
+ for (const decision of decisions)
154
+ if (!routingGuard(context.ts, decision, navigation)) {
155
+ violations.push(violation(config, sourceFile, decision, 'FE_ROUTE_DRAWING_DECISION', 'Visual route files may use terminal redirect/notFound guards but cannot select or omit visual composition.', { ts: context.ts }));
156
+ }
144
157
  }
145
-
146
158
  function reportClientDirective(config, context, sourceFile, violations, violation) {
147
- const clientDirective = hasClientDirective(context.ts, sourceFile);
148
- if (clientDirective) violations.push(violation(config, sourceFile, clientDirective, 'FE_ROUTE_CLIENT_BOUNDARY', 'A page.tsx route adapter cannot own the client boundary.', { ts: context.ts }));
159
+ const clientDirective = hasClientDirective(context.ts, sourceFile);
160
+ if (clientDirective)
161
+ violations.push(violation(config, sourceFile, clientDirective, 'FE_ROUTE_CLIENT_BOUNDARY', 'A page.tsx route adapter cannot own the client boundary.', { ts: context.ts }));
149
162
  }
150
-
151
163
  function routeHookName(ts, sourceFile, local) {
152
- return sourceFile.statements.flatMap(statement => ts.isImportDeclaration(statement) && statement.importClause?.namedBindings && ts.isNamedImports(statement.importClause.namedBindings)
153
- ? statement.importClause.namedBindings.elements.filter(item => item.name.text === local).map(item => item.name) : [])[0];
164
+ return sourceFile.statements.flatMap(statement => ts.isImportDeclaration(statement) && statement.importClause?.namedBindings && ts.isNamedImports(statement.importClause.namedBindings)
165
+ ? statement.importClause.namedBindings.elements.filter(item => item.name.text === local).map(item => item.name) : [])[0];
154
166
  }
155
-
156
167
  function reportForbiddenRouteHooks(config, context, sourceFile, navigation, violations, violation) {
157
- const { ts } = context;
158
- const forbiddenRouteHooks = new Set(['useRouter', 'usePathname', 'useSearchParams', 'useParams', 'useSelectedLayoutSegment', 'useSelectedLayoutSegments']);
159
- for (const [local, imported] of navigation) if (forbiddenRouteHooks.has(imported)) {
160
- const identifier = routeHookName(ts, sourceFile, local);
161
- if (identifier) violations.push(violation(config, sourceFile, identifier, 'FE_ROUTE_CLIENT_HOOK', `Server route adapter imports ${imported}.`, { ts }));
162
- }
163
- }
164
-
168
+ const { ts } = context;
169
+ const forbiddenRouteHooks = new Set(['useRouter', 'usePathname', 'useSearchParams', 'useParams', 'useSelectedLayoutSegment', 'useSelectedLayoutSegments']);
170
+ for (const [local, imported] of navigation)
171
+ if (forbiddenRouteHooks.has(imported)) {
172
+ const identifier = routeHookName(ts, sourceFile, local);
173
+ if (identifier)
174
+ violations.push(violation(config, sourceFile, identifier, 'FE_ROUTE_CLIENT_HOOK', `Server route adapter imports ${imported}.`, { ts }));
175
+ }
176
+ }
165
177
  export function checkRoute(config, context, sourceFile, roots, helpers) {
166
- const { violation, insideAny, importsForSource } = helpers;
167
- const { ts } = context;
168
- const violations = [];
169
- const edges = importsForSource(context, sourceFile.fileName);
170
- const bindings = importBindings(ts, sourceFile, edges);
171
- const route = routeFunction(ts, sourceFile);
172
- if (!route.exportNode || !route.fn) {
173
- violations.push({ ruleId: 'FE_ROUTE_DEFAULT_EXPORT', path: relativePath(config.root, sourceFile.fileName), line: 1, column: 1,
174
- message: 'A page.tsx must default-export one local route function.' });
178
+ const { violation, insideAny, importsForSource } = helpers;
179
+ const { ts } = context;
180
+ const violations = [];
181
+ const edges = importsForSource(context, sourceFile.fileName);
182
+ const bindings = importBindings(ts, sourceFile, edges);
183
+ const route = routeFunction(ts, sourceFile);
184
+ if (!route.exportNode || !route.fn) {
185
+ violations.push({ ruleId: 'FE_ROUTE_DEFAULT_EXPORT', path: relativePath(config.root, sourceFile.fileName), line: 1, column: 1,
186
+ message: 'A page.tsx must default-export one local route function.' });
187
+ return violations;
188
+ }
189
+ const navigation = importedNames(ts, sourceFile, 'next/navigation');
190
+ const scan = collectRouteNodes(ts, route.fn, navigation);
191
+ const mountedPages = mountedRoutePages(ts, context, sourceFile, roots.features, bindings, scan.jsx, insideAny);
192
+ const at = { config, context, sourceFile, violations, violation };
193
+ const navigationOnly = reportRouteComposition(at, route.fn, scan, mountedPages);
194
+ reportRouteDecisions(at, scan.decisions, navigation, navigationOnly);
195
+ reportClientDirective(config, context, sourceFile, violations, violation);
196
+ reportForbiddenRouteHooks(config, context, sourceFile, navigation, violations, violation);
175
197
  return violations;
176
- }
177
- const navigation = importedNames(ts, sourceFile, 'next/navigation');
178
- const scan = collectRouteNodes(ts, route.fn, navigation);
179
- const mountedPages = mountedRoutePages(ts, context, sourceFile, roots.features, bindings, scan.jsx, insideAny);
180
- const at = { config, context, sourceFile, violations, violation };
181
- const navigationOnly = reportRouteComposition(at, route, scan, mountedPages);
182
- reportRouteDecisions(at, scan.decisions, navigation, navigationOnly);
183
- reportClientDirective(config, context, sourceFile, violations, violation);
184
- reportForbiddenRouteHooks(config, context, sourceFile, navigation, violations, violation);
185
- return violations;
186
- }
198
+ }