@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
@@ -1,143 +1,176 @@
1
- /** Imported JSX components receive repeated data contracts; executable prop values remain compared. */
2
1
  import { unwrapExpression as unwrap } from '../../lib/ts-analysis.mjs';
3
-
4
2
  const TRANSLATION_MODULES = new Set(['next-intl', 'next-intl/server']);
5
3
  const TRANSLATION_FACTORIES = new Set(['useTranslations', 'getTranslations']);
6
4
  const uppercase = (name) => /^[A-Z]/.test(name);
7
-
8
5
  function bindName(ts, scope, name, binding) {
9
- if (ts.isIdentifier(name)) scope.bindings.set(name.text, binding);
10
- else if (ts.isObjectBindingPattern(name) || ts.isArrayBindingPattern(name)) {
11
- for (const element of name.elements) if (ts.isBindingElement(element)) bindName(ts, scope, element.name, binding);
12
- }
6
+ if (ts.isIdentifier(name))
7
+ scope.bindings.set(name.text, binding);
8
+ else if (ts.isObjectBindingPattern(name) || ts.isArrayBindingPattern(name)) {
9
+ for (const element of name.elements)
10
+ if (ts.isBindingElement(element))
11
+ bindName(ts, scope, element.name, binding);
12
+ }
13
13
  }
14
-
15
14
  function importBindings(ts, scope, statement) {
16
- const clause = statement.importClause;
17
- if (!clause || clause.isTypeOnly || !ts.isStringLiteral(statement.moduleSpecifier)) return;
18
- const module = statement.moduleSpecifier.text;
19
- if (clause.name) scope.bindings.set(clause.name.text, { kind: 'component' });
20
- const named = clause.namedBindings;
21
- if (!named) return;
22
- if (ts.isNamespaceImport(named)) scope.bindings.set(named.name.text, { kind: 'namespace', module });
23
- else for (const element of named.elements) {
24
- if (element.isTypeOnly) continue;
25
- const imported = element.propertyName?.text ?? element.name.text;
26
- const kind = TRANSLATION_MODULES.has(module) && TRANSLATION_FACTORIES.has(imported) ? 'translation-factory' : 'component';
27
- scope.bindings.set(element.name.text, { kind });
28
- }
15
+ const clause = statement.importClause;
16
+ if (!clause || clause.isTypeOnly || !ts.isStringLiteral(statement.moduleSpecifier))
17
+ return;
18
+ const module = statement.moduleSpecifier.text;
19
+ if (clause.name)
20
+ scope.bindings.set(clause.name.text, { kind: 'component' });
21
+ const named = clause.namedBindings;
22
+ if (!named)
23
+ return;
24
+ if (ts.isNamespaceImport(named))
25
+ scope.bindings.set(named.name.text, { kind: 'namespace', module });
26
+ else
27
+ for (const element of named.elements) {
28
+ if (element.isTypeOnly)
29
+ continue;
30
+ const imported = element.propertyName?.text ?? element.name.text;
31
+ const kind = TRANSLATION_MODULES.has(module) && TRANSLATION_FACTORIES.has(imported) ? 'translation-factory' : 'component';
32
+ scope.bindings.set(element.name.text, { kind });
33
+ }
29
34
  }
30
-
31
35
  function lexicalBindings(ts, sourceFile) {
32
- const scopes = new WeakMap();
33
- const root = { parent: null, bindings: new Map() };
34
- root.functionScope = root;
35
- const visit = (node, outer) => {
36
- if ((ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)) && node.name) bindName(ts, outer, node.name, { kind: 'local' });
37
- const functionScope = ts.isFunctionLike(node);
38
- const nested = functionScope || ts.isBlock(node) || ts.isCatchClause(node) || ts.isClassExpression(node)
39
- || ts.isForStatement(node) || ts.isForOfStatement(node) || ts.isForInStatement(node);
40
- const scope = nested ? { parent: outer, bindings: new Map(), functionScope: functionScope ? null : outer.functionScope } : outer;
41
- if (functionScope) scope.functionScope = scope;
42
- scopes.set(node, scope);
43
- if (ts.isImportDeclaration(node)) importBindings(ts, scope, node);
44
- if (ts.isParameter(node)) bindName(ts, scope, node.name, { kind: 'local' });
45
- if (ts.isFunctionExpression(node) && node.name) bindName(ts, scope, node.name, { kind: 'local' });
46
- if (ts.isVariableDeclaration(node)) {
47
- const flags = node.parent?.flags ?? ts.NodeFlags.Const;
48
- bindName(ts, flags & ts.NodeFlags.BlockScoped ? scope : scope.functionScope, node.name,
49
- { kind: flags & ts.NodeFlags.Const ? 'constant' : 'local', declaration: node });
50
- }
51
- ts.forEachChild(node, (child) => { visit(child, scope); });
52
- };
53
- visit(sourceFile, root);
54
- return (identifier) => {
55
- for (let scope = scopes.get(identifier); scope; scope = scope.parent) {
56
- if (scope.bindings.has(identifier.text)) return scope.bindings.get(identifier.text);
57
- }
58
- return null;
59
- };
36
+ const scopes = new WeakMap();
37
+ const root = { parent: null, bindings: new Map(), functionScope: null };
38
+ root.functionScope = root;
39
+ const visit = (node, outer) => {
40
+ if ((ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node)) && node.name)
41
+ bindName(ts, outer, node.name, { kind: 'local' });
42
+ const functionScope = ts.isFunctionLike(node);
43
+ const nested = functionScope || ts.isBlock(node) || ts.isCatchClause(node) || ts.isClassExpression(node)
44
+ || ts.isForStatement(node) || ts.isForOfStatement(node) || ts.isForInStatement(node);
45
+ const scope = nested ? { parent: outer, bindings: new Map(), functionScope: functionScope ? null : outer.functionScope } : outer;
46
+ if (functionScope)
47
+ scope.functionScope = scope;
48
+ scopes.set(node, scope);
49
+ if (ts.isImportDeclaration(node))
50
+ importBindings(ts, scope, node);
51
+ if (ts.isParameter(node))
52
+ bindName(ts, scope, node.name, { kind: 'local' });
53
+ if (ts.isFunctionExpression(node) && node.name)
54
+ bindName(ts, scope, node.name, { kind: 'local' });
55
+ if (ts.isVariableDeclaration(node)) {
56
+ const flags = node.parent?.flags ?? ts.NodeFlags.Const;
57
+ bindName(ts, flags & ts.NodeFlags.BlockScoped ? scope : scope.functionScope, node.name, { kind: flags & ts.NodeFlags.Const ? 'constant' : 'local', declaration: node });
58
+ }
59
+ ts.forEachChild(node, (child) => { visit(child, scope); });
60
+ };
61
+ visit(sourceFile, root);
62
+ return (identifier) => {
63
+ for (let scope = scopes.get(identifier); scope; scope = scope.parent) {
64
+ if (scope.bindings.has(identifier.text))
65
+ return scope.bindings.get(identifier.text);
66
+ }
67
+ return null;
68
+ };
60
69
  }
61
-
62
70
  function translationFactory(ts, node, bindingOf) {
63
- node = unwrap(ts, node);
64
- if (ts.isIdentifier(node)) return bindingOf(node)?.kind === 'translation-factory';
65
- return ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression)
66
- && TRANSLATION_FACTORIES.has(node.name.text) && bindingOf(node.expression)?.kind === 'namespace'
67
- && TRANSLATION_MODULES.has(bindingOf(node.expression).module);
71
+ node = unwrap(ts, node);
72
+ if (ts.isIdentifier(node))
73
+ return bindingOf(node)?.kind === 'translation-factory';
74
+ if (!(ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression) && TRANSLATION_FACTORIES.has(node.name.text)))
75
+ return false;
76
+ const namespace = bindingOf(node.expression);
77
+ return namespace?.kind === 'namespace' && TRANSLATION_MODULES.has(namespace.module);
68
78
  }
69
-
70
79
  function translator(ts, node, bindingOf) {
71
- if (!ts.isIdentifier(node)) return false;
72
- const binding = bindingOf(node);
73
- if (binding?.kind !== 'constant') return false;
74
- let initializer = unwrap(ts, binding.declaration.initializer);
75
- if (initializer && ts.isAwaitExpression(initializer)) initializer = unwrap(ts, initializer.expression);
76
- return Boolean(initializer && ts.isCallExpression(initializer) && translationFactory(ts, initializer.expression, bindingOf));
80
+ if (!ts.isIdentifier(node))
81
+ return false;
82
+ const binding = bindingOf(node);
83
+ if (binding?.kind !== 'constant')
84
+ return false;
85
+ let initializer = unwrap(ts, binding.declaration.initializer);
86
+ if (initializer && ts.isAwaitExpression(initializer))
87
+ initializer = unwrap(ts, initializer.expression);
88
+ return Boolean(initializer && ts.isCallExpression(initializer) && translationFactory(ts, initializer.expression, bindingOf));
77
89
  }
78
-
79
90
  function importedComponent(ts, tag, bindingOf) {
80
- if (ts.isIdentifier(tag)) return uppercase(tag.text) && bindingOf(tag)?.kind === 'component';
81
- if (!ts.isPropertyAccessExpression(tag) || !uppercase(tag.name.text)) return false;
82
- let root = tag.expression;
83
- while (ts.isPropertyAccessExpression(root)) root = root.expression;
84
- return ts.isIdentifier(root) && bindingOf(root)?.kind === 'namespace';
91
+ if (ts.isIdentifier(tag))
92
+ return uppercase(tag.text) && bindingOf(tag)?.kind === 'component';
93
+ if (!ts.isPropertyAccessExpression(tag) || !uppercase(tag.name.text))
94
+ return false;
95
+ let root = tag.expression;
96
+ while (ts.isPropertyAccessExpression(root))
97
+ root = root.expression;
98
+ return ts.isIdentifier(root) && bindingOf(root)?.kind === 'namespace';
85
99
  }
86
-
87
100
  function dataProperty(ts, property, mapping) {
88
- if (ts.isSpreadAssignment(property)) return mapping(property.expression);
89
- if (ts.isShorthandPropertyAssignment(property)) return !property.objectAssignmentInitializer;
90
- if (!ts.isPropertyAssignment(property)) return false;
91
- return (!ts.isComputedPropertyName(property.name) || mapping(property.name.expression)) && mapping(property.initializer);
101
+ if (ts.isSpreadAssignment(property))
102
+ return mapping(property.expression);
103
+ if (ts.isShorthandPropertyAssignment(property))
104
+ return !property.objectAssignmentInitializer;
105
+ if (!ts.isPropertyAssignment(property))
106
+ return false;
107
+ return (!ts.isComputedPropertyName(property.name) || mapping(property.name.expression)) && mapping(property.initializer);
92
108
  }
93
-
94
109
  function dataMapping(ts, expression, bindingOf) {
95
- const node = unwrap(ts, expression);
96
- if (!node) return false;
97
- const mapping = (value) => dataMapping(ts, value, bindingOf);
98
- if (ts.isIdentifier(node) || ts.isLiteralExpression(node) || node.kind === ts.SyntaxKind.TrueKeyword
99
- || node.kind === ts.SyntaxKind.FalseKeyword || node.kind === ts.SyntaxKind.NullKeyword || node.kind === ts.SyntaxKind.ThisKeyword) return true;
100
- if (ts.isPropertyAccessExpression(node)) return mapping(node.expression);
101
- if (ts.isElementAccessExpression(node)) return mapping(node.expression) && mapping(node.argumentExpression);
102
- if (ts.isObjectLiteralExpression(node)) return node.properties.every((property) => dataProperty(ts, property, mapping));
103
- if (ts.isArrayLiteralExpression(node)) return node.elements.every((element) => ts.isOmittedExpression(element)
104
- || mapping(ts.isSpreadElement(element) ? element.expression : element));
105
- if (ts.isTemplateExpression(node)) return node.templateSpans.every((span) => mapping(span.expression));
106
- if (ts.isPrefixUnaryExpression(node)) return [ts.SyntaxKind.PlusToken, ts.SyntaxKind.MinusToken].includes(node.operator)
107
- && ts.isNumericLiteral(node.operand);
108
- return ts.isCallExpression(node) && translator(ts, node.expression, bindingOf) && node.arguments.every(mapping);
110
+ const node = unwrap(ts, expression);
111
+ if (!node)
112
+ return false;
113
+ const mapping = (value) => dataMapping(ts, value, bindingOf);
114
+ if (ts.isIdentifier(node) || ts.isLiteralExpression(node) || node.kind === ts.SyntaxKind.TrueKeyword
115
+ || node.kind === ts.SyntaxKind.FalseKeyword || node.kind === ts.SyntaxKind.NullKeyword || node.kind === ts.SyntaxKind.ThisKeyword)
116
+ return true;
117
+ if (ts.isPropertyAccessExpression(node))
118
+ return mapping(node.expression);
119
+ if (ts.isElementAccessExpression(node))
120
+ return mapping(node.expression) && mapping(node.argumentExpression);
121
+ if (ts.isObjectLiteralExpression(node))
122
+ return node.properties.every((property) => dataProperty(ts, property, mapping));
123
+ if (ts.isArrayLiteralExpression(node))
124
+ return node.elements.every((element) => ts.isOmittedExpression(element)
125
+ || mapping(ts.isSpreadElement(element) ? element.expression : element));
126
+ if (ts.isTemplateExpression(node))
127
+ return node.templateSpans.every((span) => mapping(span.expression));
128
+ if (ts.isPrefixUnaryExpression(node))
129
+ return [ts.SyntaxKind.PlusToken, ts.SyntaxKind.MinusToken].includes(node.operator)
130
+ && ts.isNumericLiteral(node.operand);
131
+ return ts.isCallExpression(node) && translator(ts, node.expression, bindingOf) && node.arguments.every(mapping);
109
132
  }
110
-
111
133
  /** Only object/array values belong to the prop contract; do not descend into a call or function body. */
112
134
  function nestedDataObjects(ts, expression, bindingOf, excluded) {
113
- const node = unwrap(ts, expression);
114
- if (!node) return;
115
- if (ts.isObjectLiteralExpression(node)) {
116
- if (dataMapping(ts, node, bindingOf)) { excluded.add(node); return; }
117
- for (const property of node.properties) if (ts.isPropertyAssignment(property)) {
118
- nestedDataObjects(ts, property.initializer, bindingOf, excluded);
135
+ const node = unwrap(ts, expression);
136
+ if (!node)
137
+ return;
138
+ if (ts.isObjectLiteralExpression(node)) {
139
+ if (dataMapping(ts, node, bindingOf)) {
140
+ excluded.add(node);
141
+ return;
142
+ }
143
+ for (const property of node.properties)
144
+ if (ts.isPropertyAssignment(property)) {
145
+ nestedDataObjects(ts, property.initializer, bindingOf, excluded);
146
+ }
147
+ }
148
+ else if (ts.isArrayLiteralExpression(node)) {
149
+ for (const element of node.elements)
150
+ if (!ts.isSpreadElement(element))
151
+ nestedDataObjects(ts, element, bindingOf, excluded);
119
152
  }
120
- } else if (ts.isArrayLiteralExpression(node)) {
121
- for (const element of node.elements) if (!ts.isSpreadElement(element)) nestedDataObjects(ts, element, bindingOf, excluded);
122
- }
123
153
  }
124
-
125
154
  /** Canon data prop objects qualify through an imported component binding, never its chosen name or file path. */
126
155
  export function canonJsxCloneNodes(ts, sourceFile) {
127
- const bindingOf = lexicalBindings(ts, sourceFile);
128
- const excluded = new Set();
129
- const visit = (node) => {
130
- if ((ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) && importedComponent(ts, node.tagName, bindingOf)) {
131
- for (const attribute of node.attributes.properties) {
132
- if (!ts.isJsxAttribute(attribute) || !attribute.initializer || !ts.isJsxExpression(attribute.initializer)) continue;
133
- const value = unwrap(ts, attribute.initializer.expression);
134
- if (!value || !ts.isObjectLiteralExpression(value)) continue;
135
- if (dataMapping(ts, value, bindingOf)) excluded.add(attribute);
136
- else nestedDataObjects(ts, value, bindingOf, excluded);
137
- }
138
- }
139
- ts.forEachChild(node, visit);
140
- };
141
- visit(sourceFile);
142
- return excluded;
156
+ const bindingOf = lexicalBindings(ts, sourceFile);
157
+ const excluded = new Set();
158
+ const visit = (node) => {
159
+ if ((ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) && importedComponent(ts, node.tagName, bindingOf)) {
160
+ for (const attribute of node.attributes.properties) {
161
+ if (!ts.isJsxAttribute(attribute) || !attribute.initializer || !ts.isJsxExpression(attribute.initializer))
162
+ continue;
163
+ const value = unwrap(ts, attribute.initializer.expression);
164
+ if (!value || !ts.isObjectLiteralExpression(value))
165
+ continue;
166
+ if (dataMapping(ts, value, bindingOf))
167
+ excluded.add(attribute);
168
+ else
169
+ nestedDataObjects(ts, value, bindingOf, excluded);
170
+ }
171
+ }
172
+ ts.forEachChild(node, visit);
173
+ };
174
+ visit(sourceFile);
175
+ return excluded;
143
176
  }
@@ -1,6 +1,5 @@
1
1
  import { builtinModules } from 'node:module';
2
2
  import { sourceLocation } from '../../lib/ts-ast.mjs';
3
-
4
3
  /**
5
4
  * R55 `client-reaches-server` (FE_CLIENT_REACHES_SERVER), the repository half of the eslint rule `client-no-server-import`,
6
5
  * which sees one hop from a file that carries the directive. The machine walks the resolved import graph from every module
@@ -15,84 +14,89 @@ import { sourceLocation } from '../../lib/ts-ast.mjs';
15
14
  * `type`, and `export type` re-exports are skipped.
16
15
  */
17
16
  export const CLIENT_REACHES_SERVER_RULE_IDS = ['FE_CLIENT_REACHES_SERVER'];
18
-
19
17
  const RULE = 'FE_CLIENT_REACHES_SERVER';
20
18
  const SERVER_MODULES = new Set(['server-only', 'next/headers', 'next/server', 'next-intl/server']);
21
19
  const NODE_BUILTINS = new Set(builtinModules.map(name => name.replace(/^node:/u, '').split('/')[0]));
22
-
23
- const isServerSpecifier = specifier => SERVER_MODULES.has(specifier) || specifier.startsWith('node:') || NODE_BUILTINS.has(specifier.split('/')[0]);
20
+ const isServerSpecifier = (specifier) => SERVER_MODULES.has(specifier) || specifier.startsWith('node:') || NODE_BUILTINS.has(specifier.split('/')[0]);
24
21
  const isClientEntry = (ts, file) => {
25
- for (const statement of file.sourceFile.statements) {
26
- if (!ts.isExpressionStatement(statement) || !ts.isStringLiteral(statement.expression)) return false;
27
- if (statement.expression.text === 'use client') return true;
28
- }
29
- return false;
22
+ for (const statement of file.sourceFile.statements) {
23
+ if (!ts.isExpressionStatement(statement) || !ts.isStringLiteral(statement.expression))
24
+ return false;
25
+ if (statement.expression.text === 'use client')
26
+ return true;
27
+ }
28
+ return false;
30
29
  };
31
-
32
30
  const reachesBundle = (ts, declaration) => {
33
- if (ts.isImportDeclaration(declaration)) {
34
- const clause = declaration.importClause;
35
- if (!clause) return true;
36
- if (clause.isTypeOnly) return false;
37
- if (!clause.name && clause.namedBindings && ts.isNamedImports(clause.namedBindings)) {
38
- const elements = clause.namedBindings.elements;
39
- return elements.length === 0 || !elements.every(element => element.isTypeOnly);
31
+ if (ts.isImportDeclaration(declaration)) {
32
+ const clause = declaration.importClause;
33
+ if (!clause)
34
+ return true;
35
+ if (clause.isTypeOnly)
36
+ return false;
37
+ if (!clause.name && clause.namedBindings && ts.isNamedImports(clause.namedBindings)) {
38
+ const elements = clause.namedBindings.elements;
39
+ return elements.length === 0 || !elements.every(element => element.isTypeOnly);
40
+ }
41
+ return true;
40
42
  }
41
- return true;
42
- }
43
- return !declaration.isTypeOnly;
43
+ return !declaration.isTypeOnly;
44
44
  };
45
-
46
45
  const serverImports = (ts, file) => {
47
- const found = [];
48
- const visit = node => {
49
- let specifier = null;
50
- if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier && reachesBundle(ts, node)) specifier = node.moduleSpecifier;
51
- else if (ts.isCallExpression(node) && (node.expression.kind === ts.SyntaxKind.ImportKeyword || (ts.isIdentifier(node.expression) && node.expression.text === 'require'))) specifier = node.arguments[0];
52
- if (specifier && ts.isStringLiteralLike(specifier) && isServerSpecifier(specifier.text)) found.push({ specifier: specifier.text, node });
53
- ts.forEachChild(node, visit);
54
- };
55
- visit(file.sourceFile);
56
- return found;
46
+ const found = [];
47
+ const visit = (node) => {
48
+ let specifier = null;
49
+ if ((ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier && reachesBundle(ts, node))
50
+ specifier = node.moduleSpecifier;
51
+ else if (ts.isCallExpression(node) && (node.expression.kind === ts.SyntaxKind.ImportKeyword || (ts.isIdentifier(node.expression) && node.expression.text === 'require')))
52
+ specifier = node.arguments[0];
53
+ if (specifier && ts.isStringLiteralLike(specifier) && isServerSpecifier(specifier.text))
54
+ found.push({ specifier: specifier.text, node });
55
+ ts.forEachChild(node, visit);
56
+ };
57
+ visit(file.sourceFile);
58
+ return found;
57
59
  };
58
-
59
- const scanClientEntry = (entry, { ts, graph, runtime, violations }) => {
60
- const seen = new Map([[entry.rel, { chain: [entry.rel], first: null }]]);
61
- const queue = [entry.rel];
62
- for (const rel of queue) {
63
- const state = seen.get(rel);
64
- for (const hit of runtime.serverOf(rel)) {
65
- const at = state.first ?? sourceLocation(graph.files.get(rel).sourceFile, hit.node);
66
- violations.push({
67
- ruleId: RULE, path: entry.rel, line: at.line, column: at.column, clientEntry: entry.rel, importer: rel, specifier: hit.specifier, dependencyChain: state.chain,
68
- message: `${entry.rel} is a client module ("use client") and reaches ${hit.specifier} through ${[...state.chain, hit.specifier].join(' -> ')}; a server-only surface never enters the client bundle. Read on the server and pass the value down, or move the import out of the client graph.`,
69
- });
70
- }
71
- for (const edge of runtime.edges.get(rel) ?? []) {
72
- if (seen.has(edge.to)) continue;
73
- seen.set(edge.to, { chain: [...state.chain, edge.to], first: state.first ?? { line: edge.line, column: edge.column } });
74
- queue.push(edge.to);
60
+ const scanClientEntry = (entry, { graph, runtime, violations }) => {
61
+ const seen = new Map([[entry.rel, { chain: [entry.rel], first: null }]]);
62
+ const queue = [entry.rel];
63
+ for (const rel of queue) {
64
+ const state = seen.get(rel); // every queued module was recorded in `seen` when it was queued
65
+ for (const hit of runtime.serverOf(rel)) {
66
+ const at = state.first ?? sourceLocation(graph.files.get(rel).sourceFile, hit.node);
67
+ violations.push({
68
+ ruleId: RULE, path: entry.rel, line: at.line, column: at.column, clientEntry: entry.rel, importer: rel, specifier: hit.specifier, dependencyChain: state.chain,
69
+ message: `${entry.rel} is a client module ("use client") and reaches ${hit.specifier} through ${[...state.chain, hit.specifier].join(' -> ')}; a server-only surface never enters the client bundle. Read on the server and pass the value down, or move the import out of the client graph.`,
70
+ });
71
+ }
72
+ for (const edge of runtime.edges.get(rel) ?? []) {
73
+ if (seen.has(edge.to))
74
+ continue;
75
+ seen.set(edge.to, { chain: [...state.chain, edge.to], first: state.first ?? { line: edge.line, column: edge.column } });
76
+ queue.push(edge.to);
77
+ }
75
78
  }
76
- }
77
79
  };
78
-
79
80
  export function checkClientReachesServer({ graph, context }) {
80
- const ts = context.ts;
81
- const runtime = new Map();
82
- for (const edge of graph.edges) {
83
- if (!edge.runtime) continue;
84
- if (!runtime.has(edge.from)) runtime.set(edge.from, []);
85
- runtime.get(edge.from).push(edge);
86
- }
87
- const serverByFile = new Map();
88
- const serverOf = rel => {
89
- if (!serverByFile.has(rel)) serverByFile.set(rel, serverImports(ts, graph.files.get(rel)));
90
- return serverByFile.get(rel);
91
- };
92
-
93
- const violations = [];
94
- const entries = [...graph.files.values()].filter(file => isClientEntry(ts, file)).sort((a, b) => a.rel.localeCompare(b.rel));
95
- const scanRuntime = { ts, graph, edges: runtime, serverOf, violations };
96
- for (const entry of entries) scanClientEntry(entry, { ts, graph, runtime: scanRuntime, violations });
97
- return { violations, coverage: { status: 'checked', clientEntries: entries.length } };
81
+ const ts = context.ts;
82
+ const runtime = new Map();
83
+ for (const edge of graph.edges) {
84
+ if (!edge.runtime)
85
+ continue;
86
+ if (!runtime.has(edge.from))
87
+ runtime.set(edge.from, []);
88
+ runtime.get(edge.from)?.push(edge);
89
+ }
90
+ const serverByFile = new Map();
91
+ const serverOf = (rel) => {
92
+ if (!serverByFile.has(rel))
93
+ serverByFile.set(rel, serverImports(ts, graph.files.get(rel)));
94
+ return serverByFile.get(rel);
95
+ };
96
+ const violations = [];
97
+ const entries = [...graph.files.values()].filter(file => isClientEntry(ts, file)).sort((a, b) => a.rel.localeCompare(b.rel));
98
+ const scanRuntime = { ts, graph, edges: runtime, serverOf, violations };
99
+ for (const entry of entries)
100
+ scanClientEntry(entry, { graph, runtime: scanRuntime, violations });
101
+ return { violations, coverage: { status: 'checked', clientEntries: entries.length } };
98
102
  }