@starci/eslint-canon-be 3.8.20 → 3.9.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 (164) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/package.json +1 -1
  3. package/runtime/bundle.json +192 -0
  4. package/runtime/engine/by-code-unit.mjs +6 -6
  5. package/runtime/engine/model-config.mjs +98 -76
  6. package/runtime/engine/orca-config.mjs +22 -17
  7. package/runtime/engine/release-config.mjs +22 -18
  8. package/runtime/engine/removed-vocabulary.mjs +21 -20
  9. package/runtime/engine/resources-config.mjs +42 -35
  10. package/runtime/engine/runtime-root.mjs +11 -13
  11. package/runtime/engine/secrets.mjs +170 -102
  12. package/runtime/engine/sonar-config.mjs +16 -13
  13. package/runtime/engine/temp-root.mjs +3 -9
  14. package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
  15. package/runtime/knowledge/hfs/rules.yaml +6 -6
  16. package/runtime/knowledge/hfs/slots.yaml +2 -2
  17. package/runtime/knowledge/sonar-gate.yaml +1 -1
  18. package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
  19. package/runtime/scripts/api/git/cat-file.mjs +0 -1
  20. package/runtime/scripts/api/git/config-get.mjs +1 -2
  21. package/runtime/scripts/api/git/diff.mjs +0 -1
  22. package/runtime/scripts/api/git/lib.mjs +32 -32
  23. package/runtime/scripts/api/git/ls-files.mjs +0 -1
  24. package/runtime/scripts/api/git/ls-tree.mjs +0 -1
  25. package/runtime/scripts/api/git/merge-base.mjs +2 -3
  26. package/runtime/scripts/api/git/remote.mjs +0 -1
  27. package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
  28. package/runtime/scripts/api/git/show.mjs +0 -1
  29. package/runtime/scripts/hfs/allows.mjs +37 -38
  30. package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
  31. package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
  32. package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
  33. package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
  34. package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
  35. package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
  36. package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
  37. package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
  38. package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
  39. package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
  40. package/runtime/scripts/hfs/architecture/config.mjs +302 -268
  41. package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
  42. package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
  43. package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
  44. package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
  45. package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
  46. package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
  47. package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
  48. package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
  49. package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
  50. package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
  51. package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
  52. package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
  53. package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
  54. package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
  55. package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
  56. package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
  57. package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
  58. package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
  59. package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
  60. package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
  61. package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
  62. package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
  63. package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
  64. package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
  65. package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
  66. package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
  67. package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
  68. package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
  69. package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
  70. package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
  71. package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
  72. package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
  73. package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
  74. package/runtime/scripts/hfs/architecture/index.mjs +272 -272
  75. package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
  76. package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
  77. package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
  78. package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
  79. package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
  80. package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
  81. package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
  82. package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
  83. package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
  84. package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
  85. package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
  86. package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
  87. package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
  88. package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
  89. package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
  90. package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
  91. package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
  92. package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
  93. package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
  94. package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
  95. package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
  96. package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
  97. package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
  98. package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
  99. package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
  100. package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
  101. package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
  102. package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
  103. package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
  104. package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
  105. package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
  106. package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
  107. package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
  108. package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
  109. package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
  110. package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
  111. package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
  112. package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
  113. package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
  114. package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
  115. package/runtime/scripts/hfs/edition-slots.mjs +43 -40
  116. package/runtime/scripts/hfs/linear-text.mjs +20 -20
  117. package/runtime/scripts/hfs/param-names.mjs +6 -11
  118. package/runtime/scripts/hfs/path-findings.mjs +120 -100
  119. package/runtime/scripts/hfs/repo-identity.mjs +55 -42
  120. package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
  121. package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
  122. package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
  123. package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
  124. package/runtime/scripts/hfs/rules/read.mjs +19 -15
  125. package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
  126. package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
  127. package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
  128. package/runtime/scripts/hfs/slot-classify.mjs +42 -38
  129. package/runtime/scripts/hfs/slot-errors.mjs +8 -7
  130. package/runtime/scripts/hfs/slot-imports.mjs +70 -63
  131. package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
  132. package/runtime/scripts/hfs/slot-match.mjs +122 -111
  133. package/runtime/scripts/hfs/slot-path.mjs +0 -2
  134. package/runtime/scripts/hfs/slot-required.mjs +65 -59
  135. package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
  136. package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
  137. package/runtime/scripts/hfs/slots.mjs +175 -152
  138. package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
  139. package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
  140. package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
  141. package/runtime/scripts/hfs/view.mjs +38 -40
  142. package/runtime/scripts/lib/dockerfile.mjs +131 -114
  143. package/runtime/scripts/lib/env.mjs +3 -6
  144. package/runtime/scripts/lib/event-contract.mjs +73 -78
  145. package/runtime/scripts/lib/git.mjs +15 -16
  146. package/runtime/scripts/lib/glob.mjs +23 -14
  147. package/runtime/scripts/lib/grammar-lint.mjs +33 -37
  148. package/runtime/scripts/lib/i18n.mjs +32 -35
  149. package/runtime/scripts/lib/in-order.mjs +57 -38
  150. package/runtime/scripts/lib/json-clone.mjs +45 -36
  151. package/runtime/scripts/lib/json.mjs +26 -14
  152. package/runtime/scripts/lib/language.mjs +133 -129
  153. package/runtime/scripts/lib/list.mjs +9 -14
  154. package/runtime/scripts/lib/mutation-fence.mjs +10 -5
  155. package/runtime/scripts/lib/path-key.mjs +53 -38
  156. package/runtime/scripts/lib/read-text.mjs +30 -17
  157. package/runtime/scripts/lib/regex.mjs +1 -2
  158. package/runtime/scripts/lib/same-text.mjs +0 -1
  159. package/runtime/scripts/lib/sops-envelope.mjs +148 -120
  160. package/runtime/scripts/lib/stack-services.mjs +128 -129
  161. package/runtime/scripts/lib/ts-analysis.mjs +28 -26
  162. package/runtime/scripts/lib/ts-ast.mjs +36 -42
  163. package/runtime/scripts/lib/walk.mjs +33 -27
  164. package/runtime/scripts/lib/yaml-cached.mjs +4 -4
@@ -5,437 +5,458 @@ import { reachableViolation, relativePath } from './typescript.mjs';
5
5
  import { checkApplicationEnvironment } from './backend-app-files.mjs';
6
6
  import { accessName, sourceLocation } from '../../lib/ts-ast.mjs';
7
7
  import { byCodeUnit } from '../../lib/list.mjs';
8
-
9
8
  const FORBIDDEN_APP_ROLE = /(?:^|\.)(?:service|provider|providers|resolver|controller|handler|repository|entity|use-case|command|query|listener|consumer|processor)\.[cm]?[jt]sx?$/i;
10
9
  const FORBIDDEN_DECLARATION = /(?:Service|Provider|Resolver|Controller|Handler|Repository|Entity|UseCase|Command|Query|Listener|Consumer|Processor)$/;
11
10
  const FORBIDDEN_DECORATORS = new Set(['Controller', 'Resolver', 'Injectable', 'Processor', 'WebSocketGateway']);
12
11
  const TRANSPORT_PACKAGES = new RegExp(`^(?:${[
13
- '@nestjs/(?:graphql|microservices|platform-[^/]+|websockets)(?:/|$)',
14
- '@apollo/',
15
- 'apollo-server(?:/|$)',
16
- 'express(?:/|$)',
17
- 'fastify(?:/|$)',
18
- 'graphql(?:/|$)',
19
- 'class-validator(?:/|$)',
20
- 'class-transformer(?:/|$)',
12
+ '@nestjs/(?:graphql|microservices|platform-[^/]+|websockets)(?:/|$)',
13
+ '@apollo/',
14
+ 'apollo-server(?:/|$)',
15
+ 'express(?:/|$)',
16
+ 'fastify(?:/|$)',
17
+ 'graphql(?:/|$)',
18
+ 'class-validator(?:/|$)',
19
+ 'class-transformer(?:/|$)',
21
20
  ].join('|')})`);
22
21
  const NEST_COMMON_TRANSPORT = new Set(['Controller', 'Get', 'Post', 'Put', 'Patch', 'Delete', 'Options', 'Head', 'Body', 'Param', 'Query', 'Req', 'Request', 'Res', 'Response', 'Headers', 'Header', 'HttpCode', 'Redirect', 'Render', 'Sse', 'UploadedFile', 'UploadedFiles', 'UseGuards', 'UseInterceptors', 'UsePipes']);
23
-
24
22
  function absolute(root, relative) {
25
- return path.resolve(root, ...relative.split('/'));
23
+ return path.resolve(root, ...relative.split('/'));
26
24
  }
27
-
28
25
  function roots(root, relatives) {
29
- return relatives.map(relative => absolute(root, relative));
26
+ return relatives.map(relative => absolute(root, relative));
30
27
  }
31
-
32
28
  function insideAny(candidates, fileName) {
33
- return candidates.some(root => isInside(root, fileName));
29
+ return candidates.some(root => isInside(root, fileName));
34
30
  }
35
-
36
31
  function insideFeatureLayer(featureRoots, fileName, layer) {
37
- return featureRoots.some(root => isInside(root, fileName)
38
- && relativePath(root, fileName).split('/').some(segment => segment.toLowerCase() === layer));
32
+ return featureRoots.some(root => isInside(root, fileName)
33
+ && relativePath(root, fileName).split('/').some(segment => segment.toLowerCase() === layer));
39
34
  }
40
-
41
35
  function appSource(config, fileName, excludedRoots = []) {
42
- if (excludedRoots.some(excluded => isInside(excluded, fileName))) return null;
43
- for (const appRoot of roots(config.root, config.backend.apps)) {
44
- if (!isInside(appRoot, fileName)) continue;
45
- const parts = relativePath(appRoot, fileName).split('/');
46
- const sourceIndex = parts.indexOf('src');
47
- if (sourceIndex >= 0) return { appRoot, relative: parts.slice(sourceIndex + 1).join('/') };
48
- // An app root may name its src/ directly (apps/<app>/src), but the repository src/ itself is
49
- // never an app root: HFS composition lives under apps/<app> only.
50
- const appRootRelative = relativePath(config.root, appRoot).split('/');
51
- if (path.basename(appRoot).toLowerCase() === 'src' && appRootRelative[0] === 'apps' && appRootRelative.length > 1) {
52
- return { appRoot, relative: parts.join('/') };
36
+ if (excludedRoots.some(excluded => isInside(excluded, fileName)))
37
+ return null;
38
+ for (const appRoot of roots(config.root, config.backend.apps)) {
39
+ if (!isInside(appRoot, fileName))
40
+ continue;
41
+ const parts = relativePath(appRoot, fileName).split('/');
42
+ const sourceIndex = parts.indexOf('src');
43
+ if (sourceIndex >= 0)
44
+ return { appRoot, relative: parts.slice(sourceIndex + 1).join('/') };
45
+ // An app root may name its src/ directly (apps/<app>/src), but the repository src/ itself is
46
+ // never an app root: HFS composition lives under apps/<app> only.
47
+ const appRootRelative = relativePath(config.root, appRoot).split('/');
48
+ if (path.basename(appRoot).toLowerCase() === 'src' && appRootRelative[0] === 'apps' && appRootRelative.length > 1) {
49
+ return { appRoot, relative: parts.join('/') };
50
+ }
51
+ return null;
53
52
  }
54
53
  return null;
55
- }
56
- return null;
57
54
  }
58
-
59
55
  function decoratorName(ts, decorator) {
60
- const expression = decorator.expression;
61
- const called = ts.isCallExpression(expression) ? expression.expression : expression;
62
- if (ts.isIdentifier(called)) return called.text;
63
- return ts.isPropertyAccessExpression(called) ? called.name.text : null;
56
+ const expression = decorator.expression;
57
+ const called = ts.isCallExpression(expression) ? expression.expression : expression;
58
+ if (ts.isIdentifier(called))
59
+ return called.text;
60
+ return ts.isPropertyAccessExpression(called) ? called.name.text : null;
64
61
  }
65
-
66
62
  function roleEvidence(ts, sourceFile) {
67
- let found = null;
68
- const visit = node => {
69
- if (found) return;
70
- const decorators = ts.canHaveDecorators?.(node) ? ts.getDecorators(node) ?? [] : node.decorators ?? [];
71
- const forbidden = decorators.find(item => FORBIDDEN_DECORATORS.has(decoratorName(ts, item)));
72
- if (forbidden) {
73
- found = { node: forbidden, detail: `@${decoratorName(ts, forbidden)}` };
74
- return;
75
- }
76
- if ((ts.isClassDeclaration(node) || ts.isFunctionDeclaration(node)) && node.name && FORBIDDEN_DECLARATION.test(node.name.text)) {
77
- found = { node: node.name, detail: node.name.text };
78
- return;
79
- }
80
- ts.forEachChild(node, visit);
81
- };
82
- visit(sourceFile);
83
- return found;
63
+ let found = null;
64
+ const visit = (node) => {
65
+ if (found)
66
+ return;
67
+ // reason: compilers before TypeScript 4.8 expose decorators as node.decorators, which the current typings no longer declare
68
+ const legacyDecorators = node.decorators;
69
+ const decorators = ts.canHaveDecorators?.(node) ? ts.getDecorators(node) ?? [] : legacyDecorators ?? [];
70
+ const forbidden = decorators.find(item => FORBIDDEN_DECORATORS.has(decoratorName(ts, item) ?? ''));
71
+ if (forbidden) {
72
+ found = { node: forbidden, detail: `@${decoratorName(ts, forbidden)}` };
73
+ return;
74
+ }
75
+ if ((ts.isClassDeclaration(node) || ts.isFunctionDeclaration(node)) && node.name && FORBIDDEN_DECLARATION.test(node.name.text)) {
76
+ found = { node: node.name, detail: node.name.text };
77
+ return;
78
+ }
79
+ ts.forEachChild(node, visit);
80
+ };
81
+ visit(sourceFile);
82
+ return found;
84
83
  }
85
-
86
84
  // The destructured binding elements naming a transport export (or a computed binding, which cannot be
87
85
  // proved to exclude one): `const { Controller, [x]: y } = ...`. `rest` elements are always opaque.
88
86
  function destructuredTransportBindings(ts, elements, detail) {
89
- return elements.flatMap(element => {
90
- let selected = null;
91
- if (!element.dotDotDotToken) {
92
- const imported = element.propertyName ?? element.name;
93
- if (ts.isIdentifier(imported) || ts.isStringLiteralLike(imported)) selected = imported.text;
94
- }
95
- return selected === null || NEST_COMMON_TRANSPORT.has(selected) ? [{ node: element, detail: selected ?? detail }] : [];
96
- });
87
+ return elements.flatMap((element) => {
88
+ let selected = null;
89
+ if (!element.dotDotDotToken) {
90
+ const imported = element.propertyName ?? element.name;
91
+ if (ts.isIdentifier(imported) || ts.isStringLiteralLike(imported))
92
+ selected = imported.text;
93
+ }
94
+ return selected === null || NEST_COMMON_TRANSPORT.has(selected) ? [{ node: element, detail: selected ?? detail }] : [];
95
+ });
97
96
  }
98
-
99
97
  const namespaceMemberUsages = (ts, node, isAlias) => {
100
- if (ts.isPropertyAccessExpression(node) && isAlias(node.expression)
101
- && NEST_COMMON_TRANSPORT.has(node.name.text)) return [{ node: node.name, detail: node.name.text }];
102
- if (ts.isElementAccessExpression(node) && isAlias(node.expression)) {
103
- const selected = ts.isStringLiteralLike(node.argumentExpression) ? node.argumentExpression.text : null;
104
- if (selected === null || NEST_COMMON_TRANSPORT.has(selected)) return [{ node: node.argumentExpression, detail: selected ?? 'computed @nestjs/common namespace access' }];
105
- }
106
- return [];
98
+ if (ts.isPropertyAccessExpression(node) && isAlias(node.expression)
99
+ && NEST_COMMON_TRANSPORT.has(node.name.text))
100
+ return [{ node: node.name, detail: node.name.text }];
101
+ if (ts.isElementAccessExpression(node) && isAlias(node.expression)) {
102
+ const selected = ts.isStringLiteralLike(node.argumentExpression) ? node.argumentExpression.text : null;
103
+ if (selected === null || NEST_COMMON_TRANSPORT.has(selected))
104
+ return [{ node: node.argumentExpression, detail: selected ?? 'computed @nestjs/common namespace access' }];
105
+ }
106
+ return [];
107
107
  };
108
-
109
108
  const namespaceEscapeUsages = (ts, node, isAlias) => {
110
- if (!ts.isVariableDeclaration(node) || !isAlias(node.initializer)) return [];
111
- if (!ts.isObjectBindingPattern(node.name)) return [{ node: node.name, detail: 'escaped @nestjs/common namespace access' }];
112
- return destructuredTransportBindings(ts, node.name.elements, 'computed @nestjs/common namespace destructuring');
109
+ if (!ts.isVariableDeclaration(node) || !node.initializer || !isAlias(node.initializer))
110
+ return [];
111
+ if (!ts.isObjectBindingPattern(node.name))
112
+ return [{ node: node.name, detail: 'escaped @nestjs/common namespace access' }];
113
+ return destructuredTransportBindings(ts, node.name.elements, 'computed @nestjs/common namespace destructuring');
113
114
  };
114
-
115
115
  function namespaceTransportUsages(ts, sourceFile, checker, binding) {
116
- const usages = [];
117
- const alias = binding.text;
118
- const bindingSymbol = checker?.getSymbolAtLocation(binding);
119
- const isAlias = node => ts.isIdentifier(node) && node.text === alias
120
- && (!bindingSymbol || checker?.getSymbolAtLocation(node) === bindingSymbol);
121
- const visit = node => {
122
- usages.push(...namespaceMemberUsages(ts, node, isAlias), ...namespaceEscapeUsages(ts, node, isAlias));
123
- ts.forEachChild(node, visit);
124
- };
125
- visit(sourceFile);
126
- return usages;
127
- }
128
-
116
+ const usages = [];
117
+ const alias = binding.text;
118
+ const bindingSymbol = checker?.getSymbolAtLocation(binding);
119
+ const isAlias = node => ts.isIdentifier(node) && node.text === alias
120
+ && (!bindingSymbol || checker?.getSymbolAtLocation(node) === bindingSymbol);
121
+ const visit = (node) => {
122
+ usages.push(...namespaceMemberUsages(ts, node, isAlias), ...namespaceEscapeUsages(ts, node, isAlias));
123
+ ts.forEachChild(node, visit);
124
+ };
125
+ visit(sourceFile);
126
+ return usages;
127
+ }
129
128
  function importSpecifierOf(ts, statement) {
130
- const importEqualsSpecifier = ts.isImportEqualsDeclaration(statement)
131
- && ts.isExternalModuleReference(statement.moduleReference)
132
- && statement.moduleReference.expression
133
- && ts.isStringLiteralLike(statement.moduleReference.expression)
134
- ? statement.moduleReference.expression
135
- : null;
136
- let importSpecifier = importEqualsSpecifier;
137
- if (ts.isImportDeclaration(statement) && ts.isStringLiteralLike(statement.moduleSpecifier)) importSpecifier = statement.moduleSpecifier;
138
- return importSpecifier;
139
- }
140
-
129
+ const importEqualsSpecifier = ts.isImportEqualsDeclaration(statement)
130
+ && ts.isExternalModuleReference(statement.moduleReference)
131
+ && statement.moduleReference.expression
132
+ && ts.isStringLiteralLike(statement.moduleReference.expression)
133
+ ? statement.moduleReference.expression
134
+ : null;
135
+ let importSpecifier = importEqualsSpecifier;
136
+ if (ts.isImportDeclaration(statement) && ts.isStringLiteralLike(statement.moduleSpecifier))
137
+ importSpecifier = statement.moduleSpecifier;
138
+ return importSpecifier;
139
+ }
141
140
  function addCommonImportEvidence(ts, statement, importSpecifier, sourceFile, checker, found) {
142
- if (ts.isImportEqualsDeclaration(statement)) {
143
- found.push(...namespaceTransportUsages(ts, sourceFile, checker, statement.name).map(item => ({ ...item, specifier: importSpecifier.text })));
144
- return;
145
- }
146
- if (!statement.importClause) return;
147
- const bindings = statement.importClause.namedBindings;
148
- if (bindings && ts.isNamespaceImport(bindings)) {
149
- found.push(...namespaceTransportUsages(ts, sourceFile, checker, bindings.name).map(item => ({ ...item, specifier: importSpecifier.text })));
150
- return;
151
- }
152
- if (!bindings || !ts.isNamedImports(bindings)) return;
153
- for (const element of bindings.elements) {
154
- const imported = element.propertyName?.text ?? element.name.text;
155
- if (NEST_COMMON_TRANSPORT.has(imported)) found.push({ node: element, specifier: importSpecifier.text, detail: imported });
156
- }
157
- }
158
-
141
+ if (ts.isImportEqualsDeclaration(statement)) {
142
+ found.push(...namespaceTransportUsages(ts, sourceFile, checker, statement.name).map(item => ({ ...item, specifier: importSpecifier.text })));
143
+ return;
144
+ }
145
+ if (!ts.isImportDeclaration(statement) || !statement.importClause)
146
+ return;
147
+ const bindings = statement.importClause.namedBindings;
148
+ if (bindings && ts.isNamespaceImport(bindings)) {
149
+ found.push(...namespaceTransportUsages(ts, sourceFile, checker, bindings.name).map(item => ({ ...item, specifier: importSpecifier.text })));
150
+ return;
151
+ }
152
+ if (!bindings || !ts.isNamedImports(bindings))
153
+ return;
154
+ for (const element of bindings.elements) {
155
+ const imported = element.propertyName?.text ?? element.name.text;
156
+ if (NEST_COMMON_TRANSPORT.has(imported))
157
+ found.push({ node: element, specifier: importSpecifier.text, detail: imported });
158
+ }
159
+ }
159
160
  function importTransportEvidence(ts, sourceFile, checker, found) {
160
- for (const statement of sourceFile.statements) {
161
- const importSpecifier = importSpecifierOf(ts, statement);
162
- if (!importSpecifier) continue;
163
- const specifier = importSpecifier.text;
164
- if (TRANSPORT_PACKAGES.test(specifier)) {
165
- found.push({ node: importSpecifier, specifier, detail: specifier });
166
- continue;
161
+ for (const statement of sourceFile.statements) {
162
+ const importSpecifier = importSpecifierOf(ts, statement);
163
+ if (!importSpecifier)
164
+ continue;
165
+ const specifier = importSpecifier.text;
166
+ if (TRANSPORT_PACKAGES.test(specifier)) {
167
+ found.push({ node: importSpecifier, specifier, detail: specifier });
168
+ continue;
169
+ }
170
+ if (specifier === '@nestjs/common')
171
+ addCommonImportEvidence(ts, statement, importSpecifier, sourceFile, checker, found);
167
172
  }
168
- if (specifier === '@nestjs/common') addCommonImportEvidence(ts, statement, importSpecifier, sourceFile, checker, found);
169
- }
170
173
  }
171
-
172
174
  function requiredSpecifier(ts, call) {
173
- return ts.isCallExpression(call)
174
- && ts.isIdentifier(call.expression) && call.expression.text === 'require'
175
- && call.arguments.length === 1 && ts.isStringLiteralLike(call.arguments[0])
176
- ? call.arguments[0].text
177
- : null;
175
+ const first = ts.isCallExpression(call) ? call.arguments[0] : undefined;
176
+ return ts.isCallExpression(call)
177
+ && ts.isIdentifier(call.expression) && call.expression.text === 'require'
178
+ && call.arguments.length === 1 && first && ts.isStringLiteralLike(first)
179
+ ? first.text
180
+ : null;
178
181
  }
179
-
180
182
  function requiredMemberEvidence(ts, node, found) {
181
- if (!(ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) || !ts.isCallExpression(node.expression)) return;
182
- const specifier = requiredSpecifier(ts, node.expression);
183
- const selected = accessName(ts, node);
184
- const member = ts.isPropertyAccessExpression(node) ? node.name : node.argumentExpression;
185
- if (specifier && TRANSPORT_PACKAGES.test(specifier)) {
186
- found.push({ node: member, specifier, detail: `${selected ?? 'computed member'} from ${specifier}` });
187
- } else if (specifier === '@nestjs/common' && (selected === null || NEST_COMMON_TRANSPORT.has(selected))) {
188
- found.push({ node: member, specifier, detail: selected ?? 'computed @nestjs/common require access' });
189
- }
190
- }
191
-
183
+ if (!(ts.isPropertyAccessExpression(node) || ts.isElementAccessExpression(node)) || !ts.isCallExpression(node.expression))
184
+ return;
185
+ const specifier = requiredSpecifier(ts, node.expression);
186
+ const selected = accessName(ts, node);
187
+ const member = ts.isPropertyAccessExpression(node) ? node.name : node.argumentExpression;
188
+ if (specifier && TRANSPORT_PACKAGES.test(specifier)) {
189
+ found.push({ node: member, specifier, detail: `${selected ?? 'computed member'} from ${specifier}` });
190
+ }
191
+ else if (specifier === '@nestjs/common' && (selected === null || NEST_COMMON_TRANSPORT.has(selected))) {
192
+ found.push({ node: member, specifier, detail: selected ?? 'computed @nestjs/common require access' });
193
+ }
194
+ }
192
195
  function requiredVariableEvidence(ts, node, sourceFile, checker, found) {
193
- if (!ts.isVariableDeclaration(node) || !node.initializer || !ts.isCallExpression(node.initializer)
194
- || !requiredSpecifier(ts, node.initializer)) return;
195
- const specifier = requiredSpecifier(ts, node.initializer);
196
- if (TRANSPORT_PACKAGES.test(specifier)) {
197
- found.push({ node: node.initializer.arguments[0], specifier, detail: specifier });
198
- } else if (specifier === '@nestjs/common') {
199
- if (ts.isIdentifier(node.name)) {
200
- found.push(...namespaceTransportUsages(ts, sourceFile, checker, node.name).map(item => ({ ...item, specifier })));
201
- } else if (ts.isObjectBindingPattern(node.name)) {
202
- found.push(...destructuredTransportBindings(ts, node.name.elements, 'computed @nestjs/common require destructuring').map(item => ({ ...item, specifier })));
196
+ if (!ts.isVariableDeclaration(node) || !node.initializer || !ts.isCallExpression(node.initializer))
197
+ return;
198
+ const specifier = requiredSpecifier(ts, node.initializer);
199
+ const argument = node.initializer.arguments[0];
200
+ if (!specifier || !argument)
201
+ return;
202
+ if (TRANSPORT_PACKAGES.test(specifier)) {
203
+ found.push({ node: argument, specifier, detail: specifier });
204
+ }
205
+ else if (specifier === '@nestjs/common') {
206
+ if (ts.isIdentifier(node.name)) {
207
+ found.push(...namespaceTransportUsages(ts, sourceFile, checker, node.name).map(item => ({ ...item, specifier })));
208
+ }
209
+ else if (ts.isObjectBindingPattern(node.name)) {
210
+ found.push(...destructuredTransportBindings(ts, node.name.elements, 'computed @nestjs/common require destructuring').map(item => ({ ...item, specifier })));
211
+ }
203
212
  }
204
- }
205
213
  }
206
-
207
214
  function requiredTransportEvidence(ts, node, sourceFile, checker, found) {
208
- requiredMemberEvidence(ts, node, found);
209
- requiredVariableEvidence(ts, node, sourceFile, checker, found);
210
- ts.forEachChild(node, child => requiredTransportEvidence(ts, child, sourceFile, checker, found));
215
+ requiredMemberEvidence(ts, node, found);
216
+ requiredVariableEvidence(ts, node, sourceFile, checker, found);
217
+ ts.forEachChild(node, child => requiredTransportEvidence(ts, child, sourceFile, checker, found));
211
218
  }
212
-
213
219
  function transportFrameworkEvidence(ts, sourceFile, checker) {
214
- const found = [];
215
- importTransportEvidence(ts, sourceFile, checker, found);
216
- requiredTransportEvidence(ts, sourceFile, sourceFile, checker, found);
217
- return found;
220
+ const found = [];
221
+ importTransportEvidence(ts, sourceFile, checker, found);
222
+ requiredTransportEvidence(ts, sourceFile, sourceFile, checker, found);
223
+ return found;
218
224
  }
219
-
220
225
  function importedSurface(ts, declaration) {
221
- if (!ts.isImportDeclaration(declaration)) return null;
222
- const clause = declaration.importClause;
223
- if (!clause) return null;
224
- const names = new Set(clause.name ? ['default'] : []);
225
- const bindings = clause.namedBindings;
226
- if (bindings && ts.isNamespaceImport(bindings)) return null;
227
- if (bindings && ts.isNamedImports(bindings)) {
228
- for (const element of bindings.elements) names.add(element.propertyName?.text ?? element.name.text);
229
- }
230
- return names;
231
- }
232
-
226
+ if (!ts.isImportDeclaration(declaration))
227
+ return null;
228
+ const clause = declaration.importClause;
229
+ if (!clause)
230
+ return null;
231
+ const names = new Set(clause.name ? ['default'] : []);
232
+ const bindings = clause.namedBindings;
233
+ if (bindings && ts.isNamespaceImport(bindings))
234
+ return null;
235
+ if (bindings && ts.isNamedImports(bindings)) {
236
+ for (const element of bindings.elements)
237
+ names.add(element.propertyName?.text ?? element.name.text);
238
+ }
239
+ return names;
240
+ }
233
241
  function selectedReexportSurface(ts, declaration, selected) {
234
- if (!ts.isExportDeclaration(declaration)) return undefined;
235
- if (!declaration.exportClause) return selected;
236
- if (ts.isNamespaceExport(declaration.exportClause)) {
237
- return selected === null || selected.has(declaration.exportClause.name.text) ? null : undefined;
238
- }
239
- if (!ts.isNamedExports(declaration.exportClause)) return undefined;
240
- const next = new Set();
241
- for (const element of declaration.exportClause.elements) {
242
- if (selected === null || selected.has(element.name.text)) next.add(element.propertyName?.text ?? element.name.text);
243
- }
244
- return next.size ? next : undefined;
245
- }
246
-
242
+ if (!ts.isExportDeclaration(declaration))
243
+ return undefined;
244
+ if (!declaration.exportClause)
245
+ return selected;
246
+ if (ts.isNamespaceExport(declaration.exportClause)) {
247
+ return selected === null || selected.has(declaration.exportClause.name.text) ? null : undefined;
248
+ }
249
+ if (!ts.isNamedExports(declaration.exportClause))
250
+ return undefined;
251
+ const next = new Set();
252
+ for (const element of declaration.exportClause.elements) {
253
+ if (selected === null || selected.has(element.name.text))
254
+ next.add(element.propertyName?.text ?? element.name.text);
255
+ }
256
+ return next.size ? next : undefined;
257
+ }
247
258
  function importedTransportBindings(ts, sourceFile) {
248
- const imported = new Map();
249
- for (const statement of sourceFile.statements) {
250
- if (!ts.isImportDeclaration(statement) || !ts.isStringLiteralLike(statement.moduleSpecifier) || !statement.importClause) continue;
251
- const specifier = statement.moduleSpecifier.text;
252
- const bindings = statement.importClause.namedBindings;
253
- if (bindings && ts.isNamedImports(bindings)) {
254
- for (const element of bindings.elements) imported.set(element.name.text, { specifier, imported: element.propertyName?.text ?? element.name.text });
255
- } else if (bindings && ts.isNamespaceImport(bindings)) imported.set(bindings.name.text, { specifier, imported: null });
256
- }
257
- return imported;
259
+ const imported = new Map();
260
+ for (const statement of sourceFile.statements) {
261
+ if (!ts.isImportDeclaration(statement) || !ts.isStringLiteralLike(statement.moduleSpecifier) || !statement.importClause)
262
+ continue;
263
+ const specifier = statement.moduleSpecifier.text;
264
+ const bindings = statement.importClause.namedBindings;
265
+ if (bindings && ts.isNamedImports(bindings)) {
266
+ for (const element of bindings.elements)
267
+ imported.set(element.name.text, { specifier, imported: element.propertyName?.text ?? element.name.text });
268
+ }
269
+ else if (bindings && ts.isNamespaceImport(bindings))
270
+ imported.set(bindings.name.text, { specifier, imported: null });
271
+ }
272
+ return imported;
258
273
  }
259
-
260
274
  const unnamedReexport = (statement, specifier, selected) => {
261
- if (specifier !== '@nestjs/common' || selected === null || [...selected].some(name => NEST_COMMON_TRANSPORT.has(name))) {
262
- return { node: statement.moduleSpecifier, specifier, detail: selected === null ? `unbounded ${specifier} re-export` : `re-exported ${[...selected].join(', ')}` };
263
- }
264
- return null;
275
+ if (specifier !== '@nestjs/common' || selected === null || [...selected].some(name => NEST_COMMON_TRANSPORT.has(name))) {
276
+ return { node: statement.moduleSpecifier ?? statement, specifier, detail: selected === null ? `unbounded ${specifier} re-export` : `re-exported ${[...selected].join(', ')}` };
277
+ }
278
+ return null;
265
279
  };
266
-
267
280
  const namedReexport = (clause, specifier, selected) => {
268
- for (const element of clause.elements) {
269
- if (selected !== null && !selected.has(element.name.text)) continue;
270
- const original = element.propertyName?.text ?? element.name.text;
271
- if (specifier !== '@nestjs/common' || NEST_COMMON_TRANSPORT.has(original)) return { node: element, specifier, detail: `${element.name.text} re-exported from ${specifier}` };
272
- }
273
- return null;
281
+ for (const element of clause.elements) {
282
+ if (selected !== null && !selected.has(element.name.text))
283
+ continue;
284
+ const original = element.propertyName?.text ?? element.name.text;
285
+ if (specifier !== '@nestjs/common' || NEST_COMMON_TRANSPORT.has(original))
286
+ return { node: element, specifier, detail: `${element.name.text} re-exported from ${specifier}` };
287
+ }
288
+ return null;
274
289
  };
275
-
276
290
  function directTransportReexport(ts, statement, specifier, selected) {
277
- const clause = statement.exportClause;
278
- if (!clause) return unnamedReexport(statement, specifier, selected);
279
- if (ts.isNamespaceExport(clause)) {
280
- return selected === null || selected.has(clause.name.text) ? { node: clause.name, specifier, detail: `namespace re-export from ${specifier}` } : null;
281
- }
282
- return ts.isNamedExports(clause) ? namedReexport(clause, specifier, selected) : null;
283
- }
284
-
291
+ const clause = statement.exportClause;
292
+ if (!clause)
293
+ return unnamedReexport(statement, specifier, selected);
294
+ if (ts.isNamespaceExport(clause)) {
295
+ return selected === null || selected.has(clause.name.text) ? { node: clause.name, specifier, detail: `namespace re-export from ${specifier}` } : null;
296
+ }
297
+ return ts.isNamedExports(clause) ? namedReexport(clause, specifier, selected) : null;
298
+ }
285
299
  /** True for an import binding of a transport package, or of a transport symbol of @nestjs/common. */
286
- const isTransportBinding = binding => (binding.specifier === '@nestjs/common'
287
- ? binding.imported !== null && NEST_COMMON_TRANSPORT.has(binding.imported)
288
- : TRANSPORT_PACKAGES.test(binding.specifier));
289
-
300
+ const isTransportBinding = (binding) => (binding.specifier === '@nestjs/common'
301
+ ? binding.imported !== null && NEST_COMMON_TRANSPORT.has(binding.imported)
302
+ : TRANSPORT_PACKAGES.test(binding.specifier));
290
303
  function localTransportReexport(ts, statement, selected, imported) {
291
- const clause = statement.exportClause;
292
- if (!clause || !ts.isNamedExports(clause)) return null;
293
- for (const element of clause.elements) {
294
- if (selected !== null && !selected.has(element.name.text)) continue;
295
- const binding = imported.get(element.propertyName?.text ?? element.name.text);
296
- if (!binding || !isTransportBinding(binding)) continue;
297
- return { node: element, specifier: binding.specifier, detail: `${element.name.text} re-exported from ${binding.specifier}` };
298
- }
299
- return null;
300
- }
301
-
304
+ const clause = statement.exportClause;
305
+ if (!clause || !ts.isNamedExports(clause))
306
+ return null;
307
+ for (const element of clause.elements) {
308
+ if (selected !== null && !selected.has(element.name.text))
309
+ continue;
310
+ const binding = imported.get(element.propertyName?.text ?? element.name.text);
311
+ if (!binding || !isTransportBinding(binding))
312
+ continue;
313
+ return { node: element, specifier: binding.specifier, detail: `${element.name.text} re-exported from ${binding.specifier}` };
314
+ }
315
+ return null;
316
+ }
302
317
  const statementTransportReexport = (ts, statement, selected, imported) => {
303
- const specifier = statement.moduleSpecifier && ts.isStringLiteralLike(statement.moduleSpecifier) ? statement.moduleSpecifier.text : null;
304
- if (specifier && (specifier === '@nestjs/common' || TRANSPORT_PACKAGES.test(specifier))) return directTransportReexport(ts, statement, specifier, selected);
305
- return specifier ? null : localTransportReexport(ts, statement, selected, imported);
318
+ const specifier = statement.moduleSpecifier && ts.isStringLiteralLike(statement.moduleSpecifier) ? statement.moduleSpecifier.text : null;
319
+ if (specifier && (specifier === '@nestjs/common' || TRANSPORT_PACKAGES.test(specifier)))
320
+ return directTransportReexport(ts, statement, specifier, selected);
321
+ return specifier ? null : localTransportReexport(ts, statement, selected, imported);
306
322
  };
307
-
308
323
  function externalTransportReexport(ts, sourceFile, selected) {
309
- const imported = importedTransportBindings(ts, sourceFile);
310
- for (const statement of sourceFile.statements) {
311
- if (!ts.isExportDeclaration(statement)) continue;
312
- const evidence = statementTransportReexport(ts, statement, selected, imported);
313
- if (evidence) return evidence;
314
- }
315
- return null;
316
- }
317
-
324
+ const imported = importedTransportBindings(ts, sourceFile);
325
+ for (const statement of sourceFile.statements) {
326
+ if (!ts.isExportDeclaration(statement))
327
+ continue;
328
+ const evidence = statementTransportReexport(ts, statement, selected, imported);
329
+ if (evidence)
330
+ return evidence;
331
+ }
332
+ return null;
333
+ }
318
334
  function reexportQueueKey(current) {
319
- return `${current.file}\0${current.selected === null ? '*' : [...current.selected].sort(byCodeUnit).join(',')}`;
335
+ return `${current.file}\0${current.selected === null ? '*' : [...current.selected].sort(byCodeUnit).join(',')}`;
320
336
  }
321
-
322
337
  function addReexportEdges(ts, context, current, queue) {
323
- for (const edge of context.edges.get(current.file) ?? []) {
324
- if (!edge.reexport) continue;
325
- const selected = selectedReexportSurface(ts, edge.declaration, current.selected);
326
- if (selected !== undefined) queue.push({ file: edge.to, selected, chain: [...current.chain, edge.to] });
327
- }
338
+ for (const edge of context.edges.get(current.file) ?? []) {
339
+ if (!edge.reexport)
340
+ continue;
341
+ const selected = selectedReexportSurface(ts, edge.declaration, current.selected);
342
+ if (selected !== undefined)
343
+ queue.push({ file: edge.to, selected, chain: [...current.chain, edge.to] });
344
+ }
328
345
  }
329
-
330
346
  function reexportedTransportEvidence(ts, context, sourceFiles, firstEdge) {
331
- const queue = [{ file: firstEdge.to, selected: importedSurface(ts, firstEdge.declaration), chain: [firstEdge.from, firstEdge.to] }];
332
- const visited = new Set();
333
- while (queue.length) {
334
- const current = queue.shift();
335
- const key = reexportQueueKey(current);
336
- if (visited.has(key)) continue;
337
- visited.add(key);
338
- const sourceFile = sourceFiles.get(path.resolve(current.file));
339
- if (!sourceFile) continue;
340
- const evidence = externalTransportReexport(ts, sourceFile, current.selected);
341
- if (evidence) return { evidence, chain: current.chain };
342
- addReexportEdges(ts, context, current, queue);
343
- }
344
- return null;
345
- }
346
-
347
+ const queue = [{ file: firstEdge.to, selected: importedSurface(ts, firstEdge.declaration), chain: [firstEdge.from, firstEdge.to] }];
348
+ const visited = new Set();
349
+ while (queue.length) {
350
+ const current = queue.shift();
351
+ if (!current)
352
+ break;
353
+ const key = reexportQueueKey(current);
354
+ if (visited.has(key))
355
+ continue;
356
+ visited.add(key);
357
+ const sourceFile = sourceFiles.get(path.resolve(current.file));
358
+ if (!sourceFile)
359
+ continue;
360
+ const evidence = externalTransportReexport(ts, sourceFile, current.selected);
361
+ if (evidence)
362
+ return { evidence, chain: current.chain };
363
+ addReexportEdges(ts, context, current, queue);
364
+ }
365
+ return null;
366
+ }
347
367
  function finding(config, edge, ruleId, message, chain) {
348
- return {
349
- ruleId,
350
- path: relativePath(config.root, edge.from),
351
- line: edge.line,
352
- column: edge.column,
353
- specifier: edge.specifier,
354
- resolvedPath: relativePath(config.root, chain.at(-1)),
355
- dependencyChain: chain.map(file => relativePath(config.root, file)),
356
- message,
357
- };
358
- }
359
-
368
+ return {
369
+ ruleId,
370
+ path: relativePath(config.root, edge.from),
371
+ line: edge.line,
372
+ column: edge.column,
373
+ specifier: edge.specifier,
374
+ resolvedPath: relativePath(config.root, chain.at(-1) ?? edge.to),
375
+ dependencyChain: chain.map(file => relativePath(config.root, file)),
376
+ message,
377
+ };
378
+ }
360
379
  function checkApplicationComposition(config, ts, sourceFile, fileName, app, violations) {
361
- const evidence = roleEvidence(ts, sourceFile);
362
- if (evidence) {
363
- violations.push({
364
- ruleId: 'BE_APP_BUSINESS_ROLE',
365
- path: relativePath(config.root, fileName),
366
- ...sourceLocation(sourceFile, evidence.node),
367
- message: `Application composition source contains measurable business/provider role ${evidence.detail}. Move that role under src/features or src/modules.`,
368
- });
369
- } else if (slotAdmitsFile(config.hfs, relativePath(config.root, fileName)) !== true) {
370
- violations.push({
371
- ruleId: FORBIDDEN_APP_ROLE.test(path.posix.basename(app.relative)) ? 'BE_APP_BUSINESS_ROLE' : 'BE_APP_COMPOSITION_ONLY',
372
- path: relativePath(config.root, fileName),
373
- line: 1,
374
- column: 1,
375
- message: `Application source ${app.relative} is not a file its app slot requires or allows (main.ts, app.module.ts, <app>.env.ts, <app>.options.ts, compose/<area>.ts).`,
376
- });
377
- }
380
+ const evidence = roleEvidence(ts, sourceFile);
381
+ if (evidence) {
382
+ violations.push({
383
+ ruleId: 'BE_APP_BUSINESS_ROLE',
384
+ path: relativePath(config.root, fileName),
385
+ ...sourceLocation(sourceFile, evidence.node),
386
+ message: `Application composition source contains measurable business/provider role ${evidence.detail}. Move that role under src/features or src/modules.`,
387
+ });
388
+ }
389
+ else if (slotAdmitsFile(config.hfs, relativePath(config.root, fileName)) !== true) {
390
+ violations.push({
391
+ ruleId: FORBIDDEN_APP_ROLE.test(path.posix.basename(app.relative)) ? 'BE_APP_BUSINESS_ROLE' : 'BE_APP_COMPOSITION_ONLY',
392
+ path: relativePath(config.root, fileName),
393
+ line: 1,
394
+ column: 1,
395
+ message: `Application source ${app.relative} is not a file its app slot requires or allows (main.ts, app.module.ts, <app>.env.ts, <app>.options.ts, compose/<area>.ts).`,
396
+ });
397
+ }
378
398
  }
379
-
380
399
  /** The app's environment parser never depends on features, even through a type import or an internal barrel. */
381
400
  function checkApplicationEnvEdges(config, context, fileName, violations) {
382
- const role = allowsFile(config.hfs, relativePath(config.root, fileName));
383
- if (!role?.allowed || role.entry !== '<app>.env.ts') return;
384
- const isFeature = target => config.hfs.tierOf(relativePath(config.root, target)) === 'feature';
385
- for (const edge of context.edges.get(fileName) ?? []) {
386
- const featureChain = reachableViolation(context.edges, edge, isFeature);
387
- if (featureChain) violations.push(finding(config, edge, 'BE_APP_COMPOSITION_ONLY',
388
- 'The app environment file holds typed, fail-fast environment parsing only; it cannot depend on features, including through a type import or an internal barrel.', featureChain));
389
- }
390
- }
391
-
401
+ const role = allowsFile(config.hfs, relativePath(config.root, fileName));
402
+ if (!role?.allowed || role.entry !== '<app>.env.ts')
403
+ return;
404
+ const isFeature = (target) => config.hfs.tierOf(relativePath(config.root, target)) === 'feature';
405
+ for (const edge of context.edges.get(fileName) ?? []) {
406
+ const featureChain = reachableViolation(context.edges, edge, isFeature);
407
+ if (featureChain)
408
+ violations.push(finding(config, edge, 'BE_APP_COMPOSITION_ONLY', 'The app environment file holds typed, fail-fast environment parsing only; it cannot depend on features, including through a type import or an internal barrel.', featureChain));
409
+ }
410
+ }
392
411
  function checkApplicationTransport(config, context, sourceFile, fileName, violations) {
393
- for (const evidence of transportFrameworkEvidence(context.ts, sourceFile, context.checkerFor(fileName))) {
394
- violations.push({
395
- ruleId: 'BE_APPLICATION_TRANSPORT_FRAMEWORK',
396
- path: relativePath(config.root, fileName),
397
- ...sourceLocation(sourceFile, evidence.node),
398
- specifier: evidence.specifier,
399
- message: `Feature application code imports transport framework surface ${evidence.detail}. Keep protocol decorators, request/response types, validation DTOs, and generated transport types under transport/.`,
400
- });
401
- }
412
+ for (const evidence of transportFrameworkEvidence(context.ts, sourceFile, context.checkerFor(fileName))) {
413
+ violations.push({
414
+ ruleId: 'BE_APPLICATION_TRANSPORT_FRAMEWORK',
415
+ path: relativePath(config.root, fileName),
416
+ ...sourceLocation(sourceFile, evidence.node),
417
+ specifier: evidence.specifier,
418
+ message: `Feature application code imports transport framework surface ${evidence.detail}. Keep protocol decorators, request/response types, validation DTOs, and generated transport types under transport/.`,
419
+ });
420
+ }
402
421
  }
403
-
404
422
  function checkFeatureTransportEdges(config, context, sourceFiles, featureRoots, fileName, violations) {
405
- for (const edge of context.edges.get(fileName) ?? []) {
406
- const reexported = reexportedTransportEvidence(context.ts, context, sourceFiles, edge);
407
- if (reexported) violations.push(finding(config, edge, 'BE_APPLICATION_TRANSPORT_FRAMEWORK', `Feature application code imports protocol surface ${reexported.evidence.detail} through an internal re-export. Keep protocol decorators and types under transport/.`, reexported.chain));
408
- const transportChain = reachableViolation(context.edges, edge, target => insideFeatureLayer(featureRoots, target, 'transport'));
409
- if (transportChain) violations.push(finding(config, edge, 'BE_APPLICATION_IMPORTS_TRANSPORT', 'Feature application code cannot depend on transport adapters or DTOs, including through a type import or barrel.', transportChain));
410
- }
411
- }
412
-
423
+ for (const edge of context.edges.get(fileName) ?? []) {
424
+ const reexported = reexportedTransportEvidence(context.ts, context, sourceFiles, edge);
425
+ if (reexported)
426
+ violations.push(finding(config, edge, 'BE_APPLICATION_TRANSPORT_FRAMEWORK', `Feature application code imports protocol surface ${reexported.evidence.detail} through an internal re-export. Keep protocol decorators and types under transport/.`, reexported.chain));
427
+ const transportChain = reachableViolation(context.edges, edge, target => insideFeatureLayer(featureRoots, target, 'transport'));
428
+ if (transportChain)
429
+ violations.push(finding(config, edge, 'BE_APPLICATION_IMPORTS_TRANSPORT', 'Feature application code cannot depend on transport adapters or DTOs, including through a type import or barrel.', transportChain));
430
+ }
431
+ }
413
432
  function checkBackendSource(config, context, sourceFiles, roots, sourceFile, violations) {
414
- const { moduleRoots, featureRoots, nonAppRoots } = roots;
415
- const fileName = path.resolve(sourceFile.fileName);
416
- const fromModules = insideAny(moduleRoots, fileName);
417
- const fromFeatures = insideAny(featureRoots, fileName);
418
- const fromApplication = fromFeatures && insideFeatureLayer(featureRoots, fileName, 'application');
419
- const app = !fromModules && !fromFeatures ? appSource(config, fileName, nonAppRoots) : null;
420
- if (app) {
421
- checkApplicationComposition(config, context.ts, sourceFile, fileName, app, violations);
422
- checkApplicationEnvEdges(config, context, fileName, violations);
423
- checkApplicationEnvironment(config, context, sourceFile, fileName, violations);
424
- }
425
- if (!fromModules && !fromFeatures) return;
426
- if (fromApplication) checkApplicationTransport(config, context, sourceFile, fileName, violations);
427
- if (fromApplication) checkFeatureTransportEdges(config, context, sourceFiles, featureRoots, fileName, violations);
428
- }
429
-
433
+ const { moduleRoots, featureRoots, nonAppRoots } = roots;
434
+ const fileName = path.resolve(sourceFile.fileName);
435
+ const fromModules = insideAny(moduleRoots, fileName);
436
+ const fromFeatures = insideAny(featureRoots, fileName);
437
+ const fromApplication = fromFeatures && insideFeatureLayer(featureRoots, fileName, 'application');
438
+ const app = !fromModules && !fromFeatures ? appSource(config, fileName, nonAppRoots) : null;
439
+ if (app) {
440
+ checkApplicationComposition(config, context.ts, sourceFile, fileName, app, violations);
441
+ checkApplicationEnvEdges(config, context, fileName, violations);
442
+ checkApplicationEnvironment(config, context, sourceFile, fileName, violations);
443
+ }
444
+ if (!fromModules && !fromFeatures)
445
+ return;
446
+ if (fromApplication)
447
+ checkApplicationTransport(config, context, sourceFile, fileName, violations);
448
+ if (fromApplication)
449
+ checkFeatureTransportEdges(config, context, sourceFiles, featureRoots, fileName, violations);
450
+ }
430
451
  /** Enforce backend direction and keep executable apps as measurable composition roots. */
431
452
  export function checkBackend(config, context) {
432
- const violations = [];
433
- const moduleRoots = roots(config.root, config.backend.modules);
434
- const featureRoots = roots(config.root, config.backend.features);
435
- const sourceRoots = { moduleRoots, featureRoots, nonAppRoots: [...moduleRoots, ...featureRoots] };
436
- const sourceFiles = new Map(context.files.map(file => [path.resolve(file.fileName), file]));
437
- for (const sourceFile of context.files) {
438
- checkBackendSource(config, context, sourceFiles, sourceRoots, sourceFile, violations);
439
- }
440
- return violations;
453
+ const violations = [];
454
+ const moduleRoots = roots(config.root, config.backend.modules);
455
+ const featureRoots = roots(config.root, config.backend.features);
456
+ const sourceRoots = { moduleRoots, featureRoots, nonAppRoots: [...moduleRoots, ...featureRoots] };
457
+ const sourceFiles = new Map(context.files.map((file) => [path.resolve(file.fileName), file]));
458
+ for (const sourceFile of context.files) {
459
+ checkBackendSource(config, context, sourceFiles, sourceRoots, sourceFile, violations);
460
+ }
461
+ return violations;
441
462
  }