@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
- /** An element access whose argument is a string literal: `a['b']`. */
2
- const isStringKeyedAccess = (ts, node) => ts.isElementAccessExpression(node) && ts.isStringLiteralLike(node.argumentExpression);
3
- function accessPath(deps, ts, checker, node) {
4
- node = deps.unwrapExpression(ts, node);
5
- if (ts.isIdentifier(node))
6
- return { symbol: deps.normalizedSymbol(ts, checker, node), parts: [node.text] };
7
- if (ts.isPropertyAccessExpression(node)) {
8
- const base = accessPath(deps, ts, checker, node.expression);
9
- return base ? { symbol: base.symbol, parts: [...base.parts, node.name.text] } : null;
10
- }
11
- if (ts.isElementAccessExpression(node) && ts.isStringLiteralLike(node.argumentExpression)) {
12
- const base = accessPath(deps, ts, checker, node.expression);
13
- return base ? { symbol: base.symbol, parts: [...base.parts, node.argumentExpression.text] } : null;
14
- }
15
- return null;
16
- }
17
- function expandedIdentifierPath(deps, ts, checker, node, seen, depth) {
18
- const symbol = deps.normalizedSymbol(ts, checker, node);
19
- if (!symbol || seen.has(symbol))
20
- return symbol ? { symbol, parts: [node.text] } : null;
21
- const initializer = deps.constInitializer(ts, symbol);
22
- return initializer ? expandedAccessPath(deps, ts, checker, initializer, new Set(seen).add(symbol), depth + 1)
23
- ?? { symbol, parts: [node.text] } : { symbol, parts: [node.text] };
24
- }
25
- function expandedMemberPath(deps, ts, checker, node, seen, depth) {
26
- const base = expandedAccessPath(deps, ts, checker, node.expression, seen, depth + 1);
27
- if (!base)
28
- return null;
29
- const part = ts.isPropertyAccessExpression(node) ? node.name.text : node.argumentExpression.text;
30
- return { symbol: base.symbol, parts: [...base.parts, part] };
31
- }
32
- function expandedAccessPath(deps, ts, checker, node, seen = new Set(), depth = 0) {
33
- if (!node || depth > 10)
34
- return null;
35
- node = deps.unwrapExpression(ts, node);
36
- if (ts.isIdentifier(node))
37
- return expandedIdentifierPath(deps, ts, checker, node, seen, depth);
38
- if (ts.isPropertyAccessExpression(node))
39
- return expandedMemberPath(deps, ts, checker, node, seen, depth);
40
- if (isStringKeyedAccess(ts, node))
41
- return expandedMemberPath(deps, ts, checker, node, seen, depth);
42
- return null;
43
- }
44
- function matchesIdentityAccess(deps, ts, checker, node, identity) {
45
- const matches = (access) => access !== null && access.symbol === identity.symbol && access.parts.length >= identity.parts.length
46
- && identity.parts.every((part, index) => access.parts[index] === part);
47
- return matches(accessPath(deps, ts, checker, node)) || matches(expandedAccessPath(deps, ts, checker, node));
48
- }
49
- const expressionReferences = (deps, ts, checker, expression, identity) => deps.anyDescendant(ts, expression, (node) => matchesIdentityAccess(deps, ts, checker, node, identity));
50
- function propertyKey(ts, name) {
51
- if (ts.isIdentifier(name) || ts.isStringLiteralLike(name) || ts.isNumericLiteral(name))
52
- return name.text;
53
- return null;
54
- }
55
- function effectiveObjectValues(ts, expression) {
56
- const selected = new Map();
57
- for (let index = expression.properties.length - 1; index >= 0; index -= 1) {
58
- const property = expression.properties[index];
59
- if (property === undefined)
60
- continue;
61
- if (ts.isSpreadAssignment(property) || ts.isMethodDeclaration(property) || ts.isGetAccessorDeclaration(property)
62
- || ts.isSetAccessorDeclaration(property))
63
- return null;
64
- const key = propertyKey(ts, property.name);
65
- if (key === null)
66
- return null;
67
- if (!selected.has(key))
68
- selected.set(key, ts.isShorthandPropertyAssignment(property) ? property.name : property.initializer);
69
- }
70
- return [...selected.entries()].sort(([left], [right]) => left.localeCompare(right));
71
- }
72
- function combineContributions(values) {
73
- const states = new Set(values);
74
- return states.has('yes') && 'yes' || states.has('unproven') && 'unproven' || 'no';
75
- }
76
- function identityArrayContribution(deps, ts, checker, expression, identity, seen, depth) {
77
- if (expression.elements.some(element => ts.isSpreadElement(element)))
78
- return 'unproven';
79
- return combineContributions(expression.elements.map(element => identityContribution(deps, ts, checker, element, identity, seen, depth + 1)));
80
- }
81
- function identityObjectContribution(deps, ts, checker, expression, identity, seen, depth) {
82
- const values = effectiveObjectValues(ts, expression);
83
- if (!values || values.length !== expression.properties.length)
84
- return 'unproven';
85
- return combineContributions(values.map(([, value]) => identityContribution(deps, ts, checker, value, identity, seen, depth + 1)));
86
- }
87
- function identityBinaryContribution(deps, ts, checker, expression, identity, seen, depth) {
88
- if (expression.operatorToken.kind === ts.SyntaxKind.CommaToken)
89
- return identityContribution(deps, ts, checker, expression.right, identity, seen, depth + 1);
90
- if (expression.operatorToken.kind !== ts.SyntaxKind.QuestionQuestionToken)
91
- return expressionReferences(deps, ts, checker, expression, identity) ? 'unproven' : 'no';
92
- const left = identityContribution(deps, ts, checker, expression.left, identity, seen, depth + 1);
93
- const right = identityContribution(deps, ts, checker, expression.right, identity, seen, depth + 1);
94
- return (left === 'yes' || right === 'yes') && 'yes' || (left === 'unproven' || right === 'unproven') && 'unproven' || 'no';
95
- }
96
- function identityIdentifierContribution(deps, ts, checker, expression, identity, seen, depth) {
97
- const symbol = deps.normalizedSymbol(ts, checker, expression);
98
- if (!symbol || seen.has(symbol))
99
- return 'no';
100
- const initializer = deps.constInitializer(ts, symbol);
101
- return initializer ? identityContribution(deps, ts, checker, initializer, identity, new Set(seen).add(symbol), depth + 1) : 'no';
102
- }
103
- function identityConditionalContribution(deps, ts, checker, expression, identity, seen, depth) {
104
- const whenTrue = identityContribution(deps, ts, checker, expression.whenTrue, identity, seen, depth + 1);
105
- const whenFalse = identityContribution(deps, ts, checker, expression.whenFalse, identity, seen, depth + 1);
106
- if (whenTrue === 'yes' && whenFalse === 'yes')
107
- return 'yes';
108
- if (whenTrue === 'unproven' || whenFalse === 'unproven')
109
- return 'unproven';
110
- return 'no';
111
- }
112
- function identityContribution(deps, ts, checker, expression, identity, seen = new Set(), depth = 0) {
113
- if (!expression || depth > 12)
114
- return 'unproven';
115
- expression = deps.unwrapExpression(ts, expression);
116
- if (matchesIdentityAccess(deps, ts, checker, expression, identity))
117
- return 'yes';
118
- if (ts.isIdentifier(expression))
119
- return identityIdentifierContribution(deps, ts, checker, expression, identity, seen, depth);
120
- if (ts.isConditionalExpression(expression))
121
- return identityConditionalContribution(deps, ts, checker, expression, identity, seen, depth);
122
- if (ts.isBinaryExpression(expression))
123
- return identityBinaryContribution(deps, ts, checker, expression, identity, seen, depth);
124
- if (ts.isPrefixUnaryExpression(expression))
125
- return expressionReferences(deps, ts, checker, expression, identity) ? 'unproven' : 'no';
126
- if (ts.isTemplateExpression(expression))
127
- return combineContributions(expression.templateSpans
128
- .map(span => identityContribution(deps, ts, checker, span.expression, identity, seen, depth + 1)));
129
- if (ts.isArrayLiteralExpression(expression))
130
- return identityArrayContribution(deps, ts, checker, expression, identity, seen, depth);
131
- if (ts.isObjectLiteralExpression(expression))
132
- return identityObjectContribution(deps, ts, checker, expression, identity, seen, depth);
133
- return ts.isCallExpression(expression) || ts.isNewExpression(expression) || ts.isAwaitExpression(expression) ? 'unproven' : 'no';
134
- }
135
- function returnedExpression(ts, fn) {
136
- if (ts.isArrowFunction(fn) && !ts.isBlock(fn.body))
137
- return fn.body;
138
- if (!fn.body || !ts.isBlock(fn.body))
139
- return null;
140
- const returns = [];
141
- const visit = (node) => {
142
- if (node !== fn.body && (ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node) || ts.isMethodDeclaration(node)))
143
- return;
144
- if (ts.isReturnStatement(node) && node.expression)
145
- returns.push(node.expression);
146
- else
147
- ts.forEachChild(node, visit);
148
- };
149
- visit(fn.body);
150
- return returns.length === 1 ? returns[0] ?? null : null;
151
- }
152
- function rootKeyExpression(deps, ts, checker, expression, identities, seen = new Set(), depth = 0) {
153
- if (!expression || depth > 10)
154
- return null;
155
- expression = deps.unwrapExpression(ts, expression);
156
- if (ts.isArrowFunction(expression) || ts.isFunctionExpression(expression)) {
157
- const returned = returnedExpression(ts, expression);
158
- return returned ? rootKeyExpression(deps, ts, checker, returned, identities, seen, depth + 1) : null;
159
- }
160
- if (ts.isIdentifier(expression) && !identities.some(identity => identity.symbol === deps.normalizedSymbol(ts, checker, expression))) {
161
- const symbol = deps.normalizedSymbol(ts, checker, expression);
162
- const initializer = symbol && !seen.has(symbol) ? deps.constInitializer(ts, symbol) : null;
163
- if (initializer && symbol)
164
- return rootKeyExpression(deps, ts, checker, initializer, identities, new Set(seen).add(symbol), depth + 1);
165
- }
166
- return expression;
167
- }
168
- function staticObjectKey(deps, ts, checker, expression, identities, seen, depth) {
169
- const values = effectiveObjectValues(ts, expression);
170
- return values !== null && values.length === expression.properties.length
171
- && values.every(([, value]) => staticKeyExpression(deps, ts, checker, value, identities, seen, depth + 1));
172
- }
173
- function staticCompositeKey(deps, ts, checker, expression, identities, seen, depth) {
174
- if (ts.isTemplateExpression(expression))
175
- return expression.templateSpans.every(span => staticKeyExpression(deps, ts, checker, span.expression, identities, seen, depth + 1));
176
- if (ts.isArrayLiteralExpression(expression))
177
- return expression.elements.every(element => !ts.isSpreadElement(element)
178
- && staticKeyExpression(deps, ts, checker, element, identities, seen, depth + 1));
179
- if (ts.isObjectLiteralExpression(expression))
180
- return staticObjectKey(deps, ts, checker, expression, identities, seen, depth);
181
- if (ts.isConditionalExpression(expression))
182
- return staticKeyExpression(deps, ts, checker, expression.condition, identities, seen, depth + 1)
183
- && staticKeyExpression(deps, ts, checker, expression.whenTrue, identities, seen, depth + 1)
184
- && staticKeyExpression(deps, ts, checker, expression.whenFalse, identities, seen, depth + 1);
185
- if (ts.isBinaryExpression(expression))
186
- return staticKeyExpression(deps, ts, checker, expression.left, identities, seen, depth + 1)
187
- && staticKeyExpression(deps, ts, checker, expression.right, identities, seen, depth + 1);
188
- if (ts.isPrefixUnaryExpression(expression))
189
- return staticKeyExpression(deps, ts, checker, expression.operand, identities, seen, depth + 1);
190
- return null;
191
- }
192
- function staticIdentifierKey(deps, ts, checker, expression, identities, seen, depth) {
193
- if (expression.text === 'undefined' || identities.some(identity => identity.symbol === deps.normalizedSymbol(ts, checker, expression)))
194
- return true;
195
- const symbol = deps.normalizedSymbol(ts, checker, expression);
196
- if (!symbol || seen.has(symbol))
197
- return false;
198
- const initializer = deps.constInitializer(ts, symbol);
199
- if (!initializer)
200
- return false;
201
- return staticKeyExpression(deps, ts, checker, initializer, identities, new Set(seen).add(symbol), depth + 1);
202
- }
203
- function staticKeyExpression(deps, ts, checker, expression, identities, seen = new Set(), depth = 0) {
204
- if (!expression || depth > 12)
205
- return false;
206
- expression = deps.unwrapExpression(ts, expression);
207
- if (expression.kind === ts.SyntaxKind.NullKeyword || expression.kind === ts.SyntaxKind.TrueKeyword
208
- || expression.kind === ts.SyntaxKind.FalseKeyword || ts.isStringLiteralLike(expression)
209
- || ts.isNumericLiteral(expression) || ts.isBigIntLiteral(expression) || ts.isNoSubstitutionTemplateLiteral(expression))
210
- return true;
211
- const composite = staticCompositeKey(deps, ts, checker, expression, identities, seen, depth);
212
- if (composite !== null)
213
- return composite;
214
- if (ts.isPropertyAccessExpression(expression) || ts.isElementAccessExpression(expression)) {
215
- return identities.some(identity => expressionReferences(deps, ts, checker, expression, identity));
216
- }
217
- if (ts.isIdentifier(expression))
218
- return staticIdentifierKey(deps, ts, checker, expression, identities, seen, depth);
219
- return false;
220
- }
221
- function keyLeaves(deps, ts, checker, expression, identities, decisions = [], depth = 0) {
222
- if (depth > 12)
223
- return null;
224
- expression = rootKeyExpression(deps, ts, checker, expression, identities);
225
- if (!expression)
226
- return null;
227
- if (ts.isConditionalExpression(expression)) {
228
- if (!staticKeyExpression(deps, ts, checker, expression.condition, identities))
229
- return null;
230
- const whenTrue = keyLeaves(deps, ts, checker, expression.whenTrue, identities, [...decisions, { condition: expression.condition, branch: true }], depth + 1);
231
- const whenFalse = keyLeaves(deps, ts, checker, expression.whenFalse, identities, [...decisions, { condition: expression.condition, branch: false }], depth + 1);
232
- return whenTrue && whenFalse ? [...whenTrue, ...whenFalse] : null;
233
- }
234
- if (expression.kind === ts.SyntaxKind.NullKeyword)
235
- return [{ kind: 'null', expression, decisions }];
236
- return staticKeyExpression(deps, ts, checker, expression, identities) ? [{ kind: 'active', expression, decisions }] : null;
237
- }
238
- function nullish(deps, ts, checker, expression) {
239
- expression = deps.unwrapExpression(ts, expression);
240
- if (expression.kind === ts.SyntaxKind.NullKeyword)
241
- return true;
242
- if (!ts.isIdentifier(expression) || expression.text !== 'undefined')
243
- return false;
244
- const symbol = checker.getSymbolAtLocation(expression);
245
- return !symbol || (symbol.getDeclarations?.() ?? []).every(declaration => declaration.getSourceFile().isDeclarationFile);
246
- }
247
- function logicalBranchMeansAvailable(deps, ts, checker, condition, identity, branch) {
248
- const operator = condition.operatorToken.kind;
249
- if (operator !== ts.SyntaxKind.AmpersandAmpersandToken && operator !== ts.SyntaxKind.BarBarToken)
250
- return null;
251
- // `a && b` is true only when both sides are true; `a || b` is false only when both sides are false.
252
- const decisive = operator === ts.SyntaxKind.AmpersandAmpersandToken ? branch : !branch;
253
- return decisive && [condition.left, condition.right]
254
- .some(side => branchMeansAvailable(deps, ts, checker, side, identity, branch));
255
- }
256
- function equalityBranchMeansAvailable(deps, ts, checker, condition, identity, branch) {
257
- const operator = condition.operatorToken.kind;
258
- const leftIdentity = expressionReferences(deps, ts, checker, condition.left, identity) && nullish(deps, ts, checker, condition.right);
259
- const rightIdentity = expressionReferences(deps, ts, checker, condition.right, identity) && nullish(deps, ts, checker, condition.left);
260
- if (!leftIdentity && !rightIdentity)
261
- return false;
262
- if ([ts.SyntaxKind.ExclamationEqualsToken, ts.SyntaxKind.ExclamationEqualsEqualsToken].includes(operator))
263
- return branch;
264
- if ([ts.SyntaxKind.EqualsEqualsToken, ts.SyntaxKind.EqualsEqualsEqualsToken].includes(operator))
265
- return !branch;
266
- return false;
267
- }
268
- function branchMeansAvailable(deps, ts, checker, condition, identity, branch) {
269
- condition = deps.unwrapExpression(ts, condition);
270
- if (expressionReferences(deps, ts, checker, condition, identity) && (ts.isIdentifier(condition)
271
- || ts.isPropertyAccessExpression(condition) || ts.isElementAccessExpression(condition)))
272
- return branch;
273
- if (ts.isPrefixUnaryExpression(condition) && condition.operator === ts.SyntaxKind.ExclamationToken) {
274
- return branchMeansAvailable(deps, ts, checker, condition.operand, identity, !branch);
275
- }
276
- if (!ts.isBinaryExpression(condition))
277
- return false;
278
- const logicalResult = logicalBranchMeansAvailable(deps, ts, checker, condition, identity, branch);
279
- if (logicalResult !== null)
280
- return logicalResult;
281
- return equalityBranchMeansAvailable(deps, ts, checker, condition, identity, branch);
282
- }
283
- function nonNullFalsy(deps, ts, expression) {
284
- expression = deps.unwrapExpression(ts, expression);
285
- return expression.kind === ts.SyntaxKind.FalseKeyword || ts.isStringLiteralLike(expression) && expression.text === ''
286
- || ts.isNumericLiteral(expression) && Number(expression.text) === 0
287
- || ts.isIdentifier(expression) && expression.text === 'undefined';
288
- }
289
- function containerSymbolsFromKey(deps, ts, checker, expression, found = new Set(), seen = new Set(), depth = 0) {
290
- if (!expression || depth > 12)
291
- return found;
292
- expression = deps.unwrapExpression(ts, expression);
293
- if (ts.isIdentifier(expression)) {
294
- const symbol = deps.normalizedSymbol(ts, checker, expression);
295
- if (!symbol || seen.has(symbol))
296
- return found;
297
- const initializer = deps.constInitializer(ts, symbol);
298
- if (!initializer)
299
- return found;
300
- const value = deps.unwrapExpression(ts, initializer);
301
- if (ts.isArrayLiteralExpression(value) || ts.isObjectLiteralExpression(value))
302
- found.add(symbol);
303
- containerSymbolsFromKey(deps, ts, checker, initializer, found, new Set(seen).add(symbol), depth + 1);
304
- return found;
305
- }
306
- ts.forEachChild(expression, child => { containerSymbolsFromKey(deps, ts, checker, child, found, seen, depth + 1); });
307
- return found;
308
- }
309
- function keyContainerRisks(deps, ts, checker, key, owner) {
310
- const symbols = containerSymbolsFromKey(deps, ts, checker, key);
311
- if (!symbols.size || !owner?.body)
312
- return [];
313
- const declarationNames = new Set([...symbols].flatMap(symbol => (symbol.getDeclarations?.() ?? [])
314
- .filter(ts.isVariableDeclaration).map(declaration => declaration.name)));
315
- const risks = [];
316
- const visit = (node) => {
317
- const symbol = ts.isIdentifier(node) ? deps.normalizedSymbol(ts, checker, node) : null;
318
- if (ts.isIdentifier(node) && symbol && symbols.has(symbol) && !declarationNames.has(node)
319
- && !(node.pos >= key.pos && node.end <= key.end))
320
- risks.push(node);
321
- ts.forEachChild(node, visit);
322
- };
323
- visit(owner.body);
324
- return risks;
325
- }
326
- function inspectIdentityKey(deps, scope, entry, call, identity, active) {
327
- const { config, context, violations, reasons } = scope;
328
- if (!active.length) {
329
- violations.push(deps.violation(config, call, entry.kind === 'mutation' && identity.resource ? deps.SWR_MUTATION_RULE_ID : deps.SWR_KEY_RULE_ID, `${entry.id} has no active key path carrying declared identity ${identity.id} (${identity.binding}).`, { lifecycle: entry.id, identity: identity.id }));
330
- return;
331
- }
332
- const contributions = new Set(active.map(leaf => identityContribution(deps, context.ts, call.checker, leaf.expression, identity)));
333
- if (contributions.has('unproven')) {
334
- reasons.push(`${entry.path}#${entry.export} key value contribution for identity ${identity.id} (${identity.binding}) cannot be proved on every active path`);
335
- }
336
- else if (contributions.has('no')) {
337
- const ruleId = entry.kind === 'mutation' && identity.resource ? deps.SWR_MUTATION_RULE_ID : deps.SWR_KEY_RULE_ID;
338
- violations.push(deps.violation(config, call, ruleId, `${entry.id} key must include declared ${identity.resource ? 'resource ' : ''}identity ${identity.id} (${identity.binding}) on every active key path.`, { lifecycle: entry.id, identity: identity.id }));
339
- }
340
- if (identity.gatesRequest) {
341
- const gated = active.every(leaf => leaf.decisions.some(decision => {
342
- return branchMeansAvailable(deps, context.ts, call.checker, decision.condition, identity, decision.branch);
343
- }));
344
- if (!gated)
345
- violations.push(deps.violation(config, call, deps.SWR_KEY_RULE_ID, `${entry.id} must produce an explicit null key when ${identity.id} (${identity.binding}) is unavailable.`, { lifecycle: entry.id, identity: identity.id }));
346
- }
347
- }
348
- function inspectKey(deps, scope, entry, call, identities) {
349
- const { config, context, violations, reasons } = scope;
350
- const key = call.node.arguments[0];
351
- if (!key) {
352
- reasons.push(`${entry.path}#${entry.export} has an SWR call without a key`);
353
- return;
354
- }
355
- const containerRisks = keyContainerRisks(deps, context.ts, call.checker, key, call.owner);
356
- if (containerRisks.length) {
357
- const locations = containerRisks.map(node => deps.sourceLocation(call.source, node).line).filter((line, index, all) => all.indexOf(line) === index);
358
- reasons.push(`${entry.path}#${entry.export} key container is referenced outside its declaration and selected SWR key` + (locations.length ? ` (line${'s'.repeat(Number(locations.length !== 1))} ${locations.join(', ')})` : ''));
359
- return;
360
- }
361
- const leaves = keyLeaves(deps, context.ts, call.checker, key, identities);
362
- if (!leaves) {
363
- reasons.push(`${entry.path}#${entry.export} uses a dynamic SWR key whose identity cannot be proved`);
364
- return;
365
- }
366
- const active = leaves.filter(leaf => leaf.kind === 'active');
367
- if (active.some(leaf => nonNullFalsy(deps, context.ts, leaf.expression)))
368
- violations.push(deps.violation(config, call, deps.SWR_KEY_RULE_ID, `${entry.id} uses explicit null, rather than another falsy value, for a disabled SWR key.`, { lifecycle: entry.id }));
369
- for (const identity of identities)
370
- inspectIdentityKey(deps, scope, entry, call, identity, active);
371
- }
372
- export function createNextDataKeyInspector(deps) {
373
- return (config, context, entry, call, identities, violations, reasons) => inspectKey(deps, { config, context, violations, reasons }, entry, call, identities);
374
- }
@@ -1,26 +0,0 @@
1
- import { unwrapExpression } from './typescript.mjs';
2
- import { normalizedSymbol, normalizedSymbolValue } from './ast-walks.mjs';
3
- import { isConstVariable } from '../../lib/ts-ast.mjs';
4
- export function functionNode(ts, declaration) {
5
- if (ts.isFunctionDeclaration(declaration) && declaration.body)
6
- return declaration;
7
- if (ts.isVariableDeclaration(declaration) && declaration.initializer) {
8
- const value = unwrapExpression(ts, declaration.initializer);
9
- if (ts.isArrowFunction(value) || ts.isFunctionExpression(value))
10
- return value;
11
- }
12
- return null;
13
- }
14
- export function constInitializer(ts, symbol) {
15
- const declarations = symbol?.getDeclarations?.() ?? [];
16
- const [declaration] = declarations;
17
- if (declarations.length !== 1 || !declaration || !ts.isVariableDeclaration(declaration) || !declaration.initializer
18
- || !isConstVariable(ts, declaration))
19
- return null;
20
- return declaration.initializer;
21
- }
22
- export function inferredSymbol(ts, checker, node) {
23
- return ts.isIdentifier(node) && ts.isShorthandPropertyAssignment(node.parent)
24
- ? normalizedSymbolValue(ts, checker, checker.getShorthandAssignmentValueSymbol(node.parent))
25
- : normalizedSymbol(ts, checker, node);
26
- }