@starci/eslint-canon-be 3.18.4 → 3.19.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 (208) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/comments.js +1 -1
  3. package/dist/explicit-surface.js +1 -1
  4. package/dist/index.js +1 -1
  5. package/dist/jwt-alg.js +1 -1
  6. package/dist/lib/edition.d.ts +1 -1
  7. package/dist/lib/edition.js +1 -1
  8. package/dist/lib/hfs.d.ts +0 -6
  9. package/dist/lib/hfs.js +7 -5
  10. package/dist/lib/runtime-root.d.ts +6 -1
  11. package/dist/lib/runtime-root.js +8 -2
  12. package/dist/lib/subject-values.js +1 -1
  13. package/dist/module-layering.js +2 -2
  14. package/dist/project-graph.js +1 -1
  15. package/dist/third-party-owner.js +1 -1
  16. package/package.json +3 -1
  17. package/runtime/bundle.json +1 -190
  18. package/runtime/scripts/api/git/recorded-lines.mjs +5 -5
  19. package/runtime/scripts/hfs/project-graph.mjs +6 -6
  20. package/runtime/scripts/hfs/project-rule.mjs +3 -3
  21. package/runtime/config.example.yaml +0 -194
  22. package/runtime/engine/by-code-unit.mjs +0 -12
  23. package/runtime/engine/config.mjs +0 -461
  24. package/runtime/engine/invalid-config.mjs +0 -15
  25. package/runtime/engine/model-config.mjs +0 -112
  26. package/runtime/engine/orca-config.mjs +0 -34
  27. package/runtime/engine/plain-object.mjs +0 -5
  28. package/runtime/engine/release-config.mjs +0 -32
  29. package/runtime/engine/removed-vocabulary.mjs +0 -27
  30. package/runtime/engine/resources-config.mjs +0 -59
  31. package/runtime/engine/runtime-root.mjs +0 -138
  32. package/runtime/engine/secrets.mjs +0 -202
  33. package/runtime/engine/sonar-config.mjs +0 -24
  34. package/runtime/engine/temp-root.mjs +0 -26
  35. package/runtime/engine/yaml.mjs +0 -161
  36. package/runtime/knowledge/grammars/index.yaml +0 -114
  37. package/runtime/knowledge/hfs/canon-pins.yaml +0 -720
  38. package/runtime/knowledge/hfs/fe-stack.yaml +0 -272
  39. package/runtime/knowledge/hfs/rules.yaml +0 -6760
  40. package/runtime/knowledge/hfs/slots.yaml +0 -2783
  41. package/runtime/knowledge/patterns/fe/folder.yaml +0 -425
  42. package/runtime/knowledge/sonar-gate.yaml +0 -151
  43. package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
  44. package/runtime/modules/models/registry.yaml +0 -221
  45. package/runtime/modules/models/runtimes.yaml +0 -556
  46. package/runtime/modules/models/tiers.yaml +0 -66
  47. package/runtime/scripts/api/git/cat-file.mjs +0 -4
  48. package/runtime/scripts/api/git/config-get.mjs +0 -9
  49. package/runtime/scripts/api/git/diff.mjs +0 -4
  50. package/runtime/scripts/api/git/lib.mjs +0 -80
  51. package/runtime/scripts/api/git/ls-files.mjs +0 -5
  52. package/runtime/scripts/api/git/ls-tree.mjs +0 -4
  53. package/runtime/scripts/api/git/merge-base.mjs +0 -8
  54. package/runtime/scripts/api/git/remote.mjs +0 -4
  55. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -4
  56. package/runtime/scripts/api/git/show.mjs +0 -5
  57. package/runtime/scripts/api/git/tag.mjs +0 -4
  58. package/runtime/scripts/hfs/allows.mjs +0 -77
  59. package/runtime/scripts/hfs/architecture/ast-walks.mjs +0 -250
  60. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +0 -103
  61. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +0 -114
  62. package/runtime/scripts/hfs/architecture/backend.mjs +0 -462
  63. package/runtime/scripts/hfs/architecture/background-unowned.mjs +0 -254
  64. package/runtime/scripts/hfs/architecture/canon-clones.mjs +0 -291
  65. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +0 -224
  66. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +0 -102
  67. package/runtime/scripts/hfs/architecture/clones.mjs +0 -287
  68. package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
  69. package/runtime/scripts/hfs/architecture/config-unread.mjs +0 -16
  70. package/runtime/scripts/hfs/architecture/config.mjs +0 -407
  71. package/runtime/scripts/hfs/architecture/connection-map.mjs +0 -350
  72. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +0 -115
  73. package/runtime/scripts/hfs/architecture/context-coupling.mjs +0 -117
  74. package/runtime/scripts/hfs/architecture/context-map.mjs +0 -355
  75. package/runtime/scripts/hfs/architecture/context-owner.mjs +0 -102
  76. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +0 -65
  77. package/runtime/scripts/hfs/architecture/context-transaction.mjs +0 -75
  78. package/runtime/scripts/hfs/architecture/contract-bounds.mjs +0 -72
  79. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +0 -177
  80. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +0 -360
  81. package/runtime/scripts/hfs/architecture/contracts.mjs +0 -489
  82. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +0 -81
  83. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +0 -173
  84. package/runtime/scripts/hfs/architecture/dead-exports.mjs +0 -420
  85. package/runtime/scripts/hfs/architecture/default-deny.mjs +0 -175
  86. package/runtime/scripts/hfs/architecture/doc-language.mjs +0 -45
  87. package/runtime/scripts/hfs/architecture/entity-registry.mjs +0 -51
  88. package/runtime/scripts/hfs/architecture/entrypoint.mjs +0 -75
  89. package/runtime/scripts/hfs/architecture/error-codes.mjs +0 -54
  90. package/runtime/scripts/hfs/architecture/error-masked.mjs +0 -78
  91. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +0 -44
  92. package/runtime/scripts/hfs/architecture/feature-shape.mjs +0 -60
  93. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +0 -41
  94. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +0 -112
  95. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +0 -193
  96. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +0 -198
  97. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +0 -368
  98. package/runtime/scripts/hfs/architecture/frontend-world.mjs +0 -374
  99. package/runtime/scripts/hfs/architecture/frontend.mjs +0 -248
  100. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +0 -185
  101. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +0 -77
  102. package/runtime/scripts/hfs/architecture/hfs.mjs +0 -394
  103. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +0 -118
  104. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +0 -213
  105. package/runtime/scripts/hfs/architecture/identity.mjs +0 -121
  106. package/runtime/scripts/hfs/architecture/index.mjs +0 -402
  107. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +0 -69
  108. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +0 -231
  109. package/runtime/scripts/hfs/architecture/machine-ast.mjs +0 -232
  110. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +0 -32
  111. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +0 -237
  112. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +0 -126
  113. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +0 -192
  114. package/runtime/scripts/hfs/architecture/next-data-key.mjs +0 -374
  115. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +0 -26
  116. package/runtime/scripts/hfs/architecture/next-data.mjs +0 -425
  117. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +0 -55
  118. package/runtime/scripts/hfs/architecture/owners.mjs +0 -142
  119. package/runtime/scripts/hfs/architecture/package-shape.mjs +0 -92
  120. package/runtime/scripts/hfs/architecture/presentation.mjs +0 -173
  121. package/runtime/scripts/hfs/architecture/reachability.mjs +0 -330
  122. package/runtime/scripts/hfs/architecture/register-once.mjs +0 -212
  123. package/runtime/scripts/hfs/architecture/registration.mjs +0 -372
  124. package/runtime/scripts/hfs/architecture/render-graph.mjs +0 -449
  125. package/runtime/scripts/hfs/architecture/render-prop-across-server.mjs +0 -58
  126. package/runtime/scripts/hfs/architecture/required-files.mjs +0 -237
  127. package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
  128. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +0 -133
  129. package/runtime/scripts/hfs/architecture/schema-owner.mjs +0 -288
  130. package/runtime/scripts/hfs/architecture/server-action.mjs +0 -78
  131. package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
  132. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +0 -320
  133. package/runtime/scripts/hfs/architecture/source-names.mjs +0 -393
  134. package/runtime/scripts/hfs/architecture/sql-keys.mjs +0 -344
  135. package/runtime/scripts/hfs/architecture/sql-owner.mjs +0 -291
  136. package/runtime/scripts/hfs/architecture/sql-returning.mjs +0 -76
  137. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +0 -117
  138. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +0 -587
  139. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +0 -42
  140. package/runtime/scripts/hfs/architecture/surface-nesting.mjs +0 -127
  141. package/runtime/scripts/hfs/architecture/surface.mjs +0 -88
  142. package/runtime/scripts/hfs/architecture/symbols.mjs +0 -273
  143. package/runtime/scripts/hfs/architecture/test-world-files.mjs +0 -263
  144. package/runtime/scripts/hfs/architecture/tiers.mjs +0 -256
  145. package/runtime/scripts/hfs/architecture/transport-owner.mjs +0 -248
  146. package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
  147. package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
  148. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +0 -165
  149. package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
  150. package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
  151. package/runtime/scripts/hfs/edition-slots.mjs +0 -80
  152. package/runtime/scripts/hfs/explicit-surface-rule.mjs +0 -59
  153. package/runtime/scripts/hfs/linear-text.mjs +0 -30
  154. package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
  155. package/runtime/scripts/hfs/param-names.mjs +0 -13
  156. package/runtime/scripts/hfs/path-findings.mjs +0 -167
  157. package/runtime/scripts/hfs/repo-identity.mjs +0 -89
  158. package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
  159. package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
  160. package/runtime/scripts/hfs/rules/database-constants.mjs +0 -25
  161. package/runtime/scripts/hfs/rules/database-migrations.mjs +0 -684
  162. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +0 -68
  163. package/runtime/scripts/hfs/rules/read.mjs +0 -45
  164. package/runtime/scripts/hfs/rules/secrets.mjs +0 -79
  165. package/runtime/scripts/hfs/rules/spec-placement.mjs +0 -28
  166. package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
  167. package/runtime/scripts/hfs/slot-classify.mjs +0 -69
  168. package/runtime/scripts/hfs/slot-errors.mjs +0 -12
  169. package/runtime/scripts/hfs/slot-imports.mjs +0 -98
  170. package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
  171. package/runtime/scripts/hfs/slot-match.mjs +0 -164
  172. package/runtime/scripts/hfs/slot-path.mjs +0 -6
  173. package/runtime/scripts/hfs/slot-required.mjs +0 -95
  174. package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
  175. package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
  176. package/runtime/scripts/hfs/slots.mjs +0 -306
  177. package/runtime/scripts/hfs/test-world-slot.mjs +0 -5
  178. package/runtime/scripts/hfs/trailing-slashes.mjs +0 -8
  179. package/runtime/scripts/hfs/typescript-programs.mjs +0 -95
  180. package/runtime/scripts/hfs/view.mjs +0 -180
  181. package/runtime/scripts/lib/declaration-surface.mjs +0 -166
  182. package/runtime/scripts/lib/dockerfile.mjs +0 -164
  183. package/runtime/scripts/lib/env.mjs +0 -18
  184. package/runtime/scripts/lib/event-contract.mjs +0 -102
  185. package/runtime/scripts/lib/git-hooks-dir.mjs +0 -30
  186. package/runtime/scripts/lib/git.mjs +0 -35
  187. package/runtime/scripts/lib/glob.mjs +0 -32
  188. package/runtime/scripts/lib/grammar-lint.mjs +0 -57
  189. package/runtime/scripts/lib/i18n.mjs +0 -82
  190. package/runtime/scripts/lib/in-order.mjs +0 -90
  191. package/runtime/scripts/lib/json-clone.mjs +0 -70
  192. package/runtime/scripts/lib/json.mjs +0 -44
  193. package/runtime/scripts/lib/language.mjs +0 -233
  194. package/runtime/scripts/lib/list.mjs +0 -26
  195. package/runtime/scripts/lib/mutation-fence.mjs +0 -20
  196. package/runtime/scripts/lib/package-at.mjs +0 -62
  197. package/runtime/scripts/lib/path-key.mjs +0 -124
  198. package/runtime/scripts/lib/read-text.mjs +0 -47
  199. package/runtime/scripts/lib/regex.mjs +0 -3
  200. package/runtime/scripts/lib/rule-packs.mjs +0 -243
  201. package/runtime/scripts/lib/same-text.mjs +0 -4
  202. package/runtime/scripts/lib/secret-patterns.mjs +0 -230
  203. package/runtime/scripts/lib/sops-envelope.mjs +0 -212
  204. package/runtime/scripts/lib/stack-services.mjs +0 -191
  205. package/runtime/scripts/lib/ts-analysis.mjs +0 -39
  206. package/runtime/scripts/lib/ts-ast.mjs +0 -63
  207. package/runtime/scripts/lib/walk.mjs +0 -45
  208. package/runtime/scripts/lib/yaml-cached.mjs +0 -14
@@ -1,374 +0,0 @@
1
- import path from 'node:path';
2
- import { normalizedSymbolValue, returnedExpressions as sharedReturnedExpressions } from './ast-walks.mjs';
3
- import { reachableViolation, relativePath, unwrapExpression } from './typescript.mjs';
4
- import { WorldRenderAnalysis } from './frontend-world-render.mjs';
5
- const WORLD_NAVIGATION_CALLS = new Set(['useParams', 'usePathname', 'useRouter', 'useSearchParams', 'useSelectedLayoutSegment', 'useSelectedLayoutSegments']);
6
- const WORLD_INTL_CALLS = new Set(['useLocale', 'useMessages', 'useNow', 'useTimeZone', 'useTranslations']);
7
- const WORLD_SWR_CALLS = new Set(['default', 'useSWR', 'useSWRConfig', 'useSWRImmutable', 'useSWRMutation']);
8
- const LOWER_COMPONENT_TIERS = new Set(['frames', 'composites', 'branches', 'leaves']);
9
- function selectedSymbol(ts, checker, expression) {
10
- const selected = unwrapExpression(ts, expression);
11
- if (!selected)
12
- return null;
13
- if (ts.isIdentifier(selected))
14
- return checker.getSymbolAtLocation(selected) ?? null;
15
- if (ts.isPropertyAccessExpression(selected))
16
- return checker.getSymbolAtLocation(selected.name) ?? null;
17
- if (ts.isElementAccessExpression(selected) && ts.isStringLiteralLike(selected.argumentExpression)) {
18
- return checker.getSymbolAtLocation(selected.argumentExpression)
19
- ?? checker.getTypeAtLocation(selected.expression).getProperty(selected.argumentExpression.text)
20
- ?? null;
21
- }
22
- return null;
23
- }
24
- /* The wider boundary set: `ts.isFunctionLike` (includes call signatures' declarations) rather than the
25
- * four default callable kinds. */
26
- const returnedExpressions = (ts, declaration) => sharedReturnedExpressions(ts, declaration, { functionLike: ts.isFunctionLike });
27
- function knownWorldImport(specifier, imported) {
28
- if (specifier === 'next-intl')
29
- return WORLD_INTL_CALLS.has(imported);
30
- if (specifier === 'next/navigation' || /(?:^|\/)i18n\/navigation$/.test(specifier))
31
- return WORLD_NAVIGATION_CALLS.has(imported);
32
- if (specifier === 'swr' || specifier === 'swr/immutable' || specifier === 'swr/mutation')
33
- return WORLD_SWR_CALLS.has(imported);
34
- if (specifier === 'next-auth/react')
35
- return imported === 'useSession';
36
- return false;
37
- }
38
- class WorldAnalysis {
39
- config;
40
- context;
41
- roots;
42
- ts;
43
- violations;
44
- sourceSet;
45
- worldInfoCache;
46
- functionWorldCache;
47
- renderOutputCache;
48
- intrinsicUiHookCache;
49
- renderer;
50
- constructor(config, context, roots, helpers) {
51
- this.config = config;
52
- this.context = context;
53
- this.roots = roots;
54
- this.ts = context.ts;
55
- Object.assign(this, helpers);
56
- this.violations = [];
57
- this.sourceSet = new Set(context.files.map(source => path.resolve(source.fileName)));
58
- this.worldInfoCache = new Map();
59
- this.functionWorldCache = new Map();
60
- this.renderOutputCache = new Map();
61
- this.intrinsicUiHookCache = new Map();
62
- this.renderer = new WorldRenderAnalysis(this, { selectedSymbol, returnedExpressions });
63
- }
64
- /** The checker of a program source file (every file the analysis visits belongs to a loaded program). */
65
- checkerFor(fileName) {
66
- const checker = this.context.checkerFor(fileName);
67
- if (!checker)
68
- throw new Error(`No type checker holds ${fileName}.`);
69
- return checker;
70
- }
71
- forbiddenIntrinsicEdge(edge, nextVisiting) {
72
- const forbidden = reachableViolation(this.context.edges, edge, (target) => this.insideAny(this.roots.transport, target)
73
- || this.insideAny(this.roots.modules, target) || this.insideAny(this.roots.features, target) || this.insideAny(this.roots.routes, target)
74
- // insideAny held, so the hooks root exists.
75
- || (this.insideAny(this.roots.hooks, target) && relativePath(this.rootFor(this.roots.hooks, target), target).split('/')[0] !== 'ui'), { follow: (candidate) => candidate.runtime });
76
- return Boolean(forbidden || (this.insideAny(this.roots.hooks, edge.to) && !this.intrinsicUiHookFile(edge.to, nextVisiting)));
77
- }
78
- forbiddenWorldImport(statement) {
79
- if (!this.ts.isImportDeclaration(statement) || !statement.importClause || statement.importClause.isTypeOnly
80
- || !this.ts.isStringLiteralLike(statement.moduleSpecifier))
81
- return false;
82
- const specifier = statement.moduleSpecifier.text;
83
- const bindings = [];
84
- if (statement.importClause.name)
85
- bindings.push('default');
86
- const named = statement.importClause.namedBindings;
87
- if (named && this.ts.isNamespaceImport(named)
88
- && ['next/navigation', 'next-intl', 'swr', 'swr/immutable', 'swr/mutation', 'next-auth/react'].includes(specifier))
89
- return true;
90
- if (named && this.ts.isNamedImports(named)) {
91
- for (const element of named.elements)
92
- if (!element.isTypeOnly)
93
- bindings.push(element.propertyName?.text ?? element.name.text);
94
- }
95
- return bindings.some(imported => knownWorldImport(specifier, imported));
96
- }
97
- containsUnshadowedFetch(sourceFile, checker) {
98
- let found = false;
99
- const visit = (node) => {
100
- if (!found && this.ts.isCallExpression(node) && this.ts.isIdentifier(node.expression) && node.expression.text === 'fetch'
101
- && (checker.getSymbolAtLocation(node.expression)?.getDeclarations() ?? []).every(declaration => declaration.getSourceFile().isDeclarationFile))
102
- found = true;
103
- if (!found)
104
- this.ts.forEachChild(node, visit);
105
- };
106
- visit(sourceFile);
107
- return found;
108
- }
109
- intrinsicUiHookFile(fileName, visiting = new Set()) {
110
- const resolved = path.resolve(fileName);
111
- const cached = this.intrinsicUiHookCache.get(resolved);
112
- if (cached !== undefined)
113
- return cached;
114
- const hookRoot = this.rootFor(this.roots.hooks, resolved);
115
- if (!hookRoot || relativePath(hookRoot, resolved).split('/')[0] !== 'ui' || visiting.has(resolved))
116
- return false;
117
- const sourceFile = this.context.files.find(source => path.resolve(source.fileName) === resolved);
118
- if (!sourceFile)
119
- return false;
120
- this.intrinsicUiHookCache.set(resolved, false);
121
- const nextVisiting = new Set(visiting).add(resolved);
122
- const checker = this.checkerFor(resolved);
123
- const edges = this.importsForSource(this.context, resolved);
124
- let intrinsic = true;
125
- for (const edge of edges.filter(candidate => candidate.runtime)) {
126
- if (this.forbiddenIntrinsicEdge(edge, nextVisiting)) {
127
- intrinsic = false;
128
- break;
129
- }
130
- }
131
- for (const statement of sourceFile.statements) {
132
- if (!intrinsic)
133
- break;
134
- if (this.forbiddenWorldImport(statement)) {
135
- intrinsic = false;
136
- break;
137
- }
138
- }
139
- if (intrinsic && this.containsUnshadowedFetch(sourceFile, checker))
140
- intrinsic = false;
141
- this.intrinsicUiHookCache.set(resolved, intrinsic);
142
- return intrinsic;
143
- }
144
- intrinsicUiHookSymbol(symbol, checker) {
145
- const identity = normalizedSymbolValue(this.ts, checker, symbol);
146
- const declarations = identity?.getDeclarations?.() ?? [];
147
- return declarations.length > 0 && declarations.every(declaration => this.intrinsicUiHookFile(declaration.getSourceFile().fileName));
148
- }
149
- worldEdgeOf(edge) {
150
- return edge && Boolean(reachableViolation(this.context.edges, edge, (target) => this.insideAny(this.roots.hooks, target) || this.insideAny(this.roots.transport, target), { follow: (candidate) => candidate.reexport && candidate.runtime }));
151
- }
152
- collectNamedWorldImports(checker, named, specifier, worldEdge, symbols) {
153
- for (const element of named.elements) {
154
- if (element.isTypeOnly)
155
- continue;
156
- const imported = element.propertyName?.text ?? element.name.text;
157
- const symbol = checker.getSymbolAtLocation(element.name);
158
- if (symbol && (worldEdge || knownWorldImport(specifier, imported)))
159
- symbols.add(symbol);
160
- }
161
- }
162
- inspectWorldImportStatement(sourceFile, checker, byStart, symbols, namespaces, statement) {
163
- if (!this.ts.isImportDeclaration(statement) || !statement.importClause || statement.importClause.isTypeOnly
164
- || !this.ts.isStringLiteralLike(statement.moduleSpecifier))
165
- return;
166
- const specifier = statement.moduleSpecifier.text;
167
- const worldEdge = this.worldEdgeOf(byStart.get(statement.moduleSpecifier.getStart(sourceFile)));
168
- const clause = statement.importClause;
169
- if (clause.name) {
170
- const symbol = checker.getSymbolAtLocation(clause.name);
171
- if (symbol && (worldEdge || knownWorldImport(specifier, 'default')))
172
- symbols.add(symbol);
173
- }
174
- const named = clause.namedBindings;
175
- if (named && this.ts.isNamedImports(named))
176
- this.collectNamedWorldImports(checker, named, specifier, worldEdge, symbols);
177
- if (named && this.ts.isNamespaceImport(named)) {
178
- const symbol = checker.getSymbolAtLocation(named.name);
179
- if (symbol)
180
- namespaces.set(symbol, { specifier, worldEdge });
181
- }
182
- }
183
- importInfo(sourceFile) {
184
- const key = path.resolve(sourceFile.fileName);
185
- const cached = this.worldInfoCache.get(key);
186
- if (cached)
187
- return cached;
188
- const checker = this.checkerFor(sourceFile.fileName);
189
- const edges = this.importsForSource(this.context, sourceFile.fileName);
190
- const byStart = new Map(edges.map((edge) => [edge.node.getStart(sourceFile), edge]));
191
- const symbols = new Set();
192
- const namespaces = new Map();
193
- for (const statement of sourceFile.statements)
194
- this.inspectWorldImportStatement(sourceFile, checker, byStart, symbols, namespaces, statement);
195
- const value = { checker, symbols, namespaces };
196
- this.worldInfoCache.set(key, value);
197
- return value;
198
- }
199
- collectExpressionFunctions(declaration, checker, seen, functions) {
200
- if (this.ts.isFunctionDeclaration(declaration) || this.ts.isMethodDeclaration(declaration))
201
- functions.push(declaration);
202
- else if (this.ts.isVariableDeclaration(declaration) && declaration.initializer) {
203
- functions.push(...this.expressionFunctions(declaration.initializer, checker, seen));
204
- }
205
- else if (this.ts.isClassDeclaration(declaration)) {
206
- functions.push(...declaration.members.filter((member) => this.ts.isMethodDeclaration(member)
207
- && !!member.name && (this.ts.isIdentifier(member.name) || this.ts.isStringLiteralLike(member.name)) && member.name.text === 'render'));
208
- }
209
- }
210
- isComponentWrapperCall(call) {
211
- const selected = unwrapExpression(this.ts, call.expression);
212
- const name = (this.ts.isIdentifier(selected) && selected.text) || (this.ts.isPropertyAccessExpression(selected) && selected.name.text) || null;
213
- return name !== null && ['forwardRef', 'memo'].includes(name);
214
- }
215
- expressionFunctions(input, checker, seen = new Set()) {
216
- const expression = unwrapExpression(this.ts, input);
217
- if (!expression)
218
- return [];
219
- if (this.ts.isArrowFunction(expression) || this.ts.isFunctionExpression(expression) || this.ts.isMethodDeclaration(expression)
220
- || this.ts.isFunctionDeclaration(expression))
221
- return [expression];
222
- if (this.ts.isConditionalExpression(expression)) {
223
- return [...this.expressionFunctions(expression.whenTrue, checker, seen), ...this.expressionFunctions(expression.whenFalse, checker, seen)];
224
- }
225
- if (this.ts.isCallExpression(expression) && this.isComponentWrapperCall(expression) && expression.arguments[0]) {
226
- return this.expressionFunctions(expression.arguments[0], checker, seen);
227
- }
228
- const symbol = normalizedSymbolValue(this.ts, checker, selectedSymbol(this.ts, checker, expression));
229
- if (!symbol || seen.has(symbol))
230
- return [];
231
- const nextSeen = new Set(seen).add(symbol);
232
- const functions = [];
233
- for (const declaration of symbol.getDeclarations?.() ?? [])
234
- this.collectExpressionFunctions(declaration, checker, nextSeen, functions);
235
- return [...new Set(functions.filter(fn => fn.body))];
236
- }
237
- symbolIsWorld(raw, sourceFile, propertyName = null) {
238
- if (!raw)
239
- return false;
240
- const info = this.importInfo(sourceFile);
241
- if (this.intrinsicUiHookSymbol(raw, info.checker))
242
- return false;
243
- if (info.symbols.has(raw))
244
- return true;
245
- for (const [namespace, declaration] of info.namespaces)
246
- if (namespace === raw) {
247
- return declaration.worldEdge || knownWorldImport(declaration.specifier, propertyName ?? '');
248
- }
249
- const identity = normalizedSymbolValue(this.ts, info.checker, raw);
250
- return (identity?.getDeclarations?.() ?? []).some(declaration => {
251
- const fileName = declaration.getSourceFile().fileName;
252
- return this.insideAny(this.roots.hooks, fileName) || this.insideAny(this.roots.transport, fileName);
253
- });
254
- }
255
- namespaceIsWorld(raw, sourceFile, propertyName) {
256
- const info = this.importInfo(sourceFile);
257
- const declaration = raw ? info.namespaces.get(raw) : undefined;
258
- return Boolean(declaration && (declaration.worldEdge || knownWorldImport(declaration.specifier, propertyName ?? '')));
259
- }
260
- worldMemberCallee(expression, checker, sourceFile) {
261
- let property = null;
262
- if (this.ts.isPropertyAccessExpression(expression))
263
- property = expression.name.text;
264
- else if (this.ts.isStringLiteralLike(expression.argumentExpression))
265
- property = expression.argumentExpression.text;
266
- const namespace = checker.getSymbolAtLocation(expression.expression);
267
- if (this.intrinsicUiHookSymbol(selectedSymbol(this.ts, checker, expression), checker))
268
- return false;
269
- if (this.namespaceIsWorld(namespace, sourceFile, property))
270
- return true;
271
- return this.symbolIsWorld(selectedSymbol(this.ts, checker, expression), sourceFile);
272
- }
273
- worldVariableInitializer(symbol, checker, nextSeen) {
274
- for (const declaration of symbol.getDeclarations?.() ?? []) {
275
- if (this.ts.isVariableDeclaration(declaration) && declaration.initializer
276
- && this.calleeIsWorld(declaration.initializer, checker, declaration.getSourceFile(), nextSeen))
277
- return true;
278
- }
279
- return false;
280
- }
281
- calleeIsWorld(input, checker, sourceFile, seen = new Set()) {
282
- const expression = unwrapExpression(this.ts, input);
283
- if (this.ts.isIdentifier(expression) && this.symbolIsWorld(checker.getSymbolAtLocation(expression), sourceFile))
284
- return true;
285
- if (this.ts.isPropertyAccessExpression(expression) || this.ts.isElementAccessExpression(expression))
286
- if (this.worldMemberCallee(expression, checker, sourceFile))
287
- return true;
288
- const symbol = normalizedSymbolValue(this.ts, checker, selectedSymbol(this.ts, checker, expression));
289
- if (!symbol || seen.has(symbol))
290
- return false;
291
- const nextSeen = new Set(seen).add(symbol);
292
- if (this.worldVariableInitializer(symbol, checker, nextSeen))
293
- return true;
294
- return this.expressionFunctions(expression, checker).some(fn => this.functionUsesWorld(fn, checker, nextSeen));
295
- }
296
- callIsWorld(call, checker, sourceFile, seen) { return this.calleeIsWorld(call.expression, checker, sourceFile, seen); }
297
- functionUsesWorld(fn, checker, seen = new Set()) {
298
- const cached = this.functionWorldCache.get(fn);
299
- if (cached !== undefined)
300
- return cached;
301
- this.functionWorldCache.set(fn, false);
302
- let found = false;
303
- const sourceFile = fn.getSourceFile();
304
- const visit = (node) => {
305
- if (found)
306
- return;
307
- if (this.ts.isCallExpression(node) && this.callIsWorld(node, checker, sourceFile, seen)) {
308
- found = true;
309
- return;
310
- }
311
- this.ts.forEachChild(node, visit);
312
- };
313
- visit(fn.body ?? fn);
314
- this.functionWorldCache.set(fn, found);
315
- return found;
316
- }
317
- collectFunctionNodes(node, functions) {
318
- if (this.ts.isFunctionDeclaration(node) || this.ts.isMethodDeclaration(node) || this.ts.isArrowFunction(node) || this.ts.isFunctionExpression(node))
319
- functions.push(node);
320
- this.ts.forEachChild(node, child => this.collectFunctionNodes(child, functions));
321
- }
322
- inspectBlockProductHooks(sourceFile, checker, tier, functions) {
323
- for (const fn of functions) {
324
- const name = this.declarationName(this.ts, fn);
325
- if (tier?.tier === 'blocks' && name && /^use[A-Z0-9]/.test(name.text) && this.functionUsesWorld(fn, checker)) {
326
- this.violations.push(this.violation(this.config, sourceFile, name, 'FE_BLOCK_PRODUCT_HOOK_DEFINITION', 'A block may call a product hook from hooks but cannot define product-world or data lifecycle under the block.', { ts: this.ts }));
327
- }
328
- }
329
- }
330
- inspectWorldOwner(sourceFile, checker, tier, fn) {
331
- if (!this.renderer.functionHasRender(fn, checker) || !this.functionUsesWorld(fn, checker))
332
- return;
333
- const returned = returnedExpressions(this.ts, fn);
334
- if (!returned.length || returned.some(expression => !this.renderer.renderBoundary(expression, checker, new Set(), true))) {
335
- this.violations.push(this.violation(this.config, sourceFile, fn, 'FE_WORLD_OWNER_RENDER_BOUNDARY', 'A visual owner that reads product/world state must hand every render path to a statically resolved pure render function or component; intrinsic-only interaction does not select this rule.', { ts: this.ts }));
336
- }
337
- if (tier && LOWER_COMPONENT_TIERS.has(tier.tier)) {
338
- this.violations.push(this.violation(this.config, sourceFile, fn, 'FE_COMPONENT_WORLD_OWNERSHIP', `${tier.tier} may own intrinsic browser interaction but cannot own product-world, navigation, locale, session or data lifecycle.`, { ts: this.ts }));
339
- }
340
- if (tier?.tier === 'blocks')
341
- this.inspectConnectedBlock(sourceFile, checker, fn, returned);
342
- }
343
- inspectConnectedBlock(sourceFile, checker, fn, returned) {
344
- const expected = path.resolve(path.dirname(sourceFile.fileName), 'component.tsx');
345
- const index = path.basename(sourceFile.fileName).toLowerCase() === 'index.tsx';
346
- if (!index || !this.sourceSet.has(expected) || !returned.length
347
- || returned.some(expression => !this.renderer.renderBoundary(expression, checker, new Set(), true, expected))) {
348
- this.violations.push(this.violation(this.config, sourceFile, fn, 'FE_CONNECTED_BLOCK_RENDER_PAIR', 'A connected blocks/index.tsx must hand every nonempty render path to a resolved pure export from its sibling component.tsx; pure blocks and lower tiers need no twin.', { ts: this.ts }));
349
- }
350
- }
351
- inspectWorldOwners(sourceFile, checker, tier, functions) {
352
- for (const fn of functions)
353
- this.inspectWorldOwner(sourceFile, checker, tier, fn);
354
- }
355
- inspectSourceFile(sourceFile) {
356
- if ((!this.insideAny(this.roots.components, sourceFile.fileName) && !this.insideAny(this.roots.features, sourceFile.fileName))
357
- || !/\.[cm]?tsx$/i.test(sourceFile.fileName))
358
- return;
359
- const checker = this.checkerFor(sourceFile.fileName);
360
- const tier = this.tierOf(this.roots.components, sourceFile.fileName);
361
- const functions = [];
362
- this.collectFunctionNodes(sourceFile, functions);
363
- this.inspectBlockProductHooks(sourceFile, checker, tier, functions);
364
- this.inspectWorldOwners(sourceFile, checker, tier, functions);
365
- }
366
- check() {
367
- for (const sourceFile of this.context.files)
368
- this.inspectSourceFile(sourceFile);
369
- return this.violations;
370
- }
371
- }
372
- export function checkWorldRenderBoundaries(config, context, roots, helpers) {
373
- return new WorldAnalysis(config, context, roots, helpers).check();
374
- }
@@ -1,248 +0,0 @@
1
- import path from 'node:path';
2
- import { isInside } from './config.mjs';
3
- import { frameworkPinnedRootFiles } from './framework-pinned.mjs';
4
- import { reachableViolation, relativePath } from './typescript.mjs';
5
- import { normalizedSymbolValue } from './ast-walks.mjs';
6
- import { sourceLocation } from '../../lib/ts-ast.mjs';
7
- import { checkWorldRenderBoundaries } from './frontend-world.mjs';
8
- import { checkGrammar } from './frontend-grammar.mjs';
9
- import { checkRoute } from './frontend-routing.mjs';
10
- const FEATURE_TIERS = new Set(['pages', 'layouts', 'overlays']);
11
- const COMPONENT_TIERS = new Set(['blocks', 'frames', 'composites', 'branches', 'leaves', 'providers']);
12
- function absolute(root, relative) {
13
- return path.resolve(root, ...relative.split('/'));
14
- }
15
- function absoluteRoots(root, relatives) {
16
- return relatives.map(relative => absolute(root, relative)).sort((a, b) => b.length - a.length);
17
- }
18
- function rootFor(candidates, fileName) {
19
- return candidates.find(root => isInside(root, fileName)) ?? null;
20
- }
21
- function insideAny(candidates, fileName) {
22
- return Boolean(rootFor(candidates, fileName));
23
- }
24
- function tierOf(componentRoots, fileName) {
25
- const root = rootFor(componentRoots, fileName);
26
- if (!root)
27
- return null;
28
- const tier = relativePath(root, fileName).split('/')[0];
29
- return COMPONENT_TIERS.has(tier) ? { tier, root } : null;
30
- }
31
- function violation(config, sourceFile, node, ruleId, message, extra = {}) {
32
- return {
33
- ruleId,
34
- path: relativePath(config.root, sourceFile.fileName),
35
- ...sourceLocation(sourceFile, node),
36
- message,
37
- ...Object.fromEntries(Object.entries(extra).filter(([key]) => key !== 'ts')),
38
- };
39
- }
40
- function roleEntry(relative) {
41
- const parts = String(relative).replaceAll('\\', '/').split('/');
42
- return parts.length === 1 && /^index\.[cm]?[jt]sx?$/i.test(parts[0]);
43
- }
44
- function roleFor(roots, fileName) {
45
- for (const [role, candidates] of Object.entries(roots)) { // the role names filtered next are the string[] members
46
- if (!['routes', 'features', 'components', 'hooks', 'modules'].includes(role))
47
- continue;
48
- const root = rootFor(candidates, fileName);
49
- if (root)
50
- return { role, root, relative: relativePath(root, fileName) };
51
- }
52
- return null;
53
- }
54
- // The files Next.js loads only from the source root (the directory holding app/: src/ or the project
55
- // root) are authored in knowledge/patterns/fe/folder.yaml FE-FOLDER-1 and read by ./framework-pinned.mjs.
56
- export { FRAMEWORK_PINNED_KNOWLEDGE, frameworkPinnedRootFiles } from './framework-pinned.mjs';
57
- /** The source root that directly holds this file when it is a framework-pinned root file, else null. */
58
- function frameworkPinnedRoot(roots, fileName) {
59
- if (!roots.pinnedRootFiles.has(path.basename(fileName)))
60
- return null;
61
- const directory = path.resolve(path.dirname(fileName));
62
- return roots.sourceRoots.find(root => path.resolve(root) === directory) ?? null;
63
- }
64
- function checkFrontendSourceLayout(config, sourceFile, roots) {
65
- const located = roleFor(roots, sourceFile.fileName);
66
- if (!located && frameworkPinnedRoot(roots, sourceFile.fileName))
67
- return [];
68
- if (!located)
69
- return insideAny(roots.sourceRoots, sourceFile.fileName)
70
- ? [{ ruleId: 'FE_SOURCE_LAYOUT_INVALID', path: relativePath(config.root, sourceFile.fileName), line: 1, column: 1,
71
- message: 'Production source under a Next application root must belong to app, features, components, hooks or modules, or be a framework-pinned root file Next.js loads from the source root (knowledge/patterns/fe/folder.yaml FE-FOLDER-1 frameworkPinnedRootFiles); configuration cannot hide an unclassified owner.' }]
72
- : [];
73
- if (located.role === 'routes' || located.role === 'modules')
74
- return [];
75
- const first = located.relative.split('/')[0];
76
- let valid = true;
77
- if (located.role === 'features')
78
- valid = FEATURE_TIERS.has(first) || roleEntry(located.relative);
79
- if (located.role === 'components')
80
- valid = COMPONENT_TIERS.has(first) || roleEntry(located.relative);
81
- if (located.role === 'hooks')
82
- valid = located.relative.includes('/') || roleEntry(located.relative);
83
- return valid ? [] : [{ ruleId: 'FE_SOURCE_LAYOUT_INVALID', path: relativePath(config.root, sourceFile.fileName), line: 1, column: 1,
84
- message: { features: 'Frontend features contain only pages, layouts and overlays plus an optional root public entry.',
85
- components: 'Frontend components contain only blocks, frames, composites, branches, leaves and providers plus an optional root public entry.',
86
- hooks: 'Every authored custom hook is grouped below a domain folder under hooks; only the root public entry may sit directly under hooks.' }[located.role] }];
87
- }
88
- function declarationName(ts, declaration) {
89
- if ((ts.isFunctionDeclaration(declaration) || ts.isMethodDeclaration(declaration) || ts.isVariableDeclaration(declaration))
90
- && declaration.name && ts.isIdentifier(declaration.name))
91
- return declaration.name;
92
- if ((ts.isArrowFunction(declaration) || ts.isFunctionExpression(declaration))
93
- && ts.isVariableDeclaration(declaration.parent) && ts.isIdentifier(declaration.parent.name))
94
- return declaration.parent.name;
95
- return null;
96
- }
97
- const HOOK_NAME = /^use[A-Z0-9]/;
98
- function reportCustomHook(state, symbol, node) {
99
- const { ts, checker, seen, violations, config, sourceFile } = state;
100
- const identity = normalizedSymbolValue(ts, checker, symbol) ?? symbol;
101
- if (!identity || seen.has(identity) || checker.getTypeOfSymbolAtLocation(identity, node).getCallSignatures().length === 0)
102
- return;
103
- seen.add(identity);
104
- violations.push(violation(config, sourceFile, node, 'FE_CUSTOM_HOOK_LOCATION', 'Every authored custom useX hook declaration belongs under the configured hooks root; calling built-in React hooks inside a visual is still valid.', { ts }));
105
- }
106
- function inspectHookDeclaration(state, declaration) {
107
- const name = declarationName(state.ts, declaration);
108
- if (!name || !HOOK_NAME.test(name.text))
109
- return;
110
- const symbol = state.checker.getSymbolAtLocation(name);
111
- reportCustomHook(state, symbol, name);
112
- }
113
- function visitHookDeclarations(state, node) {
114
- const { ts } = state;
115
- if (ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node) || ts.isVariableDeclaration(node))
116
- inspectHookDeclaration(state, node);
117
- ts.forEachChild(node, child => visitHookDeclarations(state, child));
118
- }
119
- function reportExportedHooks(state) {
120
- const { ts, checker, sourceFile } = state;
121
- const module = checker.getSymbolAtLocation(sourceFile);
122
- for (const exposed of module ? checker.getExportsOfModule(module) : []) {
123
- if (!HOOK_NAME.test(exposed.name))
124
- continue;
125
- const identity = normalizedSymbolValue(ts, checker, exposed);
126
- for (const declaration of identity?.getDeclarations?.() ?? []) {
127
- if (declaration.getSourceFile() !== sourceFile)
128
- continue;
129
- reportCustomHook(state, identity, declarationName(ts, declaration) ?? declaration);
130
- }
131
- }
132
- }
133
- /** True when the slot that owns this file names it as its `hooks` role (redux/hooks.ts, modules/toast/hooks.ts): the owner's own typed hooks. */
134
- function slotHooksRole(config, fileName) {
135
- const found = config.hfs?.classifyPath?.(relativePath(config.root, fileName));
136
- const role = found?.slot ? config.hfs.slot(found.slot)?.roles?.hooks : undefined;
137
- return typeof role === 'string' && path.basename(fileName) === role;
138
- }
139
- function checkCustomHookLocations(config, context, sourceFile, roots) {
140
- if (insideAny(roots.hooks, sourceFile.fileName) || slotHooksRole(config, sourceFile.fileName))
141
- return [];
142
- const { ts } = context;
143
- const state = { ts, config, sourceFile, checker: context.checkerFor(sourceFile.fileName), violations: [], seen: new Set() };
144
- visitHookDeclarations(state, sourceFile);
145
- reportExportedHooks(state);
146
- return state.violations;
147
- }
148
- function importsForSource(context, fileName) {
149
- return context.edges.get(path.resolve(fileName)) ?? [];
150
- }
151
- function inspectComponentEdge(config, context, roots, fileName, pure, edge, violations) {
152
- if (!edge.runtime)
153
- return;
154
- const configuredHookBarrel = insideAny(roots.hooks, edge.to) && /^index\.[cm]?[jt]sx?$/i.test(path.basename(edge.to));
155
- const hookChain = configuredHookBarrel ? null
156
- : reachableViolation(context.edges, edge, target => insideAny(roots.hooks, target), { follow: candidate => candidate.reexport && candidate.runtime });
157
- if (hookChain) {
158
- violations.push({ ruleId: 'FE_COMPONENT_DEEP_HOOK_IMPORT', path: relativePath(config.root, fileName), line: edge.line, column: edge.column,
159
- specifier: edge.specifier, resolvedPath: relativePath(config.root, hookChain.at(-1)), dependencyChain: hookChain.map(item => relativePath(config.root, item)),
160
- message: 'Components must enter data hooks through the owning hooks barrel.' });
161
- }
162
- if (pure)
163
- inspectPureDataReachability(config, context, roots, fileName, edge, violations);
164
- }
165
- function inspectPureDataReachability(config, context, roots, fileName, edge, violations) {
166
- const chain = reachableViolation(context.edges, edge, target => insideAny(roots.hooks, target) || insideAny(roots.transport, target), { follow: candidate => candidate.reexport && candidate.runtime });
167
- if (chain)
168
- violations.push({ ruleId: 'FE_PURE_REACHES_DATA', path: relativePath(config.root, fileName), line: edge.line, column: edge.column,
169
- specifier: edge.specifier, resolvedPath: relativePath(config.root, chain.at(-1)), dependencyChain: chain.map(item => relativePath(config.root, item)),
170
- message: 'Pure component.tsx cannot reach hooks or API transport through an alias, relative import, package, or barrel.' });
171
- }
172
- function reportWorldHookImports(config, sourceFile, named, state, violation) {
173
- const { ts, worldHooks, violations } = state;
174
- for (const element of named.elements) {
175
- const imported = element.propertyName?.text ?? element.name.text;
176
- if (!element.isTypeOnly && worldHooks.has(imported))
177
- violations.push(violation(config, sourceFile, element, 'FE_PURE_WORLD_HOOK', `Pure component.tsx imports ${imported}; its connected index.tsx owns application/world state.`, { ts }));
178
- }
179
- }
180
- function recordReactNamespaces(ts, clause, named, reactNamespaces) {
181
- if (clause?.name)
182
- reactNamespaces.add(clause.name.text);
183
- if (named && ts.isNamespaceImport(named))
184
- reactNamespaces.add(named.name.text);
185
- }
186
- function inspectPureImport(config, sourceFile, statement, state, violation) {
187
- const { ts, reactNamespaces, violations } = state;
188
- if (!ts.isImportDeclaration(statement) || !ts.isStringLiteralLike(statement.moduleSpecifier) || statement.importClause?.isTypeOnly)
189
- return;
190
- const source = statement.moduleSpecifier.text;
191
- const named = statement.importClause?.namedBindings;
192
- if (source === 'react') {
193
- if (named && ts.isNamedImports(named))
194
- reportWorldHookImports(config, sourceFile, named, state, violation);
195
- recordReactNamespaces(ts, statement.importClause, named, reactNamespaces);
196
- }
197
- if ((source === 'next/navigation' || source === 'next-intl') && statement.importClause) {
198
- violations.push(violation(config, sourceFile, statement, 'FE_PURE_WORLD_IMPORT', `Pure component.tsx imports ${source}; its connected index.tsx owns router and locale context.`, { ts }));
199
- }
200
- }
201
- function inspectPureWorldHookAccess(config, sourceFile, node, state, violation) {
202
- const { ts, worldHooks, reactNamespaces, violations } = state;
203
- if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression) && reactNamespaces.has(node.expression.text)
204
- && worldHooks.has(node.name.text)) {
205
- violations.push(violation(config, sourceFile, node, 'FE_PURE_WORLD_HOOK', `Pure component.tsx accesses ${node.expression.text}.${node.name.text}; its connected index.tsx owns application/world state.`, { ts }));
206
- }
207
- ts.forEachChild(node, child => inspectPureWorldHookAccess(config, sourceFile, child, state, violation));
208
- }
209
- function inspectPureModule(config, context, sourceFile, violations, violation) {
210
- const ts = context.ts;
211
- const state = { ts, worldHooks: new Set(['createContext', 'useContext', 'useSyncExternalStore']), reactNamespaces: new Set(), violations };
212
- for (const statement of sourceFile.statements)
213
- inspectPureImport(config, sourceFile, statement, state, violation);
214
- inspectPureWorldHookAccess(config, sourceFile, sourceFile, state, violation);
215
- }
216
- function checkPureAndData(config, context, sourceFile, roots) {
217
- const violations = [];
218
- const fileName = path.resolve(sourceFile.fileName);
219
- if (!insideAny(roots.components, fileName))
220
- return violations;
221
- const pure = path.basename(fileName).toLowerCase() === 'component.tsx';
222
- for (const edge of importsForSource(context, fileName))
223
- inspectComponentEdge(config, context, roots, fileName, pure, edge, violations);
224
- if (pure)
225
- inspectPureModule(config, context, sourceFile, violations, violation);
226
- return violations;
227
- }
228
- /** Enforce route adapters, UI responsibility tiers, pure/connected, and transport boundaries. */
229
- export function checkFrontend(config, context) {
230
- const worldRoots = {
231
- routes: absoluteRoots(config.root, config.frontend.routes),
232
- features: absoluteRoots(config.root, config.frontend.features),
233
- components: absoluteRoots(config.root, config.frontend.components),
234
- hooks: absoluteRoots(config.root, config.frontend.hooks),
235
- modules: absoluteRoots(config.root, config.frontend.modules),
236
- transport: absoluteRoots(config.root, config.frontend.transport),
237
- };
238
- const roots = { ...worldRoots, sourceRoots: [...new Set(worldRoots.routes.map(root => path.dirname(root)))], pinnedRootFiles: frameworkPinnedRootFiles() };
239
- const violations = checkGrammar(config, context, violation);
240
- for (const sourceFile of context.files) {
241
- if (insideAny(roots.routes, sourceFile.fileName) && path.basename(sourceFile.fileName).toLowerCase() === 'page.tsx') {
242
- violations.push(...checkRoute(config, context, sourceFile, roots, { violation, insideAny, importsForSource }));
243
- }
244
- violations.push(...checkFrontendSourceLayout(config, sourceFile, roots), ...checkCustomHookLocations(config, context, sourceFile, roots), ...checkPureAndData(config, context, sourceFile, roots));
245
- }
246
- violations.push(...checkWorldRenderBoundaries(config, context, roots, { insideAny, rootFor, tierOf, violation, declarationName, importsForSource }));
247
- return violations;
248
- }