@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,402 +0,0 @@
1
- import path from 'node:path';
2
- import { canonical, loadArchitectureConfig } from './config.mjs';
3
- import { sameOrUnder } from '../../lib/path-key.mjs';
4
- import { buildTypeScriptContext, relativePath } from './typescript.mjs';
5
- import { withTypeScriptProgramRun } from '../typescript-programs.mjs';
6
- import { checkBackend } from './backend.mjs';
7
- import { checkBackendContracts, PUBLIC_CONTRACT_RULE_ID, READONLY_BOUNDARY_RULE_ID } from './contracts.mjs';
8
- import { checkFrontend } from './frontend.mjs';
9
- import { checkOwners } from './owners.mjs';
10
- import { checkModuleRegistration, REGISTRATION_RULE_IDS } from './registration.mjs';
11
- import { checkFrontendDataLifecycle, SWR_DATA_RULE_IDS } from './next-data.mjs';
12
- import { checkBackendSourceShape, SOURCE_LAYOUT_RULE_ID, SOURCE_NAME_RULE_ID } from './source-names.mjs';
13
- import { checkHfs, checkHfsWithoutConfig, HFS_RULE_IDS } from './hfs.mjs';
14
- import { buildHfsGraph } from './hfs-graph.mjs';
15
- import { checkTiers, TIER_RULE_IDS } from './tiers.mjs';
16
- import { checkReachability, REACHABILITY_RULE_IDS } from './reachability.mjs';
17
- import { checkDeadExports, DEAD_EXPORT_RULE_IDS } from './dead-exports.mjs';
18
- import { checkRequiredFiles, REQUIRED_FILE_RULE_IDS, withTreeCache } from './required-files.mjs';
19
- import { checkClones, CLONE_RULE_IDS } from './clones.mjs';
20
- import { checkSymbols, SYMBOL_RULE_IDS } from './symbols.mjs';
21
- import { checkConnectionMap, CONNECTION_RULE_IDS } from './connection-map.mjs';
22
- import { checkSqlOwner, SQL_OWNER_RULE_IDS } from './sql-owner.mjs';
23
- import { checkRegisterOnce, REGISTER_ONCE_RULE_IDS } from './register-once.mjs';
24
- import { checkErrorMasked, ERROR_MASKED_RULE_IDS } from './error-masked.mjs';
25
- import { checkDefaultDeny, DEFAULT_DENY_RULE_IDS } from './default-deny.mjs';
26
- import { checkEntrypoints, ENTRYPOINT_RULE_IDS } from './entrypoint.mjs';
27
- import { checkErrorCodes, ERROR_CODE_RULE_IDS } from './error-codes.mjs';
28
- import { checkConfigUnread, CONFIG_UNREAD_RULE_IDS } from './config-unread.mjs';
29
- import { checkFeatureShape, FEATURE_SHAPE_RULE_IDS } from './feature-shape.mjs';
30
- import { checkTestWorldFiles, TEST_WORLD_FILES_RULE_IDS } from './test-world-files.mjs';
31
- import { checkUnitSpecProviders, UNIT_SPEC_PROVIDERS_RULE_IDS } from './unit-spec-providers.mjs';
32
- import { checkInjectionTokenExported, INJECTION_TOKEN_EXPORTED_RULE_IDS } from './injection-token-exported.mjs';
33
- import { checkContractFixtureGuard, CONTRACT_FIXTURE_GUARD_RULE_IDS } from './contract-fixture-guard.mjs';
34
- import { checkSchemaOwner, SCHEMA_OWNER_RULE_IDS } from './schema-owner.mjs';
35
- import { checkSqlReturning, SQL_RETURNING_RULE_IDS } from './sql-returning.mjs';
36
- import { checkContextOwner, CONTEXT_OWNER_RULE_IDS } from './context-owner.mjs';
37
- import { checkContextCoupling, CONTEXT_COUPLING_RULE_IDS } from './context-coupling.mjs';
38
- import { checkContextTransaction, CONTEXT_TRANSACTION_RULE_IDS } from './context-transaction.mjs';
39
- import { checkContextPlatformTables, CONTEXT_PLATFORM_TABLES_RULE_IDS } from './context-platform-tables.mjs';
40
- import { checkModulePerTransport, MODULE_PER_TRANSPORT_RULE_IDS } from './module-per-transport.mjs';
41
- import { checkBackgroundUnowned, BACKGROUND_UNOWNED_RULE_IDS } from './background-unowned.mjs';
42
- import { checkTransportOwner, TRANSPORT_OWNER_RULE_IDS } from './transport-owner.mjs';
43
- import { checkRouteFilesThin, ROUTE_FILES_THIN_RULE_IDS } from './route-files-thin.mjs';
44
- import { checkHooksAreHooks, HOOKS_ARE_HOOKS_RULE_IDS } from './hooks-are-hooks.mjs';
45
- import { checkRenderPropAcrossServer, RENDER_PROP_ACROSS_SERVER_RULE_IDS } from './render-prop-across-server.mjs';
46
- import { checkSurfaceNesting, SURFACE_NESTING_RULE_IDS } from './surface-nesting.mjs';
47
- import { checkClientReachesServer, CLIENT_REACHES_SERVER_RULE_IDS } from './client-reaches-server.mjs';
48
- import { checkCrossAppDuplicate, CROSS_APP_DUPLICATE_RULE_IDS } from './cross-app-duplicate.mjs';
49
- import { checkPackageShape, PACKAGE_SHAPE_RULE_IDS } from './package-shape.mjs';
50
- import { COMPONENT_TIER_RULE_IDS, checkGrammarTiers } from './component-tiers.mjs';
51
- import { checkFeSlotAllows, FE_SLOT_ALLOWS_RULE_IDS } from './fe-slot-allows.mjs';
52
- import { checkI18nKeys, I18N_KEYS_RULE_IDS } from './i18n-keys.mjs';
53
- import { checkDocLanguage, DOC_LANGUAGE_RULE_IDS } from './doc-language.mjs';
54
- import { checkBackendIdentity, IDENTITY_RULE_IDS } from './identity.mjs';
55
- import { checkServerActions, SERVER_ACTION_RULE_IDS } from './server-action.mjs';
56
- import { LINT_CODES, onLintSurface } from './surface.mjs';
57
- import { byCodeUnit } from '../../lib/list.mjs';
58
- export { REGISTRATION_RULE_IDS, SWR_DATA_RULE_IDS };
59
- const LIMITATIONS = [
60
- 'This is a static TypeScript dependency and source-shape check; it does not prove runtime dependency-injection bindings, global/provider scope, state lifetime, server/client behavior, feature-versus-capability ownership, route behavior, or business correctness.',
61
- 'Dependencies hidden behind constructed aliases, reflection, or calls other than direct import()/require() syntax require separate review.',
62
- 'Protocol surfaces selected through reflection, nonliteral computed properties, or aliases constructed beyond static import/re-export bindings require separate review.',
63
- 'Backend source-shape rules classify only resolved roots, declarations, framework symbols, and static decorator arguments; cohesive capability, error, persistence, and migration ownership still require design and runtime evidence.',
64
- 'Backend contract rules prove selected declaration and readonly field forms only; they do not prove runtime validation, serialization compatibility, provider scope, token identity, or dependency behavior.',
65
- 'Frontend SWR lifecycle rules prove declared key bindings and installed SWR identity only; domain identity completeness, stale-result behavior and mutation effects require target behavior evidence.',
66
- ];
67
- // The backend composition and data machine (R29, R32, R33, R35, R38, R39, R41, R45, R46, R47, R48, R84, R85, R86): name -> [check, the rule ids it makes truthful].
68
- const BACKEND_MACHINE = {
69
- connectionMap: [checkConnectionMap, CONNECTION_RULE_IDS],
70
- sqlOwner: [checkSqlOwner, SQL_OWNER_RULE_IDS],
71
- registerOnce: [checkRegisterOnce, REGISTER_ONCE_RULE_IDS],
72
- errorMasked: [checkErrorMasked, ERROR_MASKED_RULE_IDS],
73
- defaultDeny: [checkDefaultDeny, DEFAULT_DENY_RULE_IDS],
74
- entrypoints: [checkEntrypoints, ENTRYPOINT_RULE_IDS],
75
- errorCodes: [checkErrorCodes, ERROR_CODE_RULE_IDS],
76
- featureShape: [checkFeatureShape, FEATURE_SHAPE_RULE_IDS],
77
- unitSpecProviders: [checkUnitSpecProviders, UNIT_SPEC_PROVIDERS_RULE_IDS],
78
- injectionTokenExported: [checkInjectionTokenExported, INJECTION_TOKEN_EXPORTED_RULE_IDS],
79
- schemaOwner: [checkSchemaOwner, SCHEMA_OWNER_RULE_IDS],
80
- sqlReturning: [checkSqlReturning, SQL_RETURNING_RULE_IDS],
81
- contextOwner: [checkContextOwner, CONTEXT_OWNER_RULE_IDS],
82
- contextCoupling: [checkContextCoupling, CONTEXT_COUPLING_RULE_IDS],
83
- contextTransaction: [checkContextTransaction, CONTEXT_TRANSACTION_RULE_IDS],
84
- contextPlatformTables: [checkContextPlatformTables, CONTEXT_PLATFORM_TABLES_RULE_IDS],
85
- modulePerTransport: [checkModulePerTransport, MODULE_PER_TRANSPORT_RULE_IDS],
86
- backgroundUnowned: [checkBackgroundUnowned, BACKGROUND_UNOWNED_RULE_IDS],
87
- testWorldFiles: [checkTestWorldFiles, TEST_WORLD_FILES_RULE_IDS],
88
- contractFixtureGuard: [checkContractFixtureGuard, CONTRACT_FIXTURE_GUARD_RULE_IDS],
89
- identity: [checkBackendIdentity, IDENTITY_RULE_IDS],
90
- };
91
- // The frontend repository machine (R21, R50, R54, R55, R56, R63, R94, R106): same shape, run for a front-end repository only.
92
- const FRONTEND_MACHINE = {
93
- transportOwner: [checkTransportOwner, TRANSPORT_OWNER_RULE_IDS],
94
- routeFilesThin: [checkRouteFilesThin, ROUTE_FILES_THIN_RULE_IDS],
95
- hooksAreHooks: [checkHooksAreHooks, HOOKS_ARE_HOOKS_RULE_IDS],
96
- packageShape: [checkPackageShape, PACKAGE_SHAPE_RULE_IDS],
97
- clientReachesServer: [checkClientReachesServer, CLIENT_REACHES_SERVER_RULE_IDS],
98
- surfaceNesting: [checkSurfaceNesting, SURFACE_NESTING_RULE_IDS],
99
- renderPropAcrossServer: [checkRenderPropAcrossServer, RENDER_PROP_ACROSS_SERVER_RULE_IDS],
100
- crossAppDuplicate: [checkCrossAppDuplicate, CROSS_APP_DUPLICATE_RULE_IDS],
101
- feSlotAllows: [checkFeSlotAllows, FE_SLOT_ALLOWS_RULE_IDS],
102
- i18nKeys: [checkI18nKeys, I18N_KEYS_RULE_IDS],
103
- serverActions: [checkServerActions, SERVER_ACTION_RULE_IDS],
104
- grammarTiers: [checkGrammarTiers, COMPONENT_TIER_RULE_IDS],
105
- };
106
- /** Errors the machine reports when a program cannot be built or an edge cannot be proven: it cannot judge, so it refuses. */
107
- const COMMON_REFUSAL_RULE_IDS = [
108
- 'ARCH_DYNAMIC_DEPENDENCY_UNPROVEN',
109
- 'ARCH_INTERNAL_IMPORT_OUTSIDE',
110
- 'ARCH_INTERNAL_IMPORT_UNRESOLVED',
111
- 'ARCH_NO_SOURCE',
112
- 'ARCH_SYNTAX_INVALID',
113
- 'ARCH_TSCONFIG_INVALID',
114
- 'ARCH_TSCONFIG_MISSING',
115
- 'ARCH_TSCONFIG_REFERENCE_OUTSIDE',
116
- ];
117
- const COMMON_RULE_IDS = [
118
- ...COMMON_REFUSAL_RULE_IDS,
119
- 'ARCH_PACKAGE_EXPORT_BYPASS',
120
- 'ARCH_PACKAGE_IMPORTS_APP',
121
- ];
122
- const BACKEND_RULE_IDS = [
123
- 'BE_APP_BUSINESS_ROLE',
124
- 'BE_APP_COMPOSITION_ONLY',
125
- 'BE_APPLICATION_IMPORTS_TRANSPORT',
126
- 'BE_APPLICATION_TRANSPORT_FRAMEWORK',
127
- ];
128
- const FRONTEND_RULE_IDS = [
129
- 'FE_BLOCK_PRODUCT_HOOK_DEFINITION',
130
- 'FE_COMPONENT_WORLD_OWNERSHIP',
131
- 'FE_COMPONENT_DEEP_HOOK_IMPORT',
132
- 'FE_CONNECTED_BLOCK_RENDER_PAIR',
133
- 'FE_CUSTOM_HOOK_LOCATION',
134
- 'FE_PURE_REACHES_DATA',
135
- 'FE_PURE_WORLD_HOOK',
136
- 'FE_PURE_WORLD_IMPORT',
137
- 'FE_ROUTE_CLIENT_BOUNDARY',
138
- 'FE_ROUTE_CLIENT_HOOK',
139
- 'FE_ROUTE_DEFAULT_EXPORT',
140
- 'FE_ROUTE_DRAWING_DECISION',
141
- 'FE_ROUTE_ONE_PAGE',
142
- 'FE_SOURCE_LAYOUT_INVALID',
143
- 'FE_WORLD_OWNER_RENDER_BOUNDARY',
144
- ];
145
- const OWNER_RULE_IDS = ['ARCH_OWNER_EXPORT_BYPASS', 'ARCH_OWNER_EXPORT_STAR'];
146
- const GRAMMAR_RULE_IDS = ['ARCH_GRAMMAR_CONTRACT_INVALID', 'ARCH_GRAMMAR_EXPORT_BYPASS'];
147
- /**
148
- * Every code the machine reports as an error because it cannot judge (a check that cannot run is an error, never a pass).
149
- * These are infrastructure refusals, not obligations, so no rule of knowledge/hfs/rules.yaml owns them.
150
- */
151
- export const ERROR_RULE_IDS = Object.freeze([
152
- 'ARCH_COMPILER_FAILURE', 'ARCH_CONFIG_INVALID', 'ARCH_EXECUTION_UNAVAILABLE', 'ARCH_KNOWLEDGE_UNAVAILABLE', 'ARCH_TYPESCRIPT_INVALID', 'ARCH_TYPESCRIPT_MISSING',
153
- ...COMMON_REFUSAL_RULE_IDS,
154
- ]);
155
- const machineIds = () => [
156
- ...TIER_RULE_IDS, ...REACHABILITY_RULE_IDS, ...DEAD_EXPORT_RULE_IDS, ...REQUIRED_FILE_RULE_IDS, ...CLONE_RULE_IDS, ...SYMBOL_RULE_IDS,
157
- ...Object.values(BACKEND_MACHINE).flatMap(([, ids]) => ids), ...Object.values(FRONTEND_MACHINE).flatMap(([, ids]) => ids),
158
- ];
159
- /**
160
- * The rules only the HFS machine emits: the tier, reachability, dead-export, required-file, clone and symbol checks and the
161
- * backend composition and data machine and frontend repository machine. A spec about another rule judges its own
162
- * report without these (they have their own specs); every one of them is in ARCHITECTURE_RULE_IDS.
163
- */
164
- export const HFS_MACHINE_RULE_IDS = Object.freeze((() => {
165
- const ordinary = new Set([...COMMON_RULE_IDS, ...BACKEND_RULE_IDS, ...FRONTEND_RULE_IDS, ...OWNER_RULE_IDS, ...GRAMMAR_RULE_IDS, ...REGISTRATION_RULE_IDS,
166
- ...SWR_DATA_RULE_IDS, SOURCE_LAYOUT_RULE_ID, SOURCE_NAME_RULE_ID, PUBLIC_CONTRACT_RULE_ID, READONLY_BOUNDARY_RULE_ID]);
167
- return [...new Set(machineIds().filter((id) => !ordinary.has(id)))].sort(byCodeUnit);
168
- })());
169
- /** Every code the machine can emit, derived from the rule id lists of its checks (`starci app check` ships exactly these why entries). */
170
- export const ARCHITECTURE_RULE_IDS = Object.freeze([...new Set([
171
- ...COMMON_RULE_IDS, ...BACKEND_RULE_IDS, ...FRONTEND_RULE_IDS, ...HFS_RULE_IDS, ...TIER_RULE_IDS, ...REACHABILITY_RULE_IDS,
172
- ...DEAD_EXPORT_RULE_IDS, ...DOC_LANGUAGE_RULE_IDS, ...REQUIRED_FILE_RULE_IDS, ...CLONE_RULE_IDS, ...OWNER_RULE_IDS, ...GRAMMAR_RULE_IDS,
173
- ...REGISTRATION_RULE_IDS, ...SWR_DATA_RULE_IDS, ...SYMBOL_RULE_IDS, SOURCE_LAYOUT_RULE_ID, SOURCE_NAME_RULE_ID, PUBLIC_CONTRACT_RULE_ID,
174
- READONLY_BOUNDARY_RULE_ID, ...ERROR_RULE_IDS, ...CONFIG_UNREAD_RULE_IDS, ...Object.values(BACKEND_MACHINE).flatMap(([, ids]) => ids), ...Object.values(FRONTEND_MACHINE).flatMap(([, ids]) => ids),
175
- ])].sort(byCodeUnit));
176
- function stable(items) {
177
- return items.sort((a, b) => `${a.path ?? ''}:${a.line ?? 0}:${a.column ?? 0}:${a.ruleId}`.localeCompare(`${b.path ?? ''}:${b.line ?? 0}:${b.column ?? 0}:${b.ruleId}`));
178
- }
179
- const ownerPublicApiOf = (owners, missingEntries) => {
180
- if (!owners.length)
181
- return { status: 'unavailable', reason: 'no slot owner instance with an entry file exists in the repository' };
182
- if (missingEntries.length)
183
- return { status: 'unavailable', reason: 'one or more declared owner entries are outside the checked production TypeScript or JavaScript program',
184
- missingEntries: missingEntries.map(owner => owner.entry).sort(byCodeUnit) };
185
- return { status: 'checked', declarations: owners.length };
186
- };
187
- const grammarContractOf = (config) => {
188
- if (!config.kinds.includes('frontend'))
189
- return { status: 'not-applicable' };
190
- if (config.frontend.grammar)
191
- return { status: 'checked', package: config.frontend.grammar.package };
192
- return { status: 'unavailable', reason: 'no app has a src/app/globals.css to judge against the Grammar style entry' };
193
- };
194
- function invalidConfigurationResult(repositoryRoot, error) {
195
- const hfs = repositoryRoot === undefined ? { violations: [], coverage: { status: 'unavailable', reason: 'repository root is unavailable' } } : checkHfsWithoutConfig(repositoryRoot);
196
- return { schema: 'starci/architecture-check@1', ok: false, repository: String(repositoryRoot ?? ''), kinds: [], files: 0,
197
- compiler: null, violations: stable(hfs.violations), coverage: { hfs: hfs.coverage },
198
- errors: [{ ruleId: /^(HFS_[A-Z_]+):/.exec(String(error.message))?.[1] ?? 'ARCH_CONFIG_INVALID', message: String(error.message ?? error).replace(/^HFS_[A-Z_]+:\s*/, '') }], limitations: LIMITATIONS };
199
- }
200
- function compilerFailureResult(config, hfs, error) {
201
- const message = String(error.message ?? error);
202
- const match = /^(ARCH_[A-Z_]+):\s*/.exec(message);
203
- return { schema: 'starci/architecture-check@1', ok: false, repository: config.root, kinds: config.kinds, files: 0,
204
- compiler: null, violations: hfs.violations, coverage: { hfs: hfs.coverage },
205
- errors: [{ ruleId: match?.[1] ?? 'ARCH_COMPILER_FAILURE', message: message.replace(/^(ARCH_[A-Z_]+):\s*/, '') }], limitations: LIMITATIONS };
206
- }
207
- function runBackendChecks(config, context, paths, injectedTypeScript, violations) {
208
- violations.push(...checkBackend(config, context));
209
- // A slice may omit every app root. Registration ownership needs the complete
210
- // composition graph even when the caller asks for findings in only one path.
211
- const registrationContext = paths.length && config.backend.moduleRegistration
212
- ? buildTypeScriptContext(config, injectedTypeScript) : context;
213
- const registration = checkModuleRegistration(config, registrationContext);
214
- violations.push(...registration.violations);
215
- const sourceShape = checkBackendSourceShape(config, context);
216
- violations.push(...sourceShape.violations);
217
- const contracts = checkBackendContracts(config, context);
218
- violations.push(...contracts.violations);
219
- return { moduleRegistration: registration.coverage, backendSourceShape: sourceShape.coverage, backendContractTypeForm: contracts.coverage };
220
- }
221
- function runFrontendChecks(config, context, violations) {
222
- let frontendChecked = true;
223
- try {
224
- violations.push(...checkFrontend(config, context));
225
- }
226
- catch (error) {
227
- const message = String(error.message ?? error);
228
- const match = /^(ARCH_[A-Z_]+):\s*/.exec(message);
229
- if (!match)
230
- throw error;
231
- context.errors.push({ ruleId: match[1] ?? '', message: message.slice(match[0].length) });
232
- frontendChecked = false;
233
- }
234
- const dataLifecycle = checkFrontendDataLifecycle(config, context);
235
- violations.push(...dataLifecycle.violations);
236
- return { frontendChecked, frontendDataLifecycle: dataLifecycle.coverage };
237
- }
238
- function runHfsMachine(config, context, paths, injectedTypeScript, base, fast, violations) {
239
- // HFS machine: the slot-driven graph checks read the whole program, also when the caller asked for one path.
240
- const hfsContext = paths.length ? buildTypeScriptContext(config, injectedTypeScript) : context;
241
- const hfsChecks = { tiers: null, reachability: null, deadExports: null, requiredFiles: null, clones: null, symbols: null, docLanguage: null };
242
- if (!hfsContext.program)
243
- return hfsChecks;
244
- const graph = buildHfsGraph(config, hfsContext);
245
- const input = { config, context: hfsContext, graph, base };
246
- const runs = { tiers: () => checkTiers(graph, hfsContext.ts), reachability: () => checkReachability(input), deadExports: () => checkDeadExports(input),
247
- requiredFiles: () => checkRequiredFiles(input), clones: () => checkClones(input), symbols: () => checkSymbols(input), docLanguage: () => checkDocLanguage(input) };
248
- if (graph.profile === 'be')
249
- for (const [name, [check]] of Object.entries(BACKEND_MACHINE))
250
- runs[name] = () => check(input);
251
- if (graph.profile === 'fe')
252
- for (const [name, [check]] of Object.entries(FRONTEND_MACHINE))
253
- runs[name] = () => check(input);
254
- if (fast) {
255
- delete runs.deadExports;
256
- delete runs.clones;
257
- delete runs.symbols;
258
- }
259
- for (const [name, run] of Object.entries(runs)) {
260
- const result = run();
261
- violations.push(...result.violations.map(violation => ({ ...violation, check: name })));
262
- hfsChecks[name] = result.coverage;
263
- }
264
- return hfsChecks;
265
- }
266
- function hfsRuleIds(hfs) {
267
- return hfs.coverage.status === 'checked' ? HFS_RULE_IDS : [];
268
- }
269
- function hfsCheckRuleIds(hfsChecks) {
270
- return [
271
- ...(hfsChecks.tiers ? TIER_RULE_IDS : []),
272
- ...(hfsChecks.reachability?.status === 'checked' ? REACHABILITY_RULE_IDS : []),
273
- ...(hfsChecks.deadExports?.status === 'checked' ? DEAD_EXPORT_RULE_IDS : []),
274
- ...(hfsChecks.requiredFiles?.status === 'checked' ? REQUIRED_FILE_RULE_IDS : []),
275
- ...(hfsChecks.clones?.status === 'checked' ? CLONE_RULE_IDS : []),
276
- ...(hfsChecks.symbols?.status === 'checked' ? SYMBOL_RULE_IDS : []),
277
- ...(hfsChecks.docLanguage?.status === 'checked' ? DOC_LANGUAGE_RULE_IDS : []),
278
- ];
279
- }
280
- function derivedCoverageRuleIds(coverage) {
281
- return [
282
- ...(coverage.ownerPublicApi.status === 'checked' ? OWNER_RULE_IDS : []),
283
- ...(coverage.grammarContract.status === 'checked' ? GRAMMAR_RULE_IDS : []),
284
- ...(coverage.moduleRegistration.status === 'checked' ? REGISTRATION_RULE_IDS : []),
285
- ...(coverage.backendSourceShape.layout?.status === 'checked' ? [SOURCE_LAYOUT_RULE_ID] : []),
286
- ...(coverage.backendSourceShape.naming?.status === 'checked' ? [SOURCE_NAME_RULE_ID] : []),
287
- ...(coverage.backendContractTypeForm.publicContracts?.status === 'checked' ? [PUBLIC_CONTRACT_RULE_ID] : []),
288
- ...(coverage.backendContractTypeForm.readonlyBoundaries?.status === 'checked' ? [READONLY_BOUNDARY_RULE_ID] : []),
289
- ];
290
- }
291
- function checkedRuleIdsFor(config, hfs, hfsChecks, frontendChecked, coverage) {
292
- const machineRuleIds = Object.entries({ ...BACKEND_MACHINE, ...FRONTEND_MACHINE })
293
- .flatMap(([name, [, ids]]) => (hfsChecks[name]?.status === 'checked' ? ids : []));
294
- const checked = [...new Set([
295
- ...COMMON_RULE_IDS,
296
- ...hfsRuleIds(hfs),
297
- ...(config.kinds.includes('backend') ? BACKEND_RULE_IDS : []),
298
- ...hfsCheckRuleIds(hfsChecks),
299
- ...CONFIG_UNREAD_RULE_IDS,
300
- ...machineRuleIds,
301
- ...(frontendChecked ? FRONTEND_RULE_IDS : []),
302
- ...derivedCoverageRuleIds(coverage),
303
- ...(config.kinds.includes('frontend') && ['checked', 'not-applicable'].includes(coverage.frontendDataLifecycle.status) ? SWR_DATA_RULE_IDS : []),
304
- ])];
305
- return checked.filter(id => !(id.startsWith('FE_') && !config.kinds.includes('frontend')) && !(id.startsWith('BE_') && !config.kinds.includes('backend')))
306
- .sort(byCodeUnit);
307
- }
308
- /** The errors and the violations a surface reports: findings under the requested paths, on the requested surface, in stable order. */
309
- function scopeFindings({ config, context, violations, paths, surface }) {
310
- const inScope = (item) => {
311
- const itemPath = item.path;
312
- return !paths.length || Boolean(itemPath && paths.some(prefix => sameOrUnder(itemPath, prefix.replace(/\/$/, ''))));
313
- };
314
- // Two findings travel as context errors (package boundary edges); they are obligations of the lint surface like any other finding.
315
- const asViolation = (item) => LINT_CODES.has(item.ruleId);
316
- const allErrors = context.errors.filter(item => item.ruleId.startsWith('ARCH_TSCONFIG_') || !item.path || inScope(item));
317
- const obligations = surface === 'all' ? violations : [...violations, ...context.errors.filter(asViolation).filter(inScope)];
318
- // The lint surface is what an editor can show on a line of a TypeScript file; `starci app check` keeps every other finding of the machine.
319
- const onSurface = (item) => surface === 'all' || onLintSurface(config.root, item) === (surface === 'lint');
320
- const errors = stable(surface === 'all' ? allErrors : allErrors.filter(item => !asViolation(item)));
321
- const scopedViolations = stable(obligations.filter(inScope).filter(onSurface));
322
- return { errors, scopedViolations };
323
- }
324
- /**
325
- * Check a target repository. injectedTypeScript exists only for hermetic rule fixtures. `fast` leaves out the checks
326
- * that read the whole repository to answer (clones, dead exports, repository-wide symbols); the pre-push check of the changed owners uses it.
327
- */
328
- export function checkArchitecture(options = {}) {
329
- return withTypeScriptProgramRun(() => withTreeCache(() => checkArchitectureOnce(options)));
330
- }
331
- function checkArchitectureOnce({ repositoryRoot, injectedTypeScript, paths = [], base, fast = false, hfs: openedHfs, surface = 'all' }) {
332
- if (!['all', 'lint', 'check'].includes(surface))
333
- throw new Error(`unknown surface ${surface}`);
334
- let config;
335
- try {
336
- // an absent root reaches path.resolve, which throws and is reported as an invalid configuration
337
- config = loadArchitectureConfig(repositoryRoot, { hfs: openedHfs });
338
- }
339
- catch (error) {
340
- return invalidConfigurationResult(repositoryRoot, error);
341
- }
342
- const hfs = checkHfs(config);
343
- let context;
344
- try {
345
- context = buildTypeScriptContext(config, injectedTypeScript, paths);
346
- }
347
- catch (error) {
348
- return compilerFailureResult(config, hfs, error);
349
- }
350
- const violations = [...hfs.violations];
351
- const configUnread = checkConfigUnread({ context });
352
- violations.push(...configUnread.violations);
353
- let moduleRegistration = { status: 'not-applicable' };
354
- let backendSourceShape = { status: 'not-applicable' };
355
- let backendContractTypeForm = { publicContracts: { status: 'not-applicable' }, readonlyBoundaries: { status: 'not-applicable' } };
356
- let frontendDataLifecycle = { status: 'not-applicable' };
357
- if (context.program)
358
- violations.push(...checkOwners(config, context));
359
- if (context.program && config.kinds.includes('backend')) {
360
- const backend = runBackendChecks(config, context, paths, injectedTypeScript, violations);
361
- moduleRegistration = backend.moduleRegistration;
362
- backendSourceShape = backend.backendSourceShape;
363
- backendContractTypeForm = backend.backendContractTypeForm;
364
- }
365
- let frontendChecked = config.kinds.includes('frontend');
366
- if (context.program && config.kinds.includes('frontend')) {
367
- // A broken authored input (the framework-pinned root list in knowledge) is an error, never a
368
- // silently different contract: the frontend rules are then not reported as checked.
369
- const frontend = runFrontendChecks(config, context, violations);
370
- frontendChecked = frontend.frontendChecked;
371
- frontendDataLifecycle = frontend.frontendDataLifecycle;
372
- }
373
- const hfsChecks = runHfsMachine(config, context, paths, injectedTypeScript, base, fast, violations);
374
- const { errors, scopedViolations } = scopeFindings({ config, context, violations, paths, surface });
375
- const sourceFiles = new Set(context.files.map(file => canonical(file.fileName)));
376
- const missingOwnerEntries = config.owners?.filter(owner => !sourceFiles.has(canonical(path.resolve(config.root, ...owner.entry.split('/'))))) ?? [];
377
- const coverage = {
378
- sourceFiles: context.files.map(file => relativePath(config.root, canonical(file.fileName))).sort(byCodeUnit),
379
- hfs: hfs.coverage,
380
- configUnread: configUnread.coverage,
381
- backendContractTypeForm,
382
- backendSourceShape,
383
- frontendDataLifecycle,
384
- moduleRegistration,
385
- hfsMachine: hfsChecks,
386
- ownerPublicApi: ownerPublicApiOf(config.owners, missingOwnerEntries),
387
- grammarContract: grammarContractOf(config),
388
- };
389
- coverage.checkedRuleIds = checkedRuleIdsFor(config, hfs, hfsChecks, frontendChecked, coverage);
390
- return {
391
- schema: 'starci/architecture-check@1',
392
- ok: errors.length === 0 && scopedViolations.length === 0,
393
- repository: config.root,
394
- kinds: config.kinds,
395
- files: context.files.length,
396
- compiler: { version: context.loaded.version, resolved: context.loaded.resolved, projects: context.projects.map(item => item.relative) },
397
- coverage,
398
- violations: scopedViolations,
399
- errors,
400
- limitations: LIMITATIONS,
401
- };
402
- }
@@ -1,69 +0,0 @@
1
- import path from 'node:path';
2
- import { machineKit } from './machine-ast.mjs';
3
- import { constructorDependencies, serviceClasses } from './constructor-deps.mjs';
4
- const hasInjector = (dependency) => 'decoratorDeclaration' in dependency && 'injectorCall' in dependency
5
- && Boolean(dependency.decoratorDeclaration) && Boolean(dependency.injectorCall);
6
- /**
7
- * R85 `injection-token-exported` (BE_RAW_INJECT), the injection law's last obligation: a spec can only provide a token it
8
- * can import. Every `Inject<Thing>()` decorator that a service constructor uses resolves to a token (the argument of its
9
- * `injector<T>(TOKEN)`), and that token must be EXPORTED, by name, from the file of the decorator (`<cap>.decorators.ts`),
10
- * from the `<cap>.decorators.ts` that declares it, or from the index.ts of the capability that owns either file. A token
11
- * that is a private (non-exported) const, or one only a sibling file of the capability can reach, cannot be provided by a
12
- * unit spec and is a finding. A token that a package declares (a Nest options token, say) is the package's export.
13
- * The finding sits on the decorator's `injector(...)` call, once per decorator, however many services use it.
14
- */
15
- export const INJECTION_TOKEN_EXPORTED_RULE_IDS = ['BE_RAW_INJECT'];
16
- const RULE = 'BE_RAW_INJECT';
17
- const exportedVariableHasName = (ts, kit, statement, name) => {
18
- // The modifier flags are read off the statement itself; the kit types its argument as a declaration.
19
- if (!ts.isVariableStatement(statement) || !kit.isExported(statement))
20
- return false;
21
- return statement.declarationList.declarations.some(declaration => (ts.isIdentifier(declaration.name) && declaration.name.text === name)
22
- || (ts.isObjectBindingPattern(declaration.name) && declaration.name.elements.some(element => ts.isIdentifier(element.name) && element.name.text === name)));
23
- };
24
- const exportedDeclarationHasName = (ts, statement, name) => {
25
- if (!ts.isExportDeclaration(statement))
26
- return false;
27
- const clause = statement.exportClause;
28
- return clause !== undefined && ts.isNamedExports(clause) && clause.elements.some(element => element.name.text === name);
29
- };
30
- const exportsName = (ts, kit, file, name) => file?.sourceFile.statements.some(statement => exportedVariableHasName(ts, kit, statement, name) || exportedDeclarationHasName(ts, statement, name)) === true;
31
- const indexOf = (graph, file) => (file?.owner ? graph.files.get(`${file.owner.root}/index.ts`) : null);
32
- /** The graph file declaring `declaration`, when the program holds it. */
33
- const graphFileOf = (graph, kit, declaration) => {
34
- const rel = kit.graphPath(declaration);
35
- return rel === null ? undefined : graph.files.get(rel);
36
- };
37
- const injectionViolationFor = (graph, kit, ts, dependency) => {
38
- const decoratorFile = graphFileOf(graph, kit, dependency.decoratorDeclaration);
39
- if (dependency.kind === 'unresolved') {
40
- return decoratorFile ? { ruleId: RULE, path: decoratorFile.rel, ...kit.at(decoratorFile.rel, decoratorFile.sourceFile, dependency.injectorCall), decorator: dependency.decorator,
41
- message: `${dependency.decorator}() cannot be followed to its token (${dependency.reason}); name an exported \`unique symbol\` const so a unit spec can provide it.` } : null;
42
- }
43
- const tokenFile = dependency.declaration ? graphFileOf(graph, kit, dependency.declaration) : null;
44
- const homes = [decoratorFile, tokenFile && path.posix.basename(tokenFile.rel).endsWith('.decorators.ts') ? tokenFile : null, indexOf(graph, decoratorFile), indexOf(graph, tokenFile)];
45
- if (!decoratorFile || homes.some(home => exportsName(ts, kit, home, dependency.name)))
46
- return null;
47
- return { ruleId: RULE, path: decoratorFile.rel, ...kit.at(decoratorFile.rel, decoratorFile.sourceFile, dependency.injectorCall), decorator: dependency.decorator, token: dependency.name,
48
- message: `${dependency.decorator}() injects ${dependency.name}, which is not exported from ${path.posix.basename(decoratorFile.rel)} nor from the capability index.ts; export the token so a unit spec can provide it (\`{ provide: ${dependency.name}, useValue: double }\`).` };
49
- };
50
- export function checkInjectionTokenExported(input) {
51
- const { graph } = input;
52
- const kit = machineKit(input);
53
- const { ts } = kit;
54
- const violations = [];
55
- const seen = new Set();
56
- let decorators = 0;
57
- for (const { file, declaration } of serviceClasses(kit, graph)) {
58
- for (const dependency of constructorDependencies(kit, file, declaration)) {
59
- if (!hasInjector(dependency) || (dependency.kind === 'token' && dependency.external) || seen.has(dependency.injectorCall))
60
- continue;
61
- seen.add(dependency.injectorCall);
62
- decorators += 1;
63
- const violation = injectionViolationFor(graph, kit, ts, dependency);
64
- if (violation)
65
- violations.push(violation);
66
- }
67
- }
68
- return { violations, coverage: { status: 'checked', decorators, files: graph.files.size } };
69
- }