@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,425 +0,0 @@
1
- import path from 'node:path';
2
- import { canonical, isInside } from './config.mjs';
3
- import { parseContract, installedSWR } from './next-data-contract.mjs';
4
- import { relativePath, unwrapExpression } from './typescript.mjs';
5
- import { anyDescendant, normalizedSymbol, normalizedSymbolValue, valueSymbol as sharedValueSymbol } from './ast-walks.mjs';
6
- import { sourceLocation } from '../../lib/ts-ast.mjs';
7
- import { byCodeUnit } from '../../lib/list.mjs';
8
- import { createNextDataKeyInspector } from './next-data-key.mjs';
9
- import { functionNode, constInitializer, inferredSymbol } from './next-data-symbols.mjs';
10
- import { inferredFetcher, inferredIdentities, inferredKeyBindings } from './next-data-inference.mjs';
11
- export const SWR_KEY_RULE_ID = 'FE_SWR_KEY_IDENTITY';
12
- export const SWR_MUTATION_RULE_ID = 'FE_SWR_MUTATION_RESOURCE_IDENTITY';
13
- export const SWR_DATA_RULE_IDS = [SWR_KEY_RULE_ID, SWR_MUTATION_RULE_ID];
14
- const SWR_SPECIFIERS = new Set(['swr', 'swr/immutable', 'swr/mutation']);
15
- /* null when the expression selects no name at all (the shared default traces the unselected node itself). */
16
- const valueSymbol = (ts, checker, expression, seen = new Set()) => sharedValueSymbol(ts, checker, expression, seen, { unselected: 'null' });
17
- function declarationsInside(symbol, root) {
18
- const declarations = symbol?.getDeclarations?.() ?? [];
19
- return declarations.length > 0 && declarations.every(declaration => isInside(root, canonical(declaration.getSourceFile().fileName)));
20
- }
21
- function selectedImportBindings(ts, statement, selected) {
22
- if (!ts.isImportDeclaration(statement) || !statement.importClause)
23
- return 0;
24
- const clause = statement.importClause;
25
- let count = clause.name && selected.has('default') ? 1 : 0;
26
- const bindings = clause.namedBindings;
27
- if (bindings && ts.isNamespaceImport(bindings))
28
- count += 1;
29
- if (bindings && ts.isNamedImports(bindings))
30
- count += bindings.elements
31
- .filter(element => selected.has(element.propertyName?.text ?? element.name.text)).length;
32
- return count;
33
- }
34
- function addOfficialExports(official, checker, statement, selected, targets) {
35
- const { config, context, installed, reasons } = official;
36
- const moduleSymbol = checker.getSymbolAtLocation(statement.moduleSpecifier);
37
- if (!moduleSymbol) {
38
- reasons.push(`${relativePath(config.root, statement.getSourceFile().fileName)} cannot resolve ${statement.moduleSpecifier.text} through the target TypeScript program`);
39
- return false;
40
- }
41
- const exports = new Map(checker.getExportsOfModule(moduleSymbol).map((symbol) => [symbol.getName(), normalizedSymbolValue(context.ts, checker, symbol)]));
42
- for (const [name, kind] of selected) {
43
- const target = exports.get(name);
44
- if (!target)
45
- continue;
46
- if (!declarationsInside(target, installed.root)) {
47
- reasons.push(`${relativePath(config.root, statement.getSourceFile().fileName)} resolves ${statement.moduleSpecifier.text}#${name} outside installed swr ${installed.version}`);
48
- continue;
49
- }
50
- targets.set(target, kind);
51
- }
52
- return true;
53
- }
54
- function addOfficialStatement(official, wanted, checker, statement, targets) {
55
- const ts = official.context.ts;
56
- if (!ts.isImportDeclaration(statement) && !ts.isExportDeclaration(statement))
57
- return 0;
58
- if (!statement.moduleSpecifier || !ts.isStringLiteralLike(statement.moduleSpecifier))
59
- return 0;
60
- const selected = wanted.get(statement.moduleSpecifier.text);
61
- if (!selected)
62
- return 0;
63
- if (!addOfficialExports(official, checker, statement, selected, targets))
64
- return 0;
65
- return selectedImportBindings(ts, statement, selected);
66
- }
67
- function officialTargets(config, context, installed, reasons) {
68
- const wanted = new Map([
69
- ['swr', new Map([['default', 'query'], ['mutate', 'global-mutate'], ['useSWRConfig', 'config']])],
70
- ['swr/immutable', new Map([['default', 'query']])],
71
- ['swr/mutation', new Map([['default', 'mutation'], ['useSWRMutation', 'mutation']])],
72
- ]);
73
- const targets = new Map();
74
- const official = { config, context, installed, reasons };
75
- let selectedBindings = 0;
76
- for (const source of context.files) {
77
- const checker = context.checkerFor(source.fileName);
78
- for (const statement of source.statements)
79
- selectedBindings += addOfficialStatement(official, wanted, checker, statement, targets);
80
- }
81
- return { targets, selectedBindings };
82
- }
83
- function callKind(ts, checker, call, targets, configMutates = new Set()) {
84
- const symbol = valueSymbol(ts, checker, call.expression);
85
- return configMutates.has(symbol) ? 'global-mutate' : (symbol ? targets.get(symbol) : undefined) ?? null;
86
- }
87
- function bindingNames(ts, name) {
88
- if (ts.isIdentifier(name))
89
- return [name.text];
90
- if (ts.isObjectBindingPattern(name) || ts.isArrayBindingPattern(name))
91
- return name.elements.flatMap(element => {
92
- if (!element || ts.isOmittedExpression(element))
93
- return [];
94
- return bindingNames(ts, element.name);
95
- });
96
- return [];
97
- }
98
- function resultBindings(ts, call) {
99
- let current = call;
100
- while (current.parent && (ts.isParenthesizedExpression(current.parent) || ts.isAsExpression(current.parent)
101
- || ts.isTypeAssertionExpression(current.parent) || ts.isNonNullExpression(current.parent)
102
- || (ts.isSatisfiesExpression?.(current.parent) ?? false)
103
- || ((ts.isPropertyAccessExpression(current.parent) || ts.isElementAccessExpression(current.parent)) && current.parent.expression === current))) {
104
- current = current.parent;
105
- }
106
- return current.parent && ts.isVariableDeclaration(current.parent) && current.parent.initializer === current
107
- ? bindingNames(ts, current.parent.name) : [];
108
- }
109
- function nearestFunction(ts, node) {
110
- for (let current = node.parent; current; current = current.parent)
111
- if (ts.isFunctionDeclaration(current)
112
- || ts.isFunctionExpression(current) || ts.isArrowFunction(current) || ts.isMethodDeclaration(current))
113
- return current;
114
- return null;
115
- }
116
- function configElementProperty(ts, element) {
117
- return element.propertyName && ts.isIdentifier(element.propertyName) ? element.propertyName.text
118
- : (ts.isIdentifier(element.name) && element.name.text) || null;
119
- }
120
- function addConfigMutateSymbols(ts, checker, node, targets, symbols) {
121
- if (!(ts.isVariableDeclaration(node) && ts.isObjectBindingPattern(node.name) && node.initializer))
122
- return;
123
- const call = unwrapExpression(ts, node.initializer);
124
- if (!ts.isCallExpression(call) || callKind(ts, checker, call, targets) !== 'config')
125
- return;
126
- for (const element of node.name.elements) {
127
- if (configElementProperty(ts, element) === 'mutate' && ts.isIdentifier(element.name))
128
- symbols.add(normalizedSymbol(ts, checker, element.name));
129
- }
130
- }
131
- function configMutateSymbols(_config, context, targets) {
132
- const { ts } = context;
133
- const symbols = new Set();
134
- for (const source of context.files) {
135
- const checker = context.checkerFor(source.fileName);
136
- const visit = (node) => {
137
- addConfigMutateSymbols(ts, checker, node, targets, symbols);
138
- ts.forEachChild(node, visit);
139
- };
140
- visit(source);
141
- }
142
- return symbols;
143
- }
144
- function discoverCalls(config, context, targets) {
145
- const configMutates = configMutateSymbols(config, context, targets);
146
- const calls = [];
147
- for (const source of context.files) {
148
- const checker = context.checkerFor(source.fileName);
149
- const visit = (node) => {
150
- if (context.ts.isCallExpression(node)) {
151
- const kind = callKind(context.ts, checker, node, targets, configMutates);
152
- if (kind && kind !== 'config')
153
- calls.push({ kind, node, source, checker, owner: nearestFunction(context.ts, node), bindings: resultBindings(context.ts, node) });
154
- }
155
- context.ts.forEachChild(node, visit);
156
- };
157
- visit(source);
158
- }
159
- return calls;
160
- }
161
- function exportedHook(config, context, entry, reasons) {
162
- const source = context.files.find(candidate => canonical(candidate.fileName) === canonical(path.join(config.root, ...entry.path.split('/'))));
163
- if (!source) {
164
- reasons.push(`${entry.path} is outside the canonical production TypeScript program`);
165
- return null;
166
- }
167
- const checker = context.checkerFor(source.fileName);
168
- const moduleSymbol = checker.getSymbolAtLocation(source);
169
- const exported = moduleSymbol ? checker.getExportsOfModule(moduleSymbol).find(symbol => symbol.getName() === entry.export) : null;
170
- const symbol = normalizedSymbolValue(context.ts, checker, exported);
171
- const declarations = (symbol?.getDeclarations?.() ?? []).filter(declaration => canonical(declaration.getSourceFile().fileName) === canonical(source.fileName));
172
- const functions = declarations.map(declaration => functionNode(context.ts, declaration)).filter((fn) => fn !== null);
173
- if (functions.length !== 1) {
174
- reasons.push(`${entry.path}#${entry.export} does not resolve to one local exported hook implementation`);
175
- return null;
176
- }
177
- return { source, checker, fn: functions[0] };
178
- }
179
- function addBindingName(ts, checker, found, name) {
180
- if (ts.isIdentifier(name)) {
181
- const symbol = normalizedSymbol(ts, checker, name);
182
- if (!symbol)
183
- return;
184
- if (!found.has(name.text))
185
- found.set(name.text, new Set());
186
- found.get(name.text)?.add(symbol);
187
- return;
188
- }
189
- if (ts.isObjectBindingPattern(name) || ts.isArrayBindingPattern(name))
190
- for (const element of name.elements) {
191
- if (element && !ts.isOmittedExpression(element))
192
- addBindingName(ts, checker, found, element.name);
193
- }
194
- }
195
- function bindingSymbols(ts, checker, fn) {
196
- const found = new Map();
197
- for (const parameter of fn.parameters)
198
- addBindingName(ts, checker, found, parameter.name);
199
- const visit = (node) => {
200
- if (node !== fn && (ts.isFunctionDeclaration(node) || ts.isFunctionExpression(node) || ts.isArrowFunction(node) || ts.isMethodDeclaration(node)))
201
- return;
202
- if (ts.isVariableDeclaration(node))
203
- addBindingName(ts, checker, found, node.name);
204
- ts.forEachChild(node, visit);
205
- };
206
- if (fn.body)
207
- visit(fn.body);
208
- return found;
209
- }
210
- function resolvedIdentities(ts, checker, fn, entry, reasons) {
211
- const symbols = bindingSymbols(ts, checker, fn);
212
- const identities = [];
213
- for (const identity of entry.identities) {
214
- const parts = identity.binding.split('.');
215
- const candidates = symbols.get(parts[0]) ?? new Set();
216
- if (candidates.size !== 1) {
217
- reasons.push(`${entry.path}#${entry.export} cannot resolve one local binding for identity ${identity.id} (${identity.binding})`);
218
- continue;
219
- }
220
- identities.push({ ...identity, parts, symbol: [...candidates][0] });
221
- }
222
- return identities.length === entry.identities.length ? identities : null;
223
- }
224
- function violation(config, call, ruleId, message, extra = {}) {
225
- return { ruleId, path: relativePath(config.root, call.source.fileName), ...sourceLocation(call.source, call.node), message, ...extra };
226
- }
227
- const keyInspectorDependencies = { anyDescendant, normalizedSymbol, unwrapExpression, constInitializer, sourceLocation, violation,
228
- SWR_KEY_RULE_ID, SWR_MUTATION_RULE_ID };
229
- const inspectKey = createNextDataKeyInspector(keyInspectorDependencies);
230
- const inspectInferredKey = createNextDataKeyInspector({ ...keyInspectorDependencies, normalizedSymbol: inferredSymbol });
231
- function isUnshadowedCommonJsRequire(ts, checker, expression, seen = new Set(), depth = 0) {
232
- expression = unwrapExpression(ts, expression);
233
- if (!ts.isIdentifier(expression) || depth > 10)
234
- return false;
235
- const symbol = checker.getSymbolAtLocation(expression);
236
- const declarations = symbol?.getDeclarations?.() ?? [];
237
- if (expression.text === 'require' && (!symbol
238
- || declarations.every(declaration => declaration.getSourceFile().isDeclarationFile)))
239
- return true;
240
- const normalized = symbolOfRequireAlias(ts, checker, expression);
241
- if (!normalized || seen.has(normalized))
242
- return false;
243
- const initializer = constInitializer(ts, normalized);
244
- return initializer ? isUnshadowedCommonJsRequire(ts, checker, initializer, new Set(seen).add(normalized), depth + 1) : false;
245
- }
246
- function symbolOfRequireAlias(ts, checker, expression) {
247
- const symbol = checker.getSymbolAtLocation(expression);
248
- return normalizedSymbolValue(ts, checker, symbol);
249
- }
250
- function isSwrModuleDeclaration(ts, node) {
251
- return (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) && node.moduleSpecifier
252
- && ts.isStringLiteralLike(node.moduleSpecifier) && SWR_SPECIFIERS.has(node.moduleSpecifier.text);
253
- }
254
- /** The kind of unsupported SWR binding the node declares, else null. */
255
- function unsupportedSwrBinding(ts, checker, node) {
256
- if (ts.isImportEqualsDeclaration(node) && ts.isExternalModuleReference(node.moduleReference)
257
- && node.moduleReference.expression && ts.isStringLiteralLike(node.moduleReference.expression)
258
- && SWR_SPECIFIERS.has(node.moduleReference.expression.text))
259
- return 'import-equals binding';
260
- if (ts.isCallExpression(node) && node.arguments.length >= 1 && ts.isStringLiteralLike(node.arguments[0])
261
- && SWR_SPECIFIERS.has(node.arguments[0].text)) {
262
- if (node.expression.kind === ts.SyntaxKind.ImportKeyword)
263
- return 'dynamic import binding';
264
- if (isUnshadowedCommonJsRequire(ts, checker, node.expression))
265
- return 'CommonJS require binding';
266
- }
267
- return null;
268
- }
269
- function swrReferences(config, context) {
270
- const { ts } = context;
271
- let found = false;
272
- const unsupported = [];
273
- for (const source of context.files) {
274
- const checker = context.checkerFor(source.fileName);
275
- const visit = (node) => {
276
- if (isSwrModuleDeclaration(ts, node))
277
- found = true;
278
- const kind = unsupportedSwrBinding(ts, checker, node);
279
- if (kind) {
280
- found = true;
281
- unsupported.push(`${relativePath(config.root, source.fileName)}:${sourceLocation(source, node).line} uses unsupported ${kind} for SWR`);
282
- }
283
- ts.forEachChild(node, visit);
284
- };
285
- visit(source);
286
- }
287
- return { found, unsupported };
288
- }
289
- function unavailableDataLifecycle(ruleIds, details) {
290
- return { violations: [], coverage: { status: 'unavailable', ruleIds, details } };
291
- }
292
- function lifecycleCallSets(config, context, installed, reasons) {
293
- const official = officialTargets(config, context, installed, reasons);
294
- const calls = discoverCalls(config, context, official.targets);
295
- const lifecycleCalls = calls.filter(call => call.kind === 'query' || call.kind === 'mutation');
296
- const globalMutates = calls.filter(call => call.kind === 'global-mutate');
297
- if (official.selectedBindings && lifecycleCalls.length === 0)
298
- reasons.push('selected SWR hook imports have no statically resolved lifecycle call');
299
- for (const call of globalMutates)
300
- reasons.push(`${relativePath(config.root, call.source.fileName)}:${sourceLocation(call.source, call.node).line} uses global mutate; resource matching or filter semantics are not statically declared`);
301
- return { lifecycleCalls };
302
- }
303
- function hookEntries(config, context, contract, reasons) {
304
- const hookCache = new Map();
305
- const entriesByHook = new Map();
306
- for (const entry of contract.hooks) {
307
- const key = `${entry.path}\0${entry.export}`;
308
- if (!entriesByHook.has(key))
309
- entriesByHook.set(key, []);
310
- entriesByHook.get(key)?.push(entry);
311
- if (!hookCache.has(key))
312
- hookCache.set(key, exportedHook(config, context, entry, reasons));
313
- }
314
- return { hookCache, entriesByHook };
315
- }
316
- function inspectLifecycleEntry(scope, entry, hookCalls, mapped) {
317
- const { config, context, violations, reasons } = scope;
318
- const { entries, owned, hook } = hookCalls;
319
- let candidates;
320
- if (entry.resultBinding !== undefined)
321
- candidates = owned.filter(call => call.bindings.includes(entry.resultBinding));
322
- else
323
- candidates = owned.length === 1 && entries.length === 1 ? owned : [];
324
- if (candidates.length !== 1) {
325
- reasons.push(`${entry.path}#${entry.export} lifecycle ${entry.id} must select exactly one SWR call${owned.length > 1 ? ' with resultBinding' : ''}`);
326
- return;
327
- }
328
- const call = candidates[0];
329
- mapped.set(call, (mapped.get(call) ?? 0) + 1);
330
- if (call.kind !== entry.kind) {
331
- reasons.push(`${entry.path}#${entry.export} lifecycle ${entry.id} declares ${entry.kind} but resolves ${call.kind}`);
332
- return;
333
- }
334
- const identities = resolvedIdentities(context.ts, hook.checker, hook.fn, entry, reasons);
335
- if (identities)
336
- inspectKey(config, context, entry, call, identities, violations, reasons);
337
- }
338
- function inspectHookLifecycle(config, context, lifecycleCalls, hookCache, entriesByHook, violations, reasons) {
339
- const mapped = new Map();
340
- const scope = { config, context, violations, reasons };
341
- for (const [key, entries] of entriesByHook) {
342
- const hook = hookCache.get(key);
343
- if (!hook)
344
- continue;
345
- const owned = lifecycleCalls.filter(call => call.owner === hook.fn);
346
- if (!owned.length) {
347
- reasons.push(`${entries[0].path}#${entries[0].export} contains no statically resolved SWR lifecycle call`);
348
- continue;
349
- }
350
- for (const entry of entries)
351
- inspectLifecycleEntry(scope, entry, { entries, owned, hook }, mapped);
352
- for (const call of owned)
353
- if ((mapped.get(call) ?? 0) !== 1) {
354
- reasons.push(`${relativePath(config.root, call.source.fileName)}:${sourceLocation(call.source, call.node).line} SWR call is not matched by exactly one declared lifecycle`);
355
- }
356
- }
357
- return mapped;
358
- }
359
- function addUndeclaredLifecycleReasons(config, lifecycleCalls, hookCache, reasons) {
360
- const declaredFunctions = new Set([...hookCache.values()].filter((item) => item !== null).map(item => item.fn));
361
- for (const call of lifecycleCalls)
362
- if (!declaredFunctions.has(call.owner)) {
363
- reasons.push(`${relativePath(config.root, call.source.fileName)}:${sourceLocation(call.source, call.node).line} SWR call is outside every declared lifecycle hook`);
364
- }
365
- }
366
- function lifecycleCoverage(ruleIds, contract, installed, calls, details) {
367
- return details.length ? { status: 'unavailable', ruleIds, hooks: contract.hooks.length, calls,
368
- swr: { name: installed.name, version: installed.version, major: installed.major }, details }
369
- : { status: 'checked', ruleIds, hooks: contract.hooks.length, calls,
370
- swr: { name: installed.name, version: installed.version, major: installed.major } };
371
- }
372
- function inspectDefaultLifecycle(config, context, installed, lifecycleCalls, violations, reasons) {
373
- for (const call of lifecycleCalls) {
374
- const fetcher = inferredFetcher(context.ts, call.checker, call.node.arguments[1]);
375
- if (!fetcher) {
376
- reasons.push(`${relativePath(config.root, call.source.fileName)}:${sourceLocation(call.source, call.node).line} fetcher inputs cannot be inferred; dataLifecycle is required to declare identities`);
377
- continue;
378
- }
379
- const entry = { id: `swr:${relativePath(config.root, call.source.fileName)}:${sourceLocation(call.source, call.node).line}`,
380
- path: relativePath(config.root, call.source.fileName), export: call.owner?.name?.text ?? '<inferred hook>', kind: call.kind };
381
- const identities = inferredIdentities(context, call, fetcher, reasons);
382
- const selected = new Set(identities.map(identity => identity.id));
383
- const findings = [];
384
- inspectInferredKey(config, context, entry, call, [...identities, ...inferredKeyBindings(context, call, reasons)], findings, reasons);
385
- violations.push(...findings.filter(finding => finding.identity === undefined || selected.has(finding.identity)));
386
- }
387
- const details = [...new Set(reasons)].sort(byCodeUnit);
388
- return { violations, coverage: lifecycleCoverage([...SWR_DATA_RULE_IDS], { hooks: lifecycleCalls }, installed, lifecycleCalls.length, details) };
389
- }
390
- /** Check declared lifecycles, or infer captured request identities when production SWR has no declaration. */
391
- export function checkFrontendDataLifecycle(config, context) {
392
- const ruleIds = [...SWR_DATA_RULE_IDS];
393
- const references = swrReferences(config, context);
394
- let contract;
395
- try {
396
- contract = parseContract(config);
397
- }
398
- catch (error) {
399
- return unavailableDataLifecycle(ruleIds, [String(error.message ?? error)]);
400
- }
401
- if (!contract && !references.found)
402
- return { violations: [], coverage: { status: 'not-applicable', ruleIds } };
403
- const reasons = [];
404
- const violations = [];
405
- reasons.push(...references.unsupported);
406
- if (!contract && references.unsupported.length)
407
- reasons.push('package.json#starci.codePatterns.next.dataLifecycle is required for unsupported SWR bindings');
408
- let installed;
409
- try {
410
- installed = installedSWR(config.packageRoot ?? config.root);
411
- }
412
- catch (error) {
413
- return { violations, coverage: { status: 'unavailable', ruleIds, details: [String(error.message ?? error)] } };
414
- }
415
- if (contract && installed.major !== contract.swr.major)
416
- reasons.push(`installed swr ${installed.version} does not match declared major ${contract.swr.major}`);
417
- const { lifecycleCalls } = lifecycleCallSets(config, context, installed, reasons);
418
- if (!contract)
419
- return inspectDefaultLifecycle(config, context, installed, lifecycleCalls, violations, reasons);
420
- const { hookCache, entriesByHook } = hookEntries(config, context, contract, reasons);
421
- inspectHookLifecycle(config, context, lifecycleCalls, hookCache, entriesByHook, violations, reasons);
422
- addUndeclaredLifecycleReasons(config, lifecycleCalls, hookCache, reasons);
423
- const details = [...new Set(reasons)].sort(byCodeUnit);
424
- return { violations, coverage: lifecycleCoverage(ruleIds, contract, installed, lifecycleCalls.length, details) };
425
- }
@@ -1,55 +0,0 @@
1
- /** The app emitter consumes the API app's declared operation table without importing it from app.module.ts. */
2
- import path from 'node:path';
3
- import { hasAnyFlag } from '../../lib/ts-ast.mjs';
4
- const actualSymbol = (ts, checker, symbol) => symbol && hasAnyFlag(symbol.flags, ts.SymbolFlags.Alias) ? checker.getAliasedSymbol(symbol) : symbol;
5
- /** Follow declaration aliases while retaining the actual expression rather than an asserted type. */
6
- const initializerOf = (ts, checker, node, seen = new Set()) => {
7
- if (!node || seen.has(node))
8
- return null;
9
- seen.add(node);
10
- if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isTypeAssertionExpression(node)
11
- || ts.isSatisfiesExpression(node) || ts.isNonNullExpression(node))
12
- return initializerOf(ts, checker, node.expression, seen);
13
- if (!ts.isIdentifier(node) && !ts.isPropertyAccessExpression(node))
14
- return node;
15
- const declaration = actualSymbol(ts, checker, checker.getSymbolAtLocation(node))?.valueDeclaration; // reason: a value declaration may or may not be a variable declaration; `initializer` is read only when present
16
- return declaration?.initializer ? initializerOf(ts, checker, declaration.initializer, seen) : node;
17
- };
18
- /** A same-named local function cannot declare the platform operation contract. */
19
- const isOperationDefiner = (ts, checker, graph, config, expression, seen = new Set()) => {
20
- const symbol = actualSymbol(ts, checker, checker.getSymbolAtLocation(expression));
21
- if (!symbol || seen.has(symbol))
22
- return false;
23
- seen.add(symbol);
24
- return (symbol.declarations ?? []).some((declaration) => {
25
- const relative = path.relative(config.root, declaration.getSourceFile().fileName).split(path.sep).join('/');
26
- const owner = graph.resolver.ownerOf(relative);
27
- if (declaration.name?.text === 'defineOperations' && owner?.slot === 'be.platform' && path.posix.basename(owner.root) === 'operations')
28
- return true;
29
- const alias = declaration.initializer;
30
- return Boolean(alias && (ts.isIdentifier(alias) || ts.isPropertyAccessExpression(alias)) && isOperationDefiner(ts, checker, graph, config, alias, seen));
31
- });
32
- };
33
- /** True only for an exported, nonempty registration by the canon platform capability. */
34
- const declaresOperations = (context, graph, config, sourceFile) => {
35
- const { ts } = context;
36
- const checker = context.checkerFor?.(sourceFile.fileName);
37
- const moduleSymbol = checker?.getSymbolAtLocation(sourceFile);
38
- if (!checker || !moduleSymbol)
39
- return false;
40
- const exported = checker.getExportsOfModule(moduleSymbol).find(symbol => symbol.getName() === 'OPERATIONS');
41
- const declaration = actualSymbol(ts, checker, exported)?.valueDeclaration; // reason: see initializerOf
42
- const registration = initializerOf(ts, checker, declaration?.initializer);
43
- if (!registration || !ts.isCallExpression(registration) || !isOperationDefiner(ts, checker, graph, config, registration.expression))
44
- return false;
45
- const entries = initializerOf(ts, checker, registration.arguments[0]);
46
- return entries !== null && ts.isObjectLiteralExpression(entries) && checker.getPropertiesOfType(checker.getTypeAtLocation(entries)).length > 0;
47
- };
48
- /** Only the emitter's exact entry of a declared API app is a contract root; workers and arbitrary app files remain judged. */
49
- export function operationContractRoots(context, graph, config) {
50
- return (config.apps ?? []).filter(app => app.kind === 'api').flatMap(app => {
51
- const relative = `apps/${app.name}/src/operations.ts`;
52
- const node = graph.files.get(relative);
53
- return node?.tier === 'app' && node.slot === 'be.app.api' && declaresOperations(context, graph, config, node.sourceFile) ? [relative] : [];
54
- });
55
- }
@@ -1,142 +0,0 @@
1
- import path from 'node:path';
2
- import { canonical, isInside } from './config.mjs';
3
- import { relativePath, workspaceExportSources } from './typescript.mjs';
4
- import { sourceLocation } from '../../lib/ts-ast.mjs';
5
- import { globExpression } from '../../lib/glob.mjs';
6
- import { posixPath } from '../../lib/path-key.mjs';
7
- import { registryImporter, registrySlot } from './entity-registry.mjs';
8
- function absolute(root, relative) {
9
- return canonical(path.resolve(root, ...relative.split('/')));
10
- }
11
- /**
12
- * The extra public entries the slot manifest declares for the owner (slot field `entries`, on the slot that holds its entry file):
13
- * exact files as absolute paths, and the entries holding a `*` (one file per operation, `graphql/queries/query-*.ts`) as patterns.
14
- */
15
- function slotEntries(config, owner) {
16
- const found = config.hfs?.classifyPath?.(owner.entry);
17
- if (!found?.slot)
18
- return { exact: [], patterns: [] };
19
- const names = config.hfs.slot(found.slot)?.entries ?? [];
20
- const exact = names.filter(name => !name.includes('*')).map(name => absolute(config.root, `${found.root}/${name}`));
21
- const patterns = names.filter(name => name.includes('*')).map(name => globExpression(`${posixPath(absolute(config.root, found.root))}/${name}`));
22
- return { exact, patterns };
23
- }
24
- /** The owner's public entries: its declared entry, the `entries` its slot declares, plus every source file its package.json `exports` maps when the owner is a workspace package. */
25
- function ownerDeclarations(config, context) {
26
- return config.owners.map((owner) => {
27
- const root = absolute(config.root, owner.root);
28
- const entry = absolute(config.root, owner.entry);
29
- const workspace = context.workspaces?.find(item => item.root === root);
30
- const { exact: declared, patterns } = slotEntries(config, owner);
31
- const entries = new Set([entry, ...declared, ...(workspace ? workspaceExportSources(context.ts, workspace) : [])]);
32
- const isEntry = (file) => entries.has(file) || patterns.some(pattern => pattern.test(posixPath(file)));
33
- return { ...owner, root, entry, entries, isEntry, declared };
34
- }).sort((a, b) => b.root.length - a.root.length);
35
- }
36
- function ownerOf(owners, file) {
37
- return owners.find(owner => isInside(owner.root, file)) ?? null;
38
- }
39
- function reexportSteps(context, current) {
40
- return (context.edges.get(current.file) ?? []).filter(candidate => candidate.reexport).map(candidate => ({ file: candidate.to, chain: [...current.chain, candidate.to] }));
41
- }
42
- function privateOwnerChain(context, owners, edge) {
43
- const sourceOwner = ownerOf(owners, edge.from);
44
- const queue = [{ file: edge.to, chain: [edge.from, edge.to] }];
45
- const visited = new Set();
46
- for (let current = queue.shift(); current; current = queue.shift()) {
47
- if (visited.has(current.file))
48
- continue;
49
- visited.add(current.file);
50
- const owner = ownerOf(owners, current.file);
51
- if (owner && sourceOwner?.id !== owner.id)
52
- return owner.isEntry(current.file) ? null : { owner, chain: current.chain };
53
- queue.push(...reexportSteps(context, current));
54
- }
55
- return null;
56
- }
57
- /**
58
- * A `*.builder.ts` of slot be.tests.fixtures.builders arranges data at the schema level: it may deep-import the persistence
59
- * entity classes and connection entity lists (slot be.persistence) of any capability. No other file may.
60
- */
61
- function arrangesSchema(config, from, to) {
62
- const resolver = config.hfs;
63
- if (!resolver?.classifyPath)
64
- return false;
65
- return resolver.classifyPath(relativePath(config.root, from)).slot === 'be.tests.fixtures.builders'
66
- && resolver.classifyPath(relativePath(config.root, to)).slot === 'be.persistence';
67
- }
68
- /**
69
- * The entity registry (slot role entity-registry, entity-registry.mjs) is imported by deep path, and only from the files its slot's
70
- * `importedBy` names: app composition and the test world. Any other importer goes through the owner's entry, which never exports it.
71
- */
72
- function importsRegistry(config, from, to) {
73
- const slot = registrySlot(config.hfs, relativePath(config.root, to));
74
- return slot !== null && registryImporter(config.hfs, slot, relativePath(config.root, from));
75
- }
76
- function publicEntryViolations(config, context, owners, sourceFiles) {
77
- const violations = [];
78
- for (const owner of owners) {
79
- const sourceFile = sourceFiles.get(owner.entry);
80
- if (!sourceFile) {
81
- violations.push({ ruleId: 'ARCH_OWNER_EXPORT_BYPASS', path: relativePath(config.root, owner.entry), line: 1, column: 1, owner: owner.id,
82
- message: `Owner ${owner.id} public entry is outside the configured TypeScript programs, so its boundary cannot be checked.` });
83
- continue;
84
- }
85
- const publicFiles = new Set([
86
- sourceFile,
87
- ...owner.declared.map(file => sourceFiles.get(file)).filter((file) => Boolean(file)),
88
- ]);
89
- for (const entryFile of publicFiles) {
90
- for (const statement of entryFile.statements)
91
- if (context.ts.isExportDeclaration(statement) && !statement.exportClause) {
92
- violations.push({
93
- ruleId: 'ARCH_OWNER_EXPORT_STAR',
94
- path: relativePath(config.root, canonical(entryFile.fileName)),
95
- ...sourceLocation(entryFile, statement),
96
- owner: owner.id,
97
- message: `Owner ${owner.id} public entry must use explicit named exports rather than export *.`,
98
- });
99
- }
100
- }
101
- }
102
- return violations;
103
- }
104
- function ownerImportViolations(config, context, owners) {
105
- const violations = [];
106
- for (const sourceFile of context.files) {
107
- const from = canonical(sourceFile.fileName);
108
- for (const edge of context.edges.get(from) ?? []) {
109
- const bypass = privateOwnerChain(context, owners, edge);
110
- if (!bypass)
111
- continue;
112
- const target = bypass.chain.at(-1) ?? edge.to;
113
- if (arrangesSchema(config, from, target))
114
- continue;
115
- if (bypass.chain.length === 2 && importsRegistry(config, from, target))
116
- continue;
117
- violations.push({
118
- ruleId: 'ARCH_OWNER_EXPORT_BYPASS',
119
- path: relativePath(config.root, from),
120
- line: edge.line,
121
- column: edge.column,
122
- owner: bypass.owner.id,
123
- specifier: edge.specifier,
124
- resolvedPath: relativePath(config.root, target),
125
- dependencyChain: bypass.chain.map(file => relativePath(config.root, file)),
126
- message: `Cross-owner dependency must enter ${bypass.owner.id} through ${relativePath(config.root, bypass.owner.entry)}.`,
127
- });
128
- }
129
- }
130
- return violations;
131
- }
132
- /** Enforce explicit same-source owner entries without constraining imports inside one owner. */
133
- export function checkOwners(config, context) {
134
- if (!config.owners?.length)
135
- return [];
136
- const owners = ownerDeclarations(config, context);
137
- const sourceFiles = new Map(context.files.map((file) => [canonical(file.fileName), file]));
138
- return [
139
- ...publicEntryViolations(config, context, owners, sourceFiles),
140
- ...ownerImportViolations(config, context, owners),
141
- ];
142
- }