@starci/eslint-canon-be 3.8.20 → 3.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/package.json +1 -1
  3. package/runtime/bundle.json +192 -0
  4. package/runtime/engine/by-code-unit.mjs +6 -6
  5. package/runtime/engine/model-config.mjs +98 -76
  6. package/runtime/engine/orca-config.mjs +22 -17
  7. package/runtime/engine/release-config.mjs +22 -18
  8. package/runtime/engine/removed-vocabulary.mjs +21 -20
  9. package/runtime/engine/resources-config.mjs +42 -35
  10. package/runtime/engine/runtime-root.mjs +11 -13
  11. package/runtime/engine/secrets.mjs +170 -102
  12. package/runtime/engine/sonar-config.mjs +16 -13
  13. package/runtime/engine/temp-root.mjs +3 -9
  14. package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
  15. package/runtime/knowledge/hfs/rules.yaml +6 -6
  16. package/runtime/knowledge/hfs/slots.yaml +2 -2
  17. package/runtime/knowledge/sonar-gate.yaml +1 -1
  18. package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
  19. package/runtime/scripts/api/git/cat-file.mjs +0 -1
  20. package/runtime/scripts/api/git/config-get.mjs +1 -2
  21. package/runtime/scripts/api/git/diff.mjs +0 -1
  22. package/runtime/scripts/api/git/lib.mjs +32 -32
  23. package/runtime/scripts/api/git/ls-files.mjs +0 -1
  24. package/runtime/scripts/api/git/ls-tree.mjs +0 -1
  25. package/runtime/scripts/api/git/merge-base.mjs +2 -3
  26. package/runtime/scripts/api/git/remote.mjs +0 -1
  27. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
  28. package/runtime/scripts/api/git/show.mjs +0 -1
  29. package/runtime/scripts/hfs/allows.mjs +37 -38
  30. package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
  31. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
  32. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
  33. package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
  34. package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
  35. package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
  36. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
  37. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
  38. package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
  39. package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
  40. package/runtime/scripts/hfs/architecture/config.mjs +302 -268
  41. package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
  42. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
  43. package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
  44. package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
  45. package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
  46. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
  47. package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
  48. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
  49. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
  50. package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
  51. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
  52. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
  53. package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
  54. package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
  55. package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
  56. package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
  57. package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
  58. package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
  59. package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
  60. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
  61. package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
  62. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
  63. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
  64. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
  65. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
  66. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
  67. package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
  68. package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
  69. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
  70. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
  71. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
  72. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
  73. package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
  74. package/runtime/scripts/hfs/architecture/index.mjs +272 -272
  75. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
  76. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
  77. package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
  78. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
  79. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
  80. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
  81. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
  82. package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
  83. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
  84. package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
  85. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
  86. package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
  87. package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
  88. package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
  89. package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
  90. package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
  91. package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
  92. package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
  93. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
  94. package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
  95. package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
  96. package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
  97. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
  98. package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
  99. package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
  100. package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
  101. package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
  102. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
  103. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
  104. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
  105. package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
  106. package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
  107. package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
  108. package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
  109. package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
  110. package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
  111. package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
  112. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
  113. package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
  114. package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
  115. package/runtime/scripts/hfs/edition-slots.mjs +43 -40
  116. package/runtime/scripts/hfs/linear-text.mjs +20 -20
  117. package/runtime/scripts/hfs/param-names.mjs +6 -11
  118. package/runtime/scripts/hfs/path-findings.mjs +120 -100
  119. package/runtime/scripts/hfs/repo-identity.mjs +55 -42
  120. package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
  121. package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
  122. package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
  123. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
  124. package/runtime/scripts/hfs/rules/read.mjs +19 -15
  125. package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
  126. package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
  127. package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
  128. package/runtime/scripts/hfs/slot-classify.mjs +42 -38
  129. package/runtime/scripts/hfs/slot-errors.mjs +8 -7
  130. package/runtime/scripts/hfs/slot-imports.mjs +70 -63
  131. package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
  132. package/runtime/scripts/hfs/slot-match.mjs +122 -111
  133. package/runtime/scripts/hfs/slot-path.mjs +0 -2
  134. package/runtime/scripts/hfs/slot-required.mjs +65 -59
  135. package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
  136. package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
  137. package/runtime/scripts/hfs/slots.mjs +175 -152
  138. package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
  139. package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
  140. package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
  141. package/runtime/scripts/hfs/view.mjs +38 -40
  142. package/runtime/scripts/lib/dockerfile.mjs +131 -114
  143. package/runtime/scripts/lib/env.mjs +3 -6
  144. package/runtime/scripts/lib/event-contract.mjs +73 -78
  145. package/runtime/scripts/lib/git.mjs +15 -16
  146. package/runtime/scripts/lib/glob.mjs +23 -14
  147. package/runtime/scripts/lib/grammar-lint.mjs +33 -37
  148. package/runtime/scripts/lib/i18n.mjs +32 -35
  149. package/runtime/scripts/lib/in-order.mjs +57 -38
  150. package/runtime/scripts/lib/json-clone.mjs +45 -36
  151. package/runtime/scripts/lib/json.mjs +26 -14
  152. package/runtime/scripts/lib/language.mjs +133 -129
  153. package/runtime/scripts/lib/list.mjs +9 -14
  154. package/runtime/scripts/lib/mutation-fence.mjs +10 -5
  155. package/runtime/scripts/lib/path-key.mjs +53 -38
  156. package/runtime/scripts/lib/read-text.mjs +30 -17
  157. package/runtime/scripts/lib/regex.mjs +1 -2
  158. package/runtime/scripts/lib/same-text.mjs +0 -1
  159. package/runtime/scripts/lib/sops-envelope.mjs +148 -120
  160. package/runtime/scripts/lib/stack-services.mjs +128 -129
  161. package/runtime/scripts/lib/ts-analysis.mjs +28 -26
  162. package/runtime/scripts/lib/ts-ast.mjs +36 -42
  163. package/runtime/scripts/lib/walk.mjs +33 -27
  164. package/runtime/scripts/lib/yaml-cached.mjs +4 -4
@@ -9,250 +9,240 @@ import { checkGrammar } from './frontend-grammar.mjs';
9
9
  import { checkRoute } from './frontend-routing.mjs';
10
10
  const FEATURE_TIERS = new Set(['pages', 'layouts', 'overlays']);
11
11
  const COMPONENT_TIERS = new Set(['blocks', 'composites', 'branches', 'leaves', 'providers']);
12
-
13
12
  function absolute(root, relative) {
14
- return path.resolve(root, ...relative.split('/'));
13
+ return path.resolve(root, ...relative.split('/'));
15
14
  }
16
-
17
15
  function absoluteRoots(root, relatives) {
18
- return relatives.map(relative => absolute(root, relative)).sort((a, b) => b.length - a.length);
16
+ return relatives.map(relative => absolute(root, relative)).sort((a, b) => b.length - a.length);
19
17
  }
20
-
21
18
  function rootFor(candidates, fileName) {
22
- return candidates.find(root => isInside(root, fileName)) ?? null;
19
+ return candidates.find(root => isInside(root, fileName)) ?? null;
23
20
  }
24
-
25
21
  function insideAny(candidates, fileName) {
26
- return Boolean(rootFor(candidates, fileName));
22
+ return Boolean(rootFor(candidates, fileName));
27
23
  }
28
-
29
24
  function tierOf(componentRoots, fileName) {
30
- const root = rootFor(componentRoots, fileName);
31
- if (!root) return null;
32
- const tier = relativePath(root, fileName).split('/')[0];
33
- return COMPONENT_TIERS.has(tier) ? { tier, root } : null;
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;
34
30
  }
35
-
36
- function featureTierOf(featureRoots, fileName) {
37
- const root = rootFor(featureRoots, fileName);
38
- if (!root) return null;
39
- const tier = relativePath(root, fileName).split('/')[0];
40
- return FEATURE_TIERS.has(tier) ? { tier, root } : null;
41
- }
42
-
43
31
  function violation(config, sourceFile, node, ruleId, message, extra = {}) {
44
- return {
45
- ruleId,
46
- path: relativePath(config.root, sourceFile.fileName),
47
- ...sourceLocation(sourceFile, node),
48
- message,
49
- ...Object.fromEntries(Object.entries(extra).filter(([key]) => key !== 'ts')),
50
- };
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
+ };
51
39
  }
52
-
53
40
  function roleEntry(relative) {
54
- const parts = String(relative).replaceAll('\\', '/').split('/');
55
- return parts.length === 1 && /^index\.[cm]?[jt]sx?$/i.test(parts[0]);
41
+ const parts = String(relative).replaceAll('\\', '/').split('/');
42
+ return parts.length === 1 && /^index\.[cm]?[jt]sx?$/i.test(parts[0]);
56
43
  }
57
-
58
44
  function roleFor(roots, fileName) {
59
- for (const [role, candidates] of Object.entries(roots)) {
60
- if (!['routes', 'features', 'components', 'hooks', 'modules'].includes(role)) continue;
61
- const root = rootFor(candidates, fileName);
62
- if (root) return { role, root, relative: relativePath(root, fileName) };
63
- }
64
- return null;
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;
65
53
  }
66
-
67
54
  // The files Next.js loads only from the source root (the directory holding app/: src/ or the project
68
55
  // root) are authored in knowledge/patterns/fe/folder.yaml FE-FOLDER-1 and read by ./framework-pinned.mjs.
69
56
  export { FRAMEWORK_PINNED_KNOWLEDGE, frameworkPinnedRootFiles } from './framework-pinned.mjs';
70
-
71
57
  /** The source root that directly holds this file when it is a framework-pinned root file, else null. */
72
58
  function frameworkPinnedRoot(roots, fileName) {
73
- if (!roots.pinnedRootFiles.has(path.basename(fileName))) return null;
74
- const directory = path.resolve(path.dirname(fileName));
75
- return roots.sourceRoots.find(root => path.resolve(root) === directory) ?? null;
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;
76
63
  }
77
-
78
64
  function checkFrontendSourceLayout(config, sourceFile, roots) {
79
- const located = roleFor(roots, sourceFile.fileName);
80
- if (!located && frameworkPinnedRoot(roots, sourceFile.fileName)) return [];
81
- if (!located) return insideAny(roots.sourceRoots, sourceFile.fileName)
82
- ? [{ ruleId: 'FE_SOURCE_LAYOUT_INVALID', path: relativePath(config.root, sourceFile.fileName), line: 1, column: 1,
83
- 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.' }]
84
- : [];
85
- if (located.role === 'routes' || located.role === 'modules') return [];
86
- const first = located.relative.split('/')[0];
87
- let valid = true;
88
- if (located.role === 'features') valid = FEATURE_TIERS.has(first) || roleEntry(located.relative);
89
- if (located.role === 'components') valid = COMPONENT_TIERS.has(first) || roleEntry(located.relative);
90
- if (located.role === 'hooks') valid = located.relative.includes('/') || roleEntry(located.relative);
91
- return valid ? [] : [{ ruleId: 'FE_SOURCE_LAYOUT_INVALID', path: relativePath(config.root, sourceFile.fileName), line: 1, column: 1,
92
- message: ({ features: 'Frontend features contain only pages, layouts and overlays plus an optional root public entry.',
93
- components: 'Frontend components contain only blocks, composites, branches, leaves and providers plus an optional root public entry.',
94
- 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] }];
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, 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] }];
95
87
  }
96
-
97
88
  function declarationName(ts, declaration) {
98
- if ((ts.isFunctionDeclaration(declaration) || ts.isMethodDeclaration(declaration) || ts.isVariableDeclaration(declaration))
99
- && declaration.name && ts.isIdentifier(declaration.name)) return declaration.name;
100
- if ((ts.isArrowFunction(declaration) || ts.isFunctionExpression(declaration))
101
- && ts.isVariableDeclaration(declaration.parent) && ts.isIdentifier(declaration.parent.name)) return declaration.parent.name;
102
- return null;
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;
103
96
  }
104
-
105
97
  const HOOK_NAME = /^use[A-Z0-9]/;
106
-
107
98
  function reportCustomHook(state, symbol, node) {
108
- const { ts, checker, seen, violations, config, sourceFile } = state;
109
- const identity = normalizedSymbolValue(ts, checker, symbol) ?? symbol;
110
- if (!identity || seen.has(identity) || checker.getTypeOfSymbolAtLocation(identity, node).getCallSignatures().length === 0) return;
111
- seen.add(identity);
112
- violations.push(violation(config, sourceFile, node, 'FE_CUSTOM_HOOK_LOCATION',
113
- 'Every authored custom useX hook declaration belongs under the configured hooks root; calling built-in React hooks inside a visual is still valid.', { ts }));
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 }));
114
105
  }
115
-
116
106
  function inspectHookDeclaration(state, declaration) {
117
- const name = declarationName(state.ts, declaration);
118
- if (!name || !HOOK_NAME.test(name.text)) return;
119
- const symbol = state.checker.getSymbolAtLocation(name);
120
- reportCustomHook(state, symbol, name);
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);
121
112
  }
122
-
123
113
  function visitHookDeclarations(state, node) {
124
- const { ts } = state;
125
- if (ts.isFunctionDeclaration(node) || ts.isMethodDeclaration(node) || ts.isVariableDeclaration(node)) inspectHookDeclaration(state, node);
126
- ts.forEachChild(node, child => visitHookDeclarations(state, child));
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));
127
118
  }
128
-
129
119
  function reportExportedHooks(state) {
130
- const { ts, checker, sourceFile } = state;
131
- const module = checker.getSymbolAtLocation(sourceFile);
132
- for (const exposed of module ? checker.getExportsOfModule(module) : []) {
133
- if (!HOOK_NAME.test(exposed.name)) continue;
134
- const identity = normalizedSymbolValue(ts, checker, exposed);
135
- for (const declaration of identity?.getDeclarations?.() ?? []) {
136
- if (declaration.getSourceFile() !== sourceFile) continue;
137
- reportCustomHook(state, identity, declarationName(ts, declaration) ?? declaration);
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
+ }
138
131
  }
139
- }
140
132
  }
141
-
142
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. */
143
134
  function slotHooksRole(config, fileName) {
144
- const found = config.hfs?.classifyPath?.(relativePath(config.root, fileName));
145
- const role = found?.slot ? config.hfs.slot(found.slot)?.roles?.hooks : undefined;
146
- return typeof role === 'string' && path.basename(fileName) === role;
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;
147
138
  }
148
-
149
139
  function checkCustomHookLocations(config, context, sourceFile, roots) {
150
- if (insideAny(roots.hooks, sourceFile.fileName) || slotHooksRole(config, sourceFile.fileName)) return [];
151
- const { ts } = context;
152
- const state = { ts, config, sourceFile, checker: context.checkerFor(sourceFile.fileName), violations: [], seen: new Set() };
153
- visitHookDeclarations(state, sourceFile);
154
- reportExportedHooks(state);
155
- return state.violations;
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;
156
147
  }
157
-
158
148
  function importsForSource(context, fileName) {
159
- return context.edges.get(path.resolve(fileName)) ?? [];
149
+ return context.edges.get(path.resolve(fileName)) ?? [];
160
150
  }
161
-
162
151
  function inspectComponentEdge(config, context, roots, fileName, pure, edge, violations) {
163
- if (!edge.runtime) return;
164
- const configuredHookBarrel = insideAny(roots.hooks, edge.to) && /^index\.[cm]?[jt]sx?$/i.test(path.basename(edge.to));
165
- const hookChain = configuredHookBarrel ? null
166
- : reachableViolation(context.edges, edge, target => insideAny(roots.hooks, target), { follow: candidate => candidate.reexport && candidate.runtime });
167
- if (hookChain) {
168
- violations.push({ ruleId: 'FE_COMPONENT_DEEP_HOOK_IMPORT', path: relativePath(config.root, fileName), line: edge.line, column: edge.column,
169
- specifier: edge.specifier, resolvedPath: relativePath(config.root, hookChain.at(-1)), dependencyChain: hookChain.map(item => relativePath(config.root, item)),
170
- message: 'Components must enter data hooks through the owning hooks barrel.' });
171
- }
172
- if (pure) inspectPureDataReachability(config, context, roots, fileName, 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);
173
164
  }
174
-
175
165
  function inspectPureDataReachability(config, context, roots, fileName, edge, violations) {
176
- const chain = reachableViolation(context.edges, edge, target => insideAny(roots.hooks, target) || insideAny(roots.transport, target),
177
- { follow: candidate => candidate.reexport && candidate.runtime });
178
- if (chain) violations.push({ ruleId: 'FE_PURE_REACHES_DATA', path: relativePath(config.root, fileName), line: edge.line, column: edge.column,
179
- specifier: edge.specifier, resolvedPath: relativePath(config.root, chain.at(-1)), dependencyChain: chain.map(item => relativePath(config.root, item)),
180
- message: 'Pure component.tsx cannot reach hooks or API transport through an alias, relative import, package, or barrel.' });
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.' });
181
171
  }
182
-
183
172
  function reportWorldHookImports(config, sourceFile, named, state, violation) {
184
- const { ts, worldHooks, violations } = state;
185
- for (const element of named.elements) {
186
- const imported = element.propertyName?.text ?? element.name.text;
187
- if (!element.isTypeOnly && worldHooks.has(imported)) violations.push(violation(config, sourceFile, element, 'FE_PURE_WORLD_HOOK', `Pure component.tsx imports ${imported}; its connected index.tsx owns application/world state.`, { ts }));
188
- }
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
+ }
189
179
  }
190
-
191
180
  function recordReactNamespaces(ts, clause, named, reactNamespaces) {
192
- if (clause?.name) reactNamespaces.add(clause.name.text);
193
- if (named && ts.isNamespaceImport(named)) reactNamespaces.add(named.name.text);
181
+ if (clause?.name)
182
+ reactNamespaces.add(clause.name.text);
183
+ if (named && ts.isNamespaceImport(named))
184
+ reactNamespaces.add(named.name.text);
194
185
  }
195
-
196
186
  function inspectPureImport(config, sourceFile, statement, state, violation) {
197
- const { ts, reactNamespaces, violations } = state;
198
- if (!ts.isImportDeclaration(statement) || !ts.isStringLiteralLike(statement.moduleSpecifier) || statement.importClause?.isTypeOnly) return;
199
- const source = statement.moduleSpecifier.text;
200
- const named = statement.importClause?.namedBindings;
201
- if (source === 'react') {
202
- if (named && ts.isNamedImports(named)) reportWorldHookImports(config, sourceFile, named, state, violation);
203
- recordReactNamespaces(ts, statement.importClause, named, reactNamespaces);
204
- }
205
- if ((source === 'next/navigation' || source === 'next-intl') && statement.importClause) {
206
- 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 }));
207
- }
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
+ }
208
200
  }
209
-
210
201
  function inspectPureWorldHookAccess(config, sourceFile, node, state, violation) {
211
- const { ts, worldHooks, reactNamespaces, violations } = state;
212
- if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression) && reactNamespaces.has(node.expression.text)
213
- && worldHooks.has(node.name.text)) {
214
- 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 }));
215
- }
216
- ts.forEachChild(node, child => inspectPureWorldHookAccess(config, sourceFile, child, 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));
217
208
  }
218
-
219
209
  function inspectPureModule(config, context, sourceFile, violations, violation) {
220
- const ts = context.ts;
221
- const state = { ts, worldHooks: new Set(['createContext', 'useContext', 'useSyncExternalStore']), reactNamespaces: new Set(), violations };
222
- for (const statement of sourceFile.statements) inspectPureImport(config, sourceFile, statement, state, violation);
223
- inspectPureWorldHookAccess(config, sourceFile, sourceFile, state, 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);
224
215
  }
225
-
226
216
  function checkPureAndData(config, context, sourceFile, roots) {
227
- const violations = [];
228
- const fileName = path.resolve(sourceFile.fileName);
229
- if (!insideAny(roots.components, fileName)) return violations;
230
- const pure = path.basename(fileName).toLowerCase() === 'component.tsx';
231
- for (const edge of importsForSource(context, fileName)) inspectComponentEdge(config, context, roots, fileName, pure, edge, violations);
232
- if (pure) inspectPureModule(config, context, sourceFile, violations, violation);
233
- return violations;
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;
234
227
  }
235
-
236
-
237
228
  /** Enforce route adapters, UI responsibility tiers, pure/connected, and transport boundaries. */
238
229
  export function checkFrontend(config, context) {
239
- const roots = {
240
- routes: absoluteRoots(config.root, config.frontend.routes),
241
- features: absoluteRoots(config.root, config.frontend.features),
242
- components: absoluteRoots(config.root, config.frontend.components),
243
- hooks: absoluteRoots(config.root, config.frontend.hooks),
244
- modules: absoluteRoots(config.root, config.frontend.modules),
245
- transport: absoluteRoots(config.root, config.frontend.transport),
246
- };
247
- roots.sourceRoots = [...new Set(roots.routes.map(root => path.dirname(root)))];
248
- roots.pinnedRootFiles = frameworkPinnedRootFiles();
249
- const violations = checkGrammar(config, context, violation);
250
- for (const sourceFile of context.files) {
251
- if (insideAny(roots.routes, sourceFile.fileName) && path.basename(sourceFile.fileName).toLowerCase() === 'page.tsx') {
252
- violations.push(...checkRoute(config, context, sourceFile, roots, { violation, insideAny, importsForSource }));
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));
253
245
  }
254
- violations.push(...checkFrontendSourceLayout(config, sourceFile, roots), ...checkCustomHookLocations(config, context, sourceFile, roots), ...checkPureAndData(config, context, sourceFile, roots));
255
- }
256
- violations.push(...checkWorldRenderBoundaries(config, context, roots, { insideAny, rootFor, tierOf, violation, declarationName, importsForSource }));
257
- return violations;
246
+ violations.push(...checkWorldRenderBoundaries(config, context, roots, { insideAny, rootFor, tierOf, violation, declarationName, importsForSource }));
247
+ return violations;
258
248
  }