@starci/eslint-canon-be 3.18.4 → 3.19.1

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 (211) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -1
  3. package/dist/comments.js +1 -1
  4. package/dist/explicit-surface.js +1 -1
  5. package/dist/index.js +1 -1
  6. package/dist/jwt-alg.js +1 -1
  7. package/dist/lib/edition.d.ts +1 -1
  8. package/dist/lib/edition.js +1 -1
  9. package/dist/lib/hfs-view.d.ts +5 -0
  10. package/dist/lib/hfs.d.ts +0 -6
  11. package/dist/lib/hfs.js +7 -5
  12. package/dist/lib/runtime-root.d.ts +6 -1
  13. package/dist/lib/runtime-root.js +8 -2
  14. package/dist/lib/subject-values.js +1 -1
  15. package/dist/module-layering.js +2 -2
  16. package/dist/project-graph.js +1 -1
  17. package/dist/schema-authority.js +66 -2
  18. package/dist/third-party-owner.js +1 -1
  19. package/package.json +3 -1
  20. package/runtime/bundle.json +1 -190
  21. package/runtime/scripts/api/git/recorded-lines.mjs +5 -5
  22. package/runtime/scripts/hfs/project-graph.mjs +6 -6
  23. package/runtime/scripts/hfs/project-rule.mjs +3 -3
  24. package/runtime/config.example.yaml +0 -194
  25. package/runtime/engine/by-code-unit.mjs +0 -12
  26. package/runtime/engine/config.mjs +0 -461
  27. package/runtime/engine/invalid-config.mjs +0 -15
  28. package/runtime/engine/model-config.mjs +0 -112
  29. package/runtime/engine/orca-config.mjs +0 -34
  30. package/runtime/engine/plain-object.mjs +0 -5
  31. package/runtime/engine/release-config.mjs +0 -32
  32. package/runtime/engine/removed-vocabulary.mjs +0 -27
  33. package/runtime/engine/resources-config.mjs +0 -59
  34. package/runtime/engine/runtime-root.mjs +0 -138
  35. package/runtime/engine/secrets.mjs +0 -202
  36. package/runtime/engine/sonar-config.mjs +0 -24
  37. package/runtime/engine/temp-root.mjs +0 -26
  38. package/runtime/engine/yaml.mjs +0 -161
  39. package/runtime/knowledge/grammars/index.yaml +0 -114
  40. package/runtime/knowledge/hfs/canon-pins.yaml +0 -720
  41. package/runtime/knowledge/hfs/fe-stack.yaml +0 -272
  42. package/runtime/knowledge/hfs/rules.yaml +0 -6760
  43. package/runtime/knowledge/hfs/slots.yaml +0 -2783
  44. package/runtime/knowledge/patterns/fe/folder.yaml +0 -425
  45. package/runtime/knowledge/sonar-gate.yaml +0 -151
  46. package/runtime/modules/kernel/removed-vocabulary.yaml +0 -458
  47. package/runtime/modules/models/registry.yaml +0 -221
  48. package/runtime/modules/models/runtimes.yaml +0 -556
  49. package/runtime/modules/models/tiers.yaml +0 -66
  50. package/runtime/scripts/api/git/cat-file.mjs +0 -4
  51. package/runtime/scripts/api/git/config-get.mjs +0 -9
  52. package/runtime/scripts/api/git/diff.mjs +0 -4
  53. package/runtime/scripts/api/git/lib.mjs +0 -80
  54. package/runtime/scripts/api/git/ls-files.mjs +0 -5
  55. package/runtime/scripts/api/git/ls-tree.mjs +0 -4
  56. package/runtime/scripts/api/git/merge-base.mjs +0 -8
  57. package/runtime/scripts/api/git/remote.mjs +0 -4
  58. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -4
  59. package/runtime/scripts/api/git/show.mjs +0 -5
  60. package/runtime/scripts/api/git/tag.mjs +0 -4
  61. package/runtime/scripts/hfs/allows.mjs +0 -77
  62. package/runtime/scripts/hfs/architecture/ast-walks.mjs +0 -250
  63. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +0 -103
  64. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +0 -114
  65. package/runtime/scripts/hfs/architecture/backend.mjs +0 -462
  66. package/runtime/scripts/hfs/architecture/background-unowned.mjs +0 -254
  67. package/runtime/scripts/hfs/architecture/canon-clones.mjs +0 -291
  68. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +0 -224
  69. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +0 -102
  70. package/runtime/scripts/hfs/architecture/clones.mjs +0 -287
  71. package/runtime/scripts/hfs/architecture/component-tiers.mjs +0 -161
  72. package/runtime/scripts/hfs/architecture/config-unread.mjs +0 -16
  73. package/runtime/scripts/hfs/architecture/config.mjs +0 -407
  74. package/runtime/scripts/hfs/architecture/connection-map.mjs +0 -350
  75. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +0 -115
  76. package/runtime/scripts/hfs/architecture/context-coupling.mjs +0 -117
  77. package/runtime/scripts/hfs/architecture/context-map.mjs +0 -355
  78. package/runtime/scripts/hfs/architecture/context-owner.mjs +0 -102
  79. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +0 -65
  80. package/runtime/scripts/hfs/architecture/context-transaction.mjs +0 -75
  81. package/runtime/scripts/hfs/architecture/contract-bounds.mjs +0 -72
  82. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +0 -177
  83. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +0 -360
  84. package/runtime/scripts/hfs/architecture/contracts.mjs +0 -489
  85. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +0 -81
  86. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +0 -173
  87. package/runtime/scripts/hfs/architecture/dead-exports.mjs +0 -420
  88. package/runtime/scripts/hfs/architecture/default-deny.mjs +0 -175
  89. package/runtime/scripts/hfs/architecture/doc-language.mjs +0 -45
  90. package/runtime/scripts/hfs/architecture/entity-registry.mjs +0 -51
  91. package/runtime/scripts/hfs/architecture/entrypoint.mjs +0 -75
  92. package/runtime/scripts/hfs/architecture/error-codes.mjs +0 -54
  93. package/runtime/scripts/hfs/architecture/error-masked.mjs +0 -78
  94. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +0 -44
  95. package/runtime/scripts/hfs/architecture/feature-shape.mjs +0 -60
  96. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +0 -41
  97. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +0 -112
  98. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +0 -193
  99. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +0 -198
  100. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +0 -368
  101. package/runtime/scripts/hfs/architecture/frontend-world.mjs +0 -374
  102. package/runtime/scripts/hfs/architecture/frontend.mjs +0 -248
  103. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +0 -185
  104. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +0 -77
  105. package/runtime/scripts/hfs/architecture/hfs.mjs +0 -394
  106. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +0 -118
  107. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +0 -213
  108. package/runtime/scripts/hfs/architecture/identity.mjs +0 -121
  109. package/runtime/scripts/hfs/architecture/index.mjs +0 -402
  110. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +0 -69
  111. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +0 -231
  112. package/runtime/scripts/hfs/architecture/machine-ast.mjs +0 -232
  113. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +0 -32
  114. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +0 -237
  115. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +0 -126
  116. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +0 -192
  117. package/runtime/scripts/hfs/architecture/next-data-key.mjs +0 -374
  118. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +0 -26
  119. package/runtime/scripts/hfs/architecture/next-data.mjs +0 -425
  120. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +0 -55
  121. package/runtime/scripts/hfs/architecture/owners.mjs +0 -142
  122. package/runtime/scripts/hfs/architecture/package-shape.mjs +0 -92
  123. package/runtime/scripts/hfs/architecture/presentation.mjs +0 -173
  124. package/runtime/scripts/hfs/architecture/reachability.mjs +0 -330
  125. package/runtime/scripts/hfs/architecture/register-once.mjs +0 -212
  126. package/runtime/scripts/hfs/architecture/registration.mjs +0 -372
  127. package/runtime/scripts/hfs/architecture/render-graph.mjs +0 -449
  128. package/runtime/scripts/hfs/architecture/render-prop-across-server.mjs +0 -58
  129. package/runtime/scripts/hfs/architecture/required-files.mjs +0 -237
  130. package/runtime/scripts/hfs/architecture/root-packages.mjs +0 -78
  131. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +0 -133
  132. package/runtime/scripts/hfs/architecture/schema-owner.mjs +0 -288
  133. package/runtime/scripts/hfs/architecture/server-action.mjs +0 -78
  134. package/runtime/scripts/hfs/architecture/side-boundary.mjs +0 -13
  135. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +0 -320
  136. package/runtime/scripts/hfs/architecture/source-names.mjs +0 -393
  137. package/runtime/scripts/hfs/architecture/sql-keys.mjs +0 -344
  138. package/runtime/scripts/hfs/architecture/sql-owner.mjs +0 -291
  139. package/runtime/scripts/hfs/architecture/sql-returning.mjs +0 -76
  140. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +0 -117
  141. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +0 -587
  142. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +0 -42
  143. package/runtime/scripts/hfs/architecture/surface-nesting.mjs +0 -127
  144. package/runtime/scripts/hfs/architecture/surface.mjs +0 -88
  145. package/runtime/scripts/hfs/architecture/symbols.mjs +0 -273
  146. package/runtime/scripts/hfs/architecture/test-world-files.mjs +0 -263
  147. package/runtime/scripts/hfs/architecture/tiers.mjs +0 -256
  148. package/runtime/scripts/hfs/architecture/transport-owner.mjs +0 -248
  149. package/runtime/scripts/hfs/architecture/type-context.mjs +0 -335
  150. package/runtime/scripts/hfs/architecture/typescript.mjs +0 -477
  151. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +0 -165
  152. package/runtime/scripts/hfs/declaration-shape.mjs +0 -196
  153. package/runtime/scripts/hfs/declaration-slots.mjs +0 -89
  154. package/runtime/scripts/hfs/edition-slots.mjs +0 -80
  155. package/runtime/scripts/hfs/explicit-surface-rule.mjs +0 -59
  156. package/runtime/scripts/hfs/linear-text.mjs +0 -30
  157. package/runtime/scripts/hfs/manifest-shape.mjs +0 -474
  158. package/runtime/scripts/hfs/param-names.mjs +0 -13
  159. package/runtime/scripts/hfs/path-findings.mjs +0 -167
  160. package/runtime/scripts/hfs/repo-identity.mjs +0 -89
  161. package/runtime/scripts/hfs/rule-catalog.mjs +0 -458
  162. package/runtime/scripts/hfs/rule-params-shape.mjs +0 -103
  163. package/runtime/scripts/hfs/rules/database-constants.mjs +0 -25
  164. package/runtime/scripts/hfs/rules/database-migrations.mjs +0 -684
  165. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +0 -68
  166. package/runtime/scripts/hfs/rules/read.mjs +0 -45
  167. package/runtime/scripts/hfs/rules/secrets.mjs +0 -79
  168. package/runtime/scripts/hfs/rules/spec-placement.mjs +0 -28
  169. package/runtime/scripts/hfs/slot-app-view.mjs +0 -97
  170. package/runtime/scripts/hfs/slot-classify.mjs +0 -69
  171. package/runtime/scripts/hfs/slot-errors.mjs +0 -12
  172. package/runtime/scripts/hfs/slot-imports.mjs +0 -98
  173. package/runtime/scripts/hfs/slot-manifest-shape.mjs +0 -111
  174. package/runtime/scripts/hfs/slot-match.mjs +0 -164
  175. package/runtime/scripts/hfs/slot-path.mjs +0 -6
  176. package/runtime/scripts/hfs/slot-required.mjs +0 -95
  177. package/runtime/scripts/hfs/slot-semantic-problems.mjs +0 -175
  178. package/runtime/scripts/hfs/slot-side-problems.mjs +0 -32
  179. package/runtime/scripts/hfs/slots.mjs +0 -306
  180. package/runtime/scripts/hfs/test-world-slot.mjs +0 -5
  181. package/runtime/scripts/hfs/trailing-slashes.mjs +0 -8
  182. package/runtime/scripts/hfs/typescript-programs.mjs +0 -95
  183. package/runtime/scripts/hfs/view.mjs +0 -180
  184. package/runtime/scripts/lib/declaration-surface.mjs +0 -166
  185. package/runtime/scripts/lib/dockerfile.mjs +0 -164
  186. package/runtime/scripts/lib/env.mjs +0 -18
  187. package/runtime/scripts/lib/event-contract.mjs +0 -102
  188. package/runtime/scripts/lib/git-hooks-dir.mjs +0 -30
  189. package/runtime/scripts/lib/git.mjs +0 -35
  190. package/runtime/scripts/lib/glob.mjs +0 -32
  191. package/runtime/scripts/lib/grammar-lint.mjs +0 -57
  192. package/runtime/scripts/lib/i18n.mjs +0 -82
  193. package/runtime/scripts/lib/in-order.mjs +0 -90
  194. package/runtime/scripts/lib/json-clone.mjs +0 -70
  195. package/runtime/scripts/lib/json.mjs +0 -44
  196. package/runtime/scripts/lib/language.mjs +0 -233
  197. package/runtime/scripts/lib/list.mjs +0 -26
  198. package/runtime/scripts/lib/mutation-fence.mjs +0 -20
  199. package/runtime/scripts/lib/package-at.mjs +0 -62
  200. package/runtime/scripts/lib/path-key.mjs +0 -124
  201. package/runtime/scripts/lib/read-text.mjs +0 -47
  202. package/runtime/scripts/lib/regex.mjs +0 -3
  203. package/runtime/scripts/lib/rule-packs.mjs +0 -243
  204. package/runtime/scripts/lib/same-text.mjs +0 -4
  205. package/runtime/scripts/lib/secret-patterns.mjs +0 -230
  206. package/runtime/scripts/lib/sops-envelope.mjs +0 -212
  207. package/runtime/scripts/lib/stack-services.mjs +0 -191
  208. package/runtime/scripts/lib/ts-analysis.mjs +0 -39
  209. package/runtime/scripts/lib/ts-ast.mjs +0 -63
  210. package/runtime/scripts/lib/walk.mjs +0 -45
  211. package/runtime/scripts/lib/yaml-cached.mjs +0 -14
@@ -1,449 +0,0 @@
1
- import { unwrapExpression } from '../../lib/ts-analysis.mjs';
2
- import { sourceLocation } from '../../lib/ts-ast.mjs';
3
- const GRAMMAR_PACKAGE = /^@starci\/grammar(?:\/|$)/u;
4
- const MAX_DEPTH = 14;
5
- const HELPER_DEPTH = 3;
6
- const MAP_METHODS = new Set(['map', 'flatMap']);
7
- /** Everything the walk needs about the files of one program. */
8
- export class RenderGraph {
9
- ts;
10
- graph;
11
- components = new Map();
12
- imports = new Map();
13
- exportsCache = new Map();
14
- fileEdges = new Map();
15
- constructor(ts, graph) {
16
- this.ts = ts;
17
- this.graph = graph;
18
- for (const edge of graph.edges) {
19
- let bySpecifier = this.fileEdges.get(edge.from);
20
- if (!bySpecifier) {
21
- bySpecifier = new Map();
22
- this.fileEdges.set(edge.from, bySpecifier);
23
- }
24
- bySpecifier.set(edge.specifier, edge.to);
25
- }
26
- for (const file of graph.files.values())
27
- if (/\.tsx$/u.test(file.rel) && !/\.(?:spec|test|stories)\.tsx$/u.test(file.rel))
28
- this.readComponents(file.rel, file.sourceFile);
29
- }
30
- /** Every app component of the program. */
31
- allComponents() {
32
- return [...this.components.values()].flatMap(byName => [...byName.values()]);
33
- }
34
- /** The component a file declares under a name. */
35
- componentOf(file, name) {
36
- return this.components.get(file)?.get(name) ?? null;
37
- }
38
- /** The location of a node, 1-based. */
39
- locate(element) {
40
- const file = this.graph.files.get(element.file);
41
- return { path: element.file, ...(file ? sourceLocation(file.sourceFile, element.node) : { line: 1, column: 1 }) };
42
- }
43
- // --- reading a file -------------------------------------------------------------------------------------------------------
44
- readComponents(rel, sourceFile) {
45
- const { ts } = this;
46
- const byName = new Map();
47
- const functions = new Map();
48
- for (const statement of sourceFile.statements) {
49
- if (ts.isFunctionDeclaration(statement) && statement.name)
50
- functions.set(statement.name.text, statement);
51
- if (ts.isVariableStatement(statement)) {
52
- for (const declaration of statement.declarationList.declarations) {
53
- const fn = ts.isIdentifier(declaration.name) ? this.functionOf(declaration.initializer) : null;
54
- if (fn && ts.isIdentifier(declaration.name))
55
- functions.set(declaration.name.text, fn);
56
- }
57
- }
58
- }
59
- for (const [name, fn] of functions) {
60
- if (!/^[A-Z]/u.test(name))
61
- continue;
62
- const returns = this.returnsOf(rel, fn, functions);
63
- if (returns.length > 0)
64
- byName.set(name, { file: rel, name, returns });
65
- }
66
- if (byName.size > 0)
67
- this.components.set(rel, byName);
68
- }
69
- /** The function a declaration initializer is or wraps (`memo(fn)`, `forwardRef(fn)`). */
70
- functionOf(initializer) {
71
- const { ts } = this;
72
- const value = unwrapExpression(ts, initializer);
73
- if (!value)
74
- return null;
75
- if (ts.isArrowFunction(value) || ts.isFunctionExpression(value))
76
- return value;
77
- if (ts.isCallExpression(value) && value.arguments[0])
78
- return this.functionOf(value.arguments[0]);
79
- return null;
80
- }
81
- returnsOf(rel, fn, siblings) {
82
- const { ts } = this;
83
- const propNames = new Set();
84
- let propsIdentifier = null;
85
- const first = fn.parameters[0];
86
- if (first) {
87
- if (ts.isIdentifier(first.name))
88
- propsIdentifier = first.name.text;
89
- else if (ts.isObjectBindingPattern(first.name)) {
90
- for (const element of first.name.elements) {
91
- if (ts.isIdentifier(element.name))
92
- propNames.add(element.propertyName && ts.isIdentifier(element.propertyName) ? `${element.name.text}\u0000${element.propertyName.text}` : element.name.text);
93
- }
94
- }
95
- }
96
- // destructured local names -> prop name
97
- const propOfLocal = new Map();
98
- for (const entry of propNames) {
99
- const [local, prop] = entry.split('\u0000');
100
- propOfLocal.set(local, prop ?? local);
101
- }
102
- const locals = new Map();
103
- const returned = [];
104
- const scan = (node) => {
105
- if (ts.isFunctionLike(node) && node !== fn)
106
- return;
107
- if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer) {
108
- locals.set(node.name.text, node.initializer);
109
- }
110
- if (ts.isVariableDeclaration(node) && ts.isObjectBindingPattern(node.name) && node.initializer && ts.isIdentifier(node.initializer) && node.initializer.text === propsIdentifier) {
111
- for (const element of node.name.elements)
112
- if (ts.isIdentifier(element.name))
113
- propOfLocal.set(element.name.text, element.propertyName && ts.isIdentifier(element.propertyName) ? element.propertyName.text : element.name.text);
114
- }
115
- if (ts.isReturnStatement(node) && node.expression)
116
- returned.push(node.expression);
117
- ts.forEachChild(node, scan);
118
- };
119
- if (fn.body && !ts.isBlock(fn.body))
120
- returned.push(fn.body);
121
- else if (fn.body)
122
- ts.forEachChild(fn.body, scan);
123
- const reader = new PartReader(this, rel, { locals, propOfLocal, propsIdentifier, siblings });
124
- return returned.flatMap(expression => reader.read(expression, false, 0));
125
- }
126
- // --- names ----------------------------------------------------------------------------------------------------------------
127
- importsOf(rel) {
128
- const cached = this.imports.get(rel);
129
- if (cached)
130
- return cached;
131
- const { ts } = this;
132
- const bindings = new Map();
133
- const sourceFile = this.graph.files.get(rel)?.sourceFile;
134
- this.imports.set(rel, bindings);
135
- if (!sourceFile)
136
- return bindings;
137
- for (const statement of sourceFile.statements) {
138
- if (!ts.isImportDeclaration(statement) || !ts.isStringLiteralLike(statement.moduleSpecifier))
139
- continue;
140
- const specifier = statement.moduleSpecifier.text;
141
- const clause = statement.importClause;
142
- if (!clause || clause.isTypeOnly)
143
- continue;
144
- const target = this.fileEdges.get(rel)?.get(specifier) ?? null;
145
- const grammar = GRAMMAR_PACKAGE.test(specifier);
146
- const bind = (local, imported) => {
147
- if (grammar)
148
- bindings.set(local, { grammar: imported });
149
- else if (target) {
150
- const resolved = this.resolveExport(target, imported, new Set());
151
- bindings.set(local, resolved ?? { external: true });
152
- }
153
- else
154
- bindings.set(local, { external: true });
155
- };
156
- if (clause.name)
157
- bind(clause.name.text, 'default');
158
- const named = clause.namedBindings;
159
- if (named && ts.isNamespaceImport(named))
160
- bindings.set(named.name.text, grammar ? { grammar: '*' } : { external: true });
161
- else if (named)
162
- for (const element of named.elements)
163
- if (!element.isTypeOnly)
164
- bind(element.name.text, element.propertyName?.text ?? element.name.text);
165
- }
166
- return bindings;
167
- }
168
- /** The file and local name that declare what `file` exports under `name`, following re-exports. */
169
- resolveExport(file, name, seen) {
170
- const key = `${file}\u0000${name}`;
171
- if (seen.has(key))
172
- return null;
173
- seen.add(key);
174
- if (this.components.get(file)?.has(name))
175
- return { file, name };
176
- const table = this.exportTable(file);
177
- const direct = table.get(name);
178
- if (direct)
179
- return direct.file === file && direct.name === name ? direct : this.resolveExport(direct.file, direct.name, seen);
180
- const star = table.get('*');
181
- if (star)
182
- return this.resolveExport(star.file, name, seen);
183
- return null;
184
- }
185
- exportTable(file) {
186
- const cached = this.exportsCache.get(file);
187
- if (cached)
188
- return cached;
189
- const table = new Map();
190
- this.exportsCache.set(file, table);
191
- const { ts } = this;
192
- const sourceFile = this.graph.files.get(file)?.sourceFile;
193
- if (!sourceFile)
194
- return table;
195
- for (const statement of sourceFile.statements) {
196
- if (ts.isExportDeclaration(statement)) {
197
- const target = statement.moduleSpecifier && ts.isStringLiteralLike(statement.moduleSpecifier) ? this.fileEdges.get(file)?.get(statement.moduleSpecifier.text) ?? null : null;
198
- if (!statement.exportClause) {
199
- if (target)
200
- table.set('*', { file: target, name: '*' });
201
- }
202
- else if (ts.isNamedExports(statement.exportClause)) {
203
- for (const element of statement.exportClause.elements) {
204
- const local = element.propertyName?.text ?? element.name.text;
205
- table.set(element.name.text, { file: target ?? file, name: local });
206
- }
207
- }
208
- }
209
- else if (ts.isExportAssignment(statement) && ts.isIdentifier(statement.expression)) {
210
- table.set('default', { file, name: statement.expression.text });
211
- }
212
- else if (ts.isFunctionDeclaration(statement) && statement.name && statement.modifiers?.some(modifier => modifier.kind === ts.SyntaxKind.DefaultKeyword)) {
213
- table.set('default', { file, name: statement.name.text });
214
- }
215
- }
216
- return table;
217
- }
218
- /** What the JSX tag `tagName` of a file names. */
219
- tagOf(rel, tagName) {
220
- const { ts } = this;
221
- if (ts.isIdentifier(tagName)) {
222
- const name = tagName.text;
223
- if (/^[a-z]/u.test(name))
224
- return { kind: 'host', name };
225
- if (this.components.get(rel)?.has(name))
226
- return { kind: 'component', file: rel, name };
227
- const bound = this.importsOf(rel).get(name);
228
- if (bound && 'grammar' in bound)
229
- return { kind: 'grammar', name: bound.grammar };
230
- if (bound && 'file' in bound)
231
- return { kind: 'component', file: bound.file, name: bound.name };
232
- return { kind: 'unknown', name };
233
- }
234
- if (ts.isPropertyAccessExpression(tagName) && ts.isIdentifier(tagName.expression)) {
235
- const bound = this.importsOf(rel).get(tagName.expression.text);
236
- if (bound && 'grammar' in bound && bound.grammar === '*')
237
- return { kind: 'grammar', name: tagName.name.text };
238
- return { kind: 'unknown', name: `${tagName.expression.text}.${tagName.name.text}` };
239
- }
240
- return { kind: 'unknown', name: '?' };
241
- }
242
- // --- walking --------------------------------------------------------------------------------------------------------------
243
- /** Walks everything `root` draws with the empty context, reporting each element and each run of siblings to the visitor. */
244
- walkFrom(root, visitor) {
245
- this.walk(root.returns, [], null, [`${root.file}#${root.name}`], visitor, 0);
246
- }
247
- walk(parts, ancestors, supplier, stack, visitor, depth) {
248
- if (depth > MAX_DEPTH)
249
- return;
250
- const flat = this.flatten(parts, supplier);
251
- const elements = flat.filter((entry) => entry.element !== null);
252
- if (visitor.siblings && elements.length > 1)
253
- visitor.siblings(elements.map(entry => entry.element), ancestors, stack);
254
- for (const { element, supplier: supplied } of elements) {
255
- visitor.enter?.(element, ancestors, stack);
256
- const { tag } = element;
257
- if (tag.kind === 'component') {
258
- const definition = this.componentOf(tag.file, tag.name);
259
- const key = `${tag.file}#${tag.name}`;
260
- if (!definition || stack.includes(key))
261
- continue;
262
- const slots = new Map();
263
- for (const attribute of element.attributes.values())
264
- if (attribute.parts.length > 0)
265
- slots.set(attribute.name, attribute.parts);
266
- this.walk(definition.returns, ancestors, { children: element.children, slots, outer: supplied }, [...stack, key], visitor, depth + 1);
267
- }
268
- else {
269
- const inner = tag.kind === 'grammar' || tag.kind === 'host' ? [...ancestors, { element }] : ancestors;
270
- const slotParts = [...element.attributes.values()].flatMap(attribute => attribute.parts);
271
- if (visitor.parent)
272
- visitor.parent(element, this.flatten(element.children, supplied).flatMap(entry => (entry.element ? [entry.element] : [])), ancestors, stack);
273
- this.walk([...slotParts, ...element.children], inner, supplied, stack, visitor, depth + 1);
274
- }
275
- }
276
- }
277
- /** Parts with placements replaced by what the supplier handed over; each element keeps the supplier its own placements read. */
278
- flatten(parts, supplier) {
279
- const out = [];
280
- for (const part of parts) {
281
- if (part.kind === 'element') {
282
- out.push({ element: part, supplier });
283
- continue;
284
- }
285
- if (!supplier)
286
- continue;
287
- const handed = part.prop === 'children' ? supplier.children : supplier.slots.get(part.prop) ?? [];
288
- out.push(...this.flatten(handed, supplier.outer));
289
- }
290
- return out;
291
- }
292
- /** The one element a component element draws at its root, or null when it draws several things or none. */
293
- rootOf(element) {
294
- if (element.tag.kind !== 'component')
295
- return element;
296
- const definition = this.componentOf(element.tag.file, element.tag.name);
297
- const roots = definition?.returns.filter((part) => part.kind === 'element') ?? [];
298
- const only = roots.length === 1 && definition?.returns.length === 1 ? roots[0] : undefined;
299
- return only ?? null;
300
- }
301
- }
302
- /** Reads the expressions of one function into render parts. */
303
- class PartReader {
304
- graph;
305
- rel;
306
- scope;
307
- followed = new Set();
308
- constructor(graph, rel, scope) {
309
- this.graph = graph;
310
- this.rel = rel;
311
- this.scope = scope;
312
- }
313
- read(input, repeated, depth) {
314
- const { ts } = this.graph;
315
- const expression = unwrapExpression(ts, input);
316
- if (!expression || depth > 12)
317
- return [];
318
- if (ts.isJsxElement(expression))
319
- return [this.element(expression.openingElement, expression.children, repeated, depth)];
320
- if (ts.isJsxSelfClosingElement(expression))
321
- return [this.element(expression, [], repeated, depth)];
322
- if (ts.isJsxFragment(expression))
323
- return this.children(expression.children, repeated, depth);
324
- if (ts.isJsxExpression(expression))
325
- return expression.expression ? this.read(expression.expression, repeated, depth + 1) : [];
326
- if (ts.isConditionalExpression(expression))
327
- return [...this.read(expression.whenTrue, repeated, depth + 1), ...this.read(expression.whenFalse, repeated, depth + 1)];
328
- if (ts.isBinaryExpression(expression)) {
329
- const kind = expression.operatorToken.kind;
330
- if (kind === ts.SyntaxKind.AmpersandAmpersandToken)
331
- return this.read(expression.right, repeated, depth + 1);
332
- if (kind === ts.SyntaxKind.BarBarToken || kind === ts.SyntaxKind.QuestionQuestionToken)
333
- return [...this.read(expression.left, repeated, depth + 1), ...this.read(expression.right, repeated, depth + 1)];
334
- return [];
335
- }
336
- if (ts.isArrayLiteralExpression(expression))
337
- return expression.elements.flatMap(item => this.read(item, repeated, depth + 1));
338
- if (ts.isIdentifier(expression))
339
- return this.identifier(expression.text, expression, repeated, depth);
340
- if (ts.isPropertyAccessExpression(expression) && ts.isIdentifier(expression.expression) && expression.expression.text === this.scope.propsIdentifier) {
341
- return [{ kind: 'placement', prop: expression.name.text, file: this.rel, node: expression }];
342
- }
343
- if (ts.isCallExpression(expression))
344
- return this.call(expression, repeated, depth);
345
- return [];
346
- }
347
- identifier(name, node, repeated, depth) {
348
- const prop = this.scope.propOfLocal.get(name);
349
- if (prop !== undefined)
350
- return [{ kind: 'placement', prop, file: this.rel, node }];
351
- const local = this.scope.locals.get(name);
352
- if (local && !this.followed.has(local)) {
353
- this.followed.add(local);
354
- const parts = this.read(local, repeated, depth + 1);
355
- this.followed.delete(local);
356
- return parts;
357
- }
358
- return [];
359
- }
360
- call(call, repeated, depth) {
361
- const { ts } = this.graph;
362
- const callee = unwrapExpression(ts, call.expression);
363
- if (ts.isPropertyAccessExpression(callee) && MAP_METHODS.has(callee.name.text)) {
364
- const callback = call.arguments[0];
365
- const fn = callback && (ts.isArrowFunction(callback) || ts.isFunctionExpression(callback)) ? callback : null;
366
- if (!fn)
367
- return [];
368
- const returned = [];
369
- const scan = (node) => {
370
- if (ts.isFunctionLike(node) && node !== fn)
371
- return;
372
- if (ts.isReturnStatement(node) && node.expression)
373
- returned.push(node.expression);
374
- ts.forEachChild(node, scan);
375
- };
376
- if (!ts.isBlock(fn.body))
377
- returned.push(fn.body);
378
- else
379
- ts.forEachChild(fn.body, scan);
380
- return returned.flatMap(expression => this.read(expression, true, depth + 1));
381
- }
382
- if (ts.isIdentifier(callee) && depth < HELPER_DEPTH * 4) {
383
- const helper = this.scope.siblings.get(callee.text);
384
- if (helper && !/^[A-Z]/u.test(callee.text) && !this.followed.has(helper)) {
385
- this.followed.add(helper);
386
- const returned = [];
387
- const scan = (node) => {
388
- if (ts.isFunctionLike(node) && node !== helper)
389
- return;
390
- if (ts.isReturnStatement(node) && node.expression)
391
- returned.push(node.expression);
392
- ts.forEachChild(node, scan);
393
- };
394
- if (helper.body && !ts.isBlock(helper.body))
395
- returned.push(helper.body);
396
- else if (helper.body)
397
- ts.forEachChild(helper.body, scan);
398
- const parts = returned.flatMap(expression => this.read(expression, repeated, depth + 4));
399
- this.followed.delete(helper);
400
- return parts;
401
- }
402
- }
403
- return [];
404
- }
405
- children(children, repeated, depth) {
406
- return children.flatMap(child => this.read(child, repeated, depth + 1));
407
- }
408
- element(opening, children, repeated, depth) {
409
- const { ts } = this.graph;
410
- const attributes = new Map();
411
- for (const attribute of opening.attributes.properties) {
412
- if (ts.isJsxSpreadAttribute(attribute)) {
413
- attributes.set('...', { name: '...', text: null, parts: [] });
414
- continue;
415
- }
416
- if (!ts.isIdentifier(attribute.name))
417
- continue;
418
- const name = attribute.name.text;
419
- const initializer = attribute.initializer;
420
- let text = null;
421
- let parts = [];
422
- if (!initializer)
423
- text = 'true';
424
- else if (ts.isStringLiteralLike(initializer))
425
- text = initializer.text;
426
- else if (ts.isJsxExpression(initializer) && initializer.expression) {
427
- const value = unwrapExpression(ts, initializer.expression);
428
- if (ts.isStringLiteralLike(value) || ts.isNoSubstitutionTemplateLiteral(value))
429
- text = value.text;
430
- else if (value.kind === ts.SyntaxKind.TrueKeyword)
431
- text = 'true';
432
- else if (value.kind === ts.SyntaxKind.FalseKeyword)
433
- text = 'false';
434
- else if (!ts.isArrowFunction(value) && !ts.isFunctionExpression(value))
435
- parts = this.read(value, false, depth + 1);
436
- }
437
- attributes.set(name, { name, text, parts });
438
- }
439
- return {
440
- kind: 'element',
441
- tag: this.graph.tagOf(this.rel, opening.tagName),
442
- attributes,
443
- children: this.children(children, repeated, depth),
444
- repeated,
445
- file: this.rel,
446
- node: opening,
447
- };
448
- }
449
- }
@@ -1,58 +0,0 @@
1
- import { RenderGraph } from './render-graph.mjs';
2
- /**
3
- * R361 `render-prop-across-server` (FE_RENDER_PROP_ACROSS_SERVER): a function cannot cross from a server file into a client
4
- * component. React serialises props across that line, and a function is not serialisable, so `<Client render={() => ...} />`
5
- * from a server file fails at run time (or, with `'use server'`, becomes an action nobody meant). The check reads the render
6
- * graph: a JSX element in a file with no `'use client'` directive whose tag is an app component declared in a file that has
7
- * one, and one of whose props is an arrow or function expression (an inline `'use server'` function is an action and is let
8
- * through). What a block takes as data it renders itself; a callback belongs on the client branch that owns the interaction.
9
- */
10
- export const RENDER_PROP_ACROSS_SERVER_RULE_IDS = ['FE_RENDER_PROP_ACROSS_SERVER'];
11
- const RULE = 'FE_RENDER_PROP_ACROSS_SERVER';
12
- /** Whether a file or a function body opens with the directive prologue string `directive`. */
13
- const hasDirective = (ts, container, directive) => {
14
- for (const statement of container.statements) {
15
- if (!ts.isExpressionStatement(statement) || !ts.isStringLiteral(statement.expression))
16
- return false;
17
- if (statement.expression.text === directive)
18
- return true;
19
- }
20
- return false;
21
- };
22
- export function checkRenderPropAcrossServer(input) {
23
- const { ts } = input.context;
24
- const graph = new RenderGraph(ts, input.graph);
25
- const violations = [];
26
- let serverFiles = 0;
27
- for (const file of input.graph.files.values()) {
28
- if (!/\.tsx$/u.test(file.rel) || /\.(?:spec|test|stories)\.tsx$/u.test(file.rel) || hasDirective(ts, file.sourceFile, 'use client'))
29
- continue;
30
- serverFiles += 1;
31
- const visit = (node) => {
32
- if (ts.isJsxOpeningElement(node) || ts.isJsxSelfClosingElement(node)) {
33
- const tag = graph.tagOf(file.rel, node.tagName);
34
- const target = tag.kind === 'component' ? input.graph.files.get(tag.file) : undefined;
35
- if (tag.kind === 'component' && target && tag.file !== file.rel && hasDirective(ts, target.sourceFile, 'use client')) {
36
- for (const attribute of node.attributes.properties) {
37
- if (!ts.isJsxAttribute(attribute) || !attribute.initializer || !ts.isJsxExpression(attribute.initializer) || !attribute.initializer.expression)
38
- continue;
39
- const value = attribute.initializer.expression;
40
- if (!ts.isArrowFunction(value) && !ts.isFunctionExpression(value))
41
- continue;
42
- const body = value.body;
43
- if (ts.isBlock(body) && hasDirective(ts, body, 'use server'))
44
- continue;
45
- const where = graph.locate({ file: file.rel, node: attribute });
46
- violations.push({
47
- ruleId: RULE, ...where, component: tag.name,
48
- message: `${file.rel} passes a function as \`${ts.isIdentifier(attribute.name) ? attribute.name.text : 'a prop'}\` to ${tag.name}, a client component (${tag.file}), from a server file: a function does not cross the server-client line. Pass data and let ${tag.name} render it, or move the callback into a client branch that owns the interaction.`,
49
- });
50
- }
51
- }
52
- }
53
- ts.forEachChild(node, visit);
54
- };
55
- visit(file.sourceFile);
56
- }
57
- return { violations, coverage: { status: 'checked', serverFiles } };
58
- }