@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,320 +0,0 @@
1
- import { relativePath, UNPROVEN_FRAMEWORK, unwrapExpression } from './typescript.mjs';
2
- import { constructedDecoratorKind, mutableDecoratorKind, nodeDecorators, tracedFrameworkKinds, violation } from './ast-walks.mjs';
3
- import { byCodeUnit } from '../../lib/list.mjs';
4
- function locateSource(h, config, context, sourceFile, roots, state) {
5
- const { featureRoots, moduleRoots, localFiles } = roots;
6
- const { canonical, frameworkTargets, locatedRoot, sourceRole, exportedDeclarations, SPECIAL_BASENAMES } = h;
7
- const fileName = canonical(sourceFile.fileName);
8
- const featureRoot = locatedRoot(featureRoots, fileName);
9
- const moduleRoot = locatedRoot(moduleRoots, fileName);
10
- const ownerRoot = featureRoot ?? moduleRoot;
11
- if (!ownerRoot)
12
- return null;
13
- state.checkedFiles += 1;
14
- const checker = context.checkerFor(fileName);
15
- if (!checker)
16
- return null;
17
- if (!state.frameworkByChecker.has(checker))
18
- state.frameworkByChecker.set(checker, frameworkTargets(config, context, checker, localFiles));
19
- const framework = state.frameworkByChecker.get(checker) ?? frameworkTargets(config, context, checker, localFiles);
20
- const relativeToOwner = relativePath(ownerRoot, fileName);
21
- const parts = relativeToOwner.split('/');
22
- const directories = parts.slice(0, -1).map(part => part.toLowerCase());
23
- const applicationIndex = directories.indexOf('application');
24
- const transportIndex = directories.indexOf('transport');
25
- const inApplication = applicationIndex >= 0;
26
- const inTransport = transportIndex >= 0;
27
- const role = sourceRole(context.ts, sourceFile);
28
- const relative = relativePath(config.root, fileName);
29
- const migrationName = /^\d{10,}-[A-Z][A-Za-z0-9]*$/.test(role.base);
30
- const persistencePath = !role.spec && (migrationName || directories.includes('migrations'));
31
- const special = SPECIAL_BASENAMES.has(role.base.toLowerCase()) || migrationName
32
- || ['constants', 'enums', 'errors', 'migrations'].some(folder => directories.includes(folder));
33
- const publicDeclarations = exportedDeclarations(context.ts, checker, sourceFile);
34
- return { config, context, sourceFile, fileName, featureRoot, moduleRoot, checker, framework, directories, transportIndex,
35
- inApplication, inTransport, role, relative, migrationName, persistencePath, special, publicDeclarations };
36
- }
37
- function reportSourceName(h, info, state) {
38
- const { kebabSourceBase, SOURCE_NAME_RULE_ID } = h;
39
- const { config, sourceFile, migrationName, role, relative } = info;
40
- if (!migrationName && !kebabSourceBase(role.base))
41
- state.violations.push(violation(config, sourceFile, sourceFile, SOURCE_NAME_RULE_ID, `Source basename ${role.base} must use kebab-case segments plus an explicit role suffix.`));
42
- if (!role.role && !info.special)
43
- state.namingReasons.push(`${relative} has no statically identifiable source role`);
44
- }
45
- function reportFeatureRoleConflicts(h, info, state) {
46
- const { SOURCE_LAYOUT_RULE_ID, APPLICATION_ROLES, TRANSPORT_ROLES } = h;
47
- const { config, sourceFile, role, directories, inApplication, inTransport, transportIndex } = info;
48
- const { violations } = state;
49
- if (inApplication && inTransport)
50
- violations.push(violation(config, sourceFile, sourceFile, SOURCE_LAYOUT_RULE_ID, 'A feature source cannot belong to both application and transport layers.'));
51
- if (role.role && APPLICATION_ROLES.has(role.role) && !inApplication)
52
- violations.push(violation(config, sourceFile, sourceFile, SOURCE_LAYOUT_RULE_ID, `${role.role} source belongs under the feature application/ layer.`));
53
- if (role.role && TRANSPORT_ROLES.has(role.role) && !inTransport)
54
- violations.push(violation(config, sourceFile, sourceFile, SOURCE_LAYOUT_RULE_ID, `${role.role} source belongs under the feature transport/<protocol>/ layer.`));
55
- if (inApplication && role.role && TRANSPORT_ROLES.has(role.role))
56
- violations.push(violation(config, sourceFile, sourceFile, SOURCE_LAYOUT_RULE_ID, `Transport role ${role.role} cannot live in application/.`));
57
- if (inTransport && role.role && APPLICATION_ROLES.has(role.role))
58
- violations.push(violation(config, sourceFile, sourceFile, SOURCE_LAYOUT_RULE_ID, `Application role ${role.role} cannot live in transport/.`));
59
- if (inTransport && transportIndex >= directories.length - 1)
60
- violations.push(violation(config, sourceFile, sourceFile, SOURCE_LAYOUT_RULE_ID, 'Feature transport source must name a protocol below transport/.'));
61
- }
62
- /** A non-index source whose role is neither one of the layer's own roles nor one the other layer or the schema owns. */
63
- function unselectedLayerRole(role, layerRoles, otherRoles) {
64
- return role.base !== 'index' && (!role.role || !layerRoles.has(role.role)) && !(role.role && (otherRoles.has(role.role) || role.role === 'entity'));
65
- }
66
- function reportFeatureRoleSelection(h, info, state) {
67
- const { APPLICATION_ROLES, TRANSPORT_ROLES, APPLICATION_LAYER_ROLES, TRANSPORT_LAYER_ROLES } = h;
68
- const { role, relative, directories, inApplication, inTransport, persistencePath } = info;
69
- const topLevelFeatureFile = directories.length === 1 && (role.base === 'index' || role.role === 'module' || role.spec);
70
- if (inApplication && unselectedLayerRole(role, APPLICATION_LAYER_ROLES, TRANSPORT_ROLES)) {
71
- state.layoutReasons.push(`${relative} role ${role.role ?? '(unclassified)'} is not a selected application-layer role`);
72
- }
73
- if (inTransport && unselectedLayerRole(role, TRANSPORT_LAYER_ROLES, APPLICATION_ROLES)) {
74
- state.layoutReasons.push(`${relative} role ${role.role ?? '(unclassified)'} is not a selected transport-layer role`);
75
- }
76
- if (inApplication || inTransport || topLevelFeatureFile)
77
- return;
78
- if (role.role && role.role !== 'entity' && !APPLICATION_ROLES.has(role.role) && !TRANSPORT_ROLES.has(role.role)) {
79
- state.layoutReasons.push(`${relative} role ${role.role} has no statically selected feature layer`);
80
- }
81
- if (!role.role && !persistencePath)
82
- state.layoutReasons.push(`${relative} has no statically selected feature layer`);
83
- }
84
- function reportFeatureSchemaPlacement(h, info, state) {
85
- const { SOURCE_LAYOUT_RULE_ID } = h;
86
- const { config, sourceFile, role, persistencePath } = info;
87
- if (persistencePath)
88
- state.violations.push(violation(config, sourceFile, sourceFile, SOURCE_LAYOUT_RULE_ID, 'Migration source cannot be owned by a feature; place it under the declared persistence module.'));
89
- if (role.role === 'entity')
90
- state.violations.push(violation(config, sourceFile, sourceFile, SOURCE_LAYOUT_RULE_ID, 'Entity source cannot be owned by a feature; place schema under the declared persistence module.'));
91
- }
92
- function reportFeatureLayout(h, info, state) {
93
- if (!info.featureRoot)
94
- return;
95
- reportFeatureRoleConflicts(h, info, state);
96
- reportFeatureRoleSelection(h, info, state);
97
- reportFeatureSchemaPlacement(h, info, state);
98
- }
99
- function inspectClassPlacement(h, info, declaration, kinds, state) {
100
- const { implementsFramework, SOURCE_LAYOUT_RULE_ID } = h;
101
- const { config, context, sourceFile, featureRoot, inTransport, directories, transportIndex, checker, framework } = info;
102
- const { ts } = context;
103
- const graphQlDto = kinds.some(kind => kind === 'ArgsType' || kind === 'InputType' || kind === 'ObjectType');
104
- if (graphQlDto && (!featureRoot || !inTransport || directories[transportIndex + 1] !== 'graphql')) {
105
- state.violations.push(violation(config, sourceFile, declaration.name ?? declaration, SOURCE_LAYOUT_RULE_ID, 'GraphQL DTO classes belong under a feature transport/graphql/ boundary.'));
106
- }
107
- const persistenceSchema = kinds.includes('Entity') || kinds.includes('ViewEntity')
108
- || implementsFramework(ts, checker, declaration, framework.bySymbol, 'MigrationInterface');
109
- if (persistenceSchema && featureRoot)
110
- state.violations.push(violation(config, sourceFile, declaration.name ?? declaration, SOURCE_LAYOUT_RULE_ID, 'TypeORM entities and migrations cannot be owned by a feature; place schema under its declared persistence module.'));
111
- }
112
- function inspectClassName(h, info, declaration, state) {
113
- const { implementedPortNames, SOURCE_NAME_RULE_ID, CLASS_ROLE_SUFFIX, NON_CLASS_ROLES } = h;
114
- const { config, sourceFile, role, relative, checker } = info;
115
- const { ts } = info.context;
116
- const { publicDeclarations } = info;
117
- const classSuffix = role.role && !NON_CLASS_ROLES.has(role.role) ? CLASS_ROLE_SUFFIX.get(role.role) : null;
118
- const nameNode = declaration.name;
119
- if (publicDeclarations.has(declaration) && !nameNode)
120
- state.namingReasons.push(`${relative} exports an anonymous class whose role name cannot be proved`);
121
- else if (publicDeclarations.has(declaration) && nameNode && classSuffix && !nameNode.text.endsWith(classSuffix)
122
- && !implementedPortNames(ts, checker, declaration).some(port => nameNode.text.endsWith(port))) {
123
- state.violations.push(violation(config, sourceFile, nameNode, SOURCE_NAME_RULE_ID, `Exported class ${nameNode.text} must end in ${classSuffix} for a ${role.role} source file, or in the name of the port it implements.`));
124
- }
125
- else if (publicDeclarations.has(declaration) && nameNode && role.role && !NON_CLASS_ROLES.has(role.role) && !classSuffix) {
126
- state.namingReasons.push(`${relative} declares exported class ${nameNode.text} with unclassified file role ${role.role}`);
127
- }
128
- }
129
- function inspectClass(h, info, declaration, state) {
130
- const { decoratorKind } = h;
131
- const { ts } = info.context;
132
- const { checker, framework } = info;
133
- const declarationDecorators = nodeDecorators(ts, declaration);
134
- const kinds = declarationDecorators.map(decorator => decoratorKind(ts, checker, decorator, framework.bySymbol)).filter((kind) => Boolean(kind));
135
- inspectClassPlacement(h, info, declaration, kinds, state);
136
- inspectClassName(h, info, declaration, state);
137
- }
138
- function inspectClasses(h, info, state) {
139
- const declarations = info.sourceFile.statements.filter((statement) => info.context.ts.isClassDeclaration(statement));
140
- for (const declaration of declarations)
141
- inspectClass(h, info, declaration, state);
142
- }
143
- function inspectClassValue(h, info, declaration, state) {
144
- const { classValueStatus, SOURCE_NAME_RULE_ID, CLASS_ROLE_SUFFIX, NON_CLASS_ROLES } = h;
145
- const { config, sourceFile, relative, role, checker, publicDeclarations } = info;
146
- const { ts } = info.context;
147
- if (!publicDeclarations.has(declaration) || !declaration.initializer)
148
- return;
149
- const classValue = classValueStatus(ts, checker, declaration.initializer);
150
- if (classValue.status === 'unavailable') {
151
- state.namingReasons.push(`${relative} exports a class-valued declaration whose role identity is not statically proved`);
152
- return;
153
- }
154
- if (classValue.status !== 'class')
155
- return;
156
- const classSuffix = role.role && !NON_CLASS_ROLES.has(role.role) ? CLASS_ROLE_SUFFIX.get(role.role) : null;
157
- if (!classSuffix || !ts.isIdentifier(declaration.name)) {
158
- state.namingReasons.push(`${relative} exports a class-valued declaration without a statically selected class role`);
159
- return;
160
- }
161
- const names = [declaration.name.text, ...classValue.names];
162
- const invalid = names.find(name => !name.endsWith(classSuffix));
163
- if (invalid)
164
- state.violations.push(violation(config, sourceFile, declaration.name, SOURCE_NAME_RULE_ID, `Exported class value ${invalid} must end in ${classSuffix} for a ${role.role} source file.`));
165
- }
166
- function inspectClassValues(h, info, state) {
167
- const { ts } = info.context;
168
- const { sourceFile } = info;
169
- for (const statement of sourceFile.statements)
170
- if (ts.isVariableStatement(statement)) {
171
- for (const declaration of statement.declarationList.declarations)
172
- inspectClassValue(h, info, declaration, state);
173
- }
174
- }
175
- function inspectEnumMembers(h, info, statement, state) {
176
- const { SOURCE_NAME_RULE_ID } = h;
177
- const { config, sourceFile } = info;
178
- const { ts } = info.context;
179
- for (const member of statement.members) {
180
- const name = ts.isIdentifier(member.name) || ts.isStringLiteralLike(member.name) ? member.name.text : null;
181
- const initializer = member.initializer && unwrapExpression(ts, member.initializer);
182
- if (!name || !/^[A-Z][A-Za-z0-9]*$/.test(name) || !initializer || !ts.isStringLiteralLike(initializer)) {
183
- state.violations.push(violation(config, sourceFile, member.name, SOURCE_NAME_RULE_ID, 'Enum members must use PascalCase names with explicit static string values.'));
184
- }
185
- }
186
- }
187
- function inspectObjectContract(h, info, statement, state) {
188
- const { objectContractStatus, companionInterfaceAllowed, SOURCE_NAME_RULE_ID, TRANSPORT_OBJECT_SUFFIX } = h;
189
- const { config, sourceFile, role, checker, publicDeclarations } = info;
190
- const { ts } = info.context;
191
- // an object contract is an interface or an object type alias, so any other statement has no contract name to judge
192
- if (!ts.isInterfaceDeclaration(statement) && !ts.isTypeAliasDeclaration(statement))
193
- return;
194
- const contractStatus = objectContractStatus(ts, checker, statement);
195
- const transportSuffix = role.role === null ? undefined : TRANSPORT_OBJECT_SUFFIX.get(role.role);
196
- if (contractStatus === 'object' && publicDeclarations.has(statement) && transportSuffix && !role.spec
197
- && !statement.name.text.endsWith(transportSuffix) && !companionInterfaceAllowed(ts, sourceFile, statement.name.text)) {
198
- state.violations.push(violation(config, sourceFile, statement.name, SOURCE_NAME_RULE_ID, `Public object contract ${statement.name.text} in a ${role.role} source file must end in ${transportSuffix}.`));
199
- }
200
- }
201
- function inspectEnumAndContract(h, info, statement, state) {
202
- const { hasModifier, SOURCE_NAME_RULE_ID } = h;
203
- const { config, sourceFile } = info;
204
- const { ts } = info.context;
205
- if (ts.isEnumDeclaration(statement)) {
206
- if (hasModifier(ts, statement, ts.SyntaxKind.ConstKeyword) || !/^[A-Z][A-Za-z0-9]*$/.test(statement.name.text)) {
207
- state.violations.push(violation(config, sourceFile, statement.name, SOURCE_NAME_RULE_ID, 'Enums must be non-const declarations with PascalCase names.'));
208
- }
209
- inspectEnumMembers(h, info, statement, state);
210
- }
211
- inspectObjectContract(h, info, statement, state);
212
- }
213
- function inspectEnumsAndContracts(h, info, state) {
214
- for (const statement of info.sourceFile.statements)
215
- inspectEnumAndContract(h, info, statement, state);
216
- }
217
- function inspectDynamicDecorator(info, dynamic, state) {
218
- const detail = `${info.relative} uses a mutable or constructed ${dynamic} decorator identity`;
219
- if (['Entity', 'ViewEntity', 'ArgsType', 'InputType', 'ObjectType', 'multiple framework', 'unproven framework'].includes(dynamic))
220
- state.layoutReasons.push(detail);
221
- if (!['Entity', 'ViewEntity'].includes(dynamic))
222
- state.namingReasons.push(detail);
223
- }
224
- function inspectDecorator(h, info, node, decorator, state) {
225
- const { graphqlField, graphqlArgument, decoratorKind, TRACE_NEW } = h;
226
- const { ts } = info.context;
227
- const { checker, framework } = info;
228
- const kind = decoratorKind(ts, checker, decorator, framework.bySymbol);
229
- if (!kind) {
230
- const dynamic = mutableDecoratorKind(ts, checker, decorator, framework.bySymbol)
231
- ?? constructedDecoratorKind(ts, checker, decorator, framework.bySymbol, TRACE_NEW);
232
- if (dynamic)
233
- inspectDynamicDecorator(info, dynamic, state);
234
- }
235
- if (kind === 'Mutation' || kind === 'Query')
236
- graphqlField({ config: info.config, context: info.context, sourceFile: info.sourceFile,
237
- node, decorator, kind, namingReasons: state.namingReasons, violations: state.violations });
238
- if (kind === 'Args')
239
- graphqlArgument(info.config, info.context, info.sourceFile, node, decorator, state.namingReasons, state.violations);
240
- }
241
- function inspectNodeDecorators(h, info, node, state) {
242
- for (const decorator of nodeDecorators(info.context.ts, node))
243
- inspectDecorator(h, info, node, decorator, state);
244
- }
245
- function inspectEnumCalls(h, info, node, state) {
246
- const { graphqlEnumRegistration, selectedCallKind, callsNamedHelper } = h;
247
- const { ts } = info.context;
248
- const { checker, framework } = info;
249
- if (!ts.isCallExpression(node))
250
- return;
251
- if (selectedCallKind(ts, checker, node, framework.bySymbol) === 'registerEnumType') {
252
- graphqlEnumRegistration(info.config, info.context, info.sourceFile, node, state.namingReasons, state.violations);
253
- }
254
- else if (callsNamedHelper(ts, checker, node, 'createEnumType')) {
255
- state.namingReasons.push(`${info.relative} calls a project GraphQL enum adapter whose emitted type name is not statically proved`);
256
- }
257
- }
258
- function inspectConstructedSource(h, info, node, state) {
259
- const { SOURCE_LAYOUT_RULE_ID, TRACE_NEW } = h;
260
- const { ts } = info.context;
261
- const { checker, framework, publicDeclarations, featureRoot } = info;
262
- const exportedFactoryCall = ts.isCallExpression(node) && ts.isVariableDeclaration(node.parent) && publicDeclarations.has(node.parent);
263
- if ((ts.isNewExpression(node) || exportedFactoryCall) && featureRoot) {
264
- const constructed = tracedFrameworkKinds(ts, checker, node, framework.bySymbol, TRACE_NEW);
265
- if (constructed.has('EntitySchema'))
266
- state.violations.push(violation(info.config, info.sourceFile, node.expression, SOURCE_LAYOUT_RULE_ID, 'TypeORM EntitySchema cannot be owned by a feature; place schema under its declared persistence module.'));
267
- if (constructed.has(UNPROVEN_FRAMEWORK))
268
- state.layoutReasons.push(`${info.relative} has a constructed provider identity beyond the bounded static trace`);
269
- }
270
- }
271
- function visitSourceNode(h, info, node, state) {
272
- inspectNodeDecorators(h, info, node, state);
273
- inspectEnumCalls(h, info, node, state);
274
- inspectConstructedSource(h, info, node, state);
275
- info.context.ts.forEachChild(node, child => visitSourceNode(h, info, child, state));
276
- }
277
- function inspectSourceFile(h, config, context, sourceFile, roots, state) {
278
- const info = locateSource(h, config, context, sourceFile, roots, state);
279
- if (!info)
280
- return;
281
- reportSourceName(h, info, state);
282
- reportFeatureLayout(h, info, state);
283
- inspectClasses(h, info, state);
284
- inspectClassValues(h, info, state);
285
- inspectEnumsAndContracts(h, info, state);
286
- visitSourceNode(h, info, sourceFile, state);
287
- }
288
- function coverageFor(state) {
289
- for (const framework of state.frameworkByChecker.values()) {
290
- state.layoutReasons.push(...framework.reasons);
291
- state.namingReasons.push(...framework.reasons.filter(reason => reason.includes('@nestjs/graphql')));
292
- }
293
- if (state.checkedFiles === 0) {
294
- state.layoutReasons.push('the checked TypeScript program contains no configured backend feature or module source');
295
- state.namingReasons.push('the checked TypeScript program contains no configured backend feature or module source');
296
- }
297
- return {
298
- files: state.checkedFiles,
299
- layout: state.layoutReasons.length
300
- ? { status: 'unavailable', reason: 'one or more backend source placement relations are not statically proved', details: [...new Set(state.layoutReasons)].sort(byCodeUnit) }
301
- : { status: 'checked' },
302
- naming: state.namingReasons.length
303
- ? { status: 'unavailable', reason: 'one or more backend source naming relations are not statically proved', details: [...new Set(state.namingReasons)].sort(byCodeUnit) }
304
- : { status: 'checked' },
305
- };
306
- }
307
- /** Check the adopted domain-first backend source layout without inferring semantic ownership from folder names alone. */
308
- export function createBackendSourceShapeChecker(helpers) {
309
- const { absoluteRoots, canonical } = helpers;
310
- return function checkBackendSourceShape(config, context) {
311
- const featureRoots = absoluteRoots(config.root, config.backend.features);
312
- const moduleRoots = absoluteRoots(config.root, config.backend.modules);
313
- const localFiles = new Set(context.files.map(file => canonical(file.fileName)));
314
- const state = { frameworkByChecker: new Map(), violations: [], layoutReasons: [], namingReasons: [], checkedFiles: 0 };
315
- const roots = { featureRoots, moduleRoots, localFiles };
316
- for (const sourceFile of context.files)
317
- inspectSourceFile(helpers, config, context, sourceFile, roots, state);
318
- return { violations: state.violations, coverage: coverageFor(state) };
319
- };
320
- }