@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.
- package/CHANGELOG.md +8 -0
- package/package.json +1 -1
- package/runtime/bundle.json +192 -0
- package/runtime/engine/by-code-unit.mjs +6 -6
- package/runtime/engine/model-config.mjs +98 -76
- package/runtime/engine/orca-config.mjs +22 -17
- package/runtime/engine/release-config.mjs +22 -18
- package/runtime/engine/removed-vocabulary.mjs +21 -20
- package/runtime/engine/resources-config.mjs +42 -35
- package/runtime/engine/runtime-root.mjs +11 -13
- package/runtime/engine/secrets.mjs +170 -102
- package/runtime/engine/sonar-config.mjs +16 -13
- package/runtime/engine/temp-root.mjs +3 -9
- package/runtime/knowledge/hfs/canon-pins.yaml +10 -10
- package/runtime/knowledge/hfs/rules.yaml +6 -6
- package/runtime/knowledge/hfs/slots.yaml +2 -2
- package/runtime/knowledge/sonar-gate.yaml +1 -1
- package/runtime/packages/hfs/templates/app/package-scripts/package.json +1 -1
- package/runtime/scripts/api/git/cat-file.mjs +0 -1
- package/runtime/scripts/api/git/config-get.mjs +1 -2
- package/runtime/scripts/api/git/diff.mjs +0 -1
- package/runtime/scripts/api/git/lib.mjs +32 -32
- package/runtime/scripts/api/git/ls-files.mjs +0 -1
- package/runtime/scripts/api/git/ls-tree.mjs +0 -1
- package/runtime/scripts/api/git/merge-base.mjs +2 -3
- package/runtime/scripts/api/git/remote.mjs +0 -1
- package/runtime/scripts/api/git/rev-parse-query.mjs +0 -1
- package/runtime/scripts/api/git/show.mjs +0 -1
- package/runtime/scripts/hfs/allows.mjs +37 -38
- package/runtime/scripts/hfs/architecture/ast-walks.mjs +180 -163
- package/runtime/scripts/hfs/architecture/automatic-gates.mjs +80 -73
- package/runtime/scripts/hfs/architecture/backend-app-files.mjs +88 -77
- package/runtime/scripts/hfs/architecture/backend.mjs +378 -357
- package/runtime/scripts/hfs/architecture/background-unowned.mjs +201 -187
- package/runtime/scripts/hfs/architecture/canon-clones.mjs +260 -209
- package/runtime/scripts/hfs/architecture/canon-jsx-clones.mjs +149 -116
- package/runtime/scripts/hfs/architecture/client-reaches-server.mjs +72 -68
- package/runtime/scripts/hfs/architecture/clones.mjs +212 -217
- package/runtime/scripts/hfs/architecture/config-unread.mjs +7 -9
- package/runtime/scripts/hfs/architecture/config.mjs +302 -268
- package/runtime/scripts/hfs/architecture/connection-map.mjs +258 -225
- package/runtime/scripts/hfs/architecture/constructor-deps.mjs +80 -71
- package/runtime/scripts/hfs/architecture/context-coupling.mjs +82 -77
- package/runtime/scripts/hfs/architecture/context-map.mjs +267 -234
- package/runtime/scripts/hfs/architecture/context-owner.mjs +73 -61
- package/runtime/scripts/hfs/architecture/context-platform-tables.mjs +47 -43
- package/runtime/scripts/hfs/architecture/context-transaction.mjs +54 -52
- package/runtime/scripts/hfs/architecture/contract-fixture-guard.mjs +113 -104
- package/runtime/scripts/hfs/architecture/contracts-readonly.mjs +288 -270
- package/runtime/scripts/hfs/architecture/contracts.mjs +408 -393
- package/runtime/scripts/hfs/architecture/cross-app-duplicate.mjs +50 -51
- package/runtime/scripts/hfs/architecture/dead-exports-bindings.mjs +143 -119
- package/runtime/scripts/hfs/architecture/dead-exports.mjs +286 -228
- package/runtime/scripts/hfs/architecture/default-deny.mjs +129 -110
- package/runtime/scripts/hfs/architecture/doc-language.mjs +24 -19
- package/runtime/scripts/hfs/architecture/entity-registry.mjs +20 -22
- package/runtime/scripts/hfs/architecture/entrypoint.mjs +47 -45
- package/runtime/scripts/hfs/architecture/error-codes.mjs +37 -35
- package/runtime/scripts/hfs/architecture/error-masked.mjs +55 -59
- package/runtime/scripts/hfs/architecture/fe-slot-allows.mjs +24 -23
- package/runtime/scripts/hfs/architecture/feature-shape.mjs +40 -38
- package/runtime/scripts/hfs/architecture/framework-pinned.mjs +21 -21
- package/runtime/scripts/hfs/architecture/frontend-block-render.mjs +106 -98
- package/runtime/scripts/hfs/architecture/frontend-grammar.mjs +153 -150
- package/runtime/scripts/hfs/architecture/frontend-routing.mjs +161 -149
- package/runtime/scripts/hfs/architecture/frontend-world-render.mjs +343 -305
- package/runtime/scripts/hfs/architecture/frontend-world.mjs +340 -294
- package/runtime/scripts/hfs/architecture/frontend.mjs +174 -184
- package/runtime/scripts/hfs/architecture/function-spec-providers.mjs +124 -106
- package/runtime/scripts/hfs/architecture/hfs-graph.mjs +52 -48
- package/runtime/scripts/hfs/architecture/hooks-are-hooks.mjs +81 -71
- package/runtime/scripts/hfs/architecture/i18n-keys.mjs +155 -141
- package/runtime/scripts/hfs/architecture/identity.mjs +141 -125
- package/runtime/scripts/hfs/architecture/index.mjs +272 -272
- package/runtime/scripts/hfs/architecture/injection-token-exported.mjs +45 -43
- package/runtime/scripts/hfs/architecture/jwt-ast.mjs +195 -176
- package/runtime/scripts/hfs/architecture/machine-ast.mjs +163 -155
- package/runtime/scripts/hfs/architecture/managed-scripts.mjs +19 -20
- package/runtime/scripts/hfs/architecture/module-per-transport.mjs +177 -172
- package/runtime/scripts/hfs/architecture/next-data-contract.mjs +100 -78
- package/runtime/scripts/hfs/architecture/next-data-inference.mjs +170 -154
- package/runtime/scripts/hfs/architecture/next-data-key.mjs +311 -275
- package/runtime/scripts/hfs/architecture/next-data-symbols.mjs +17 -17
- package/runtime/scripts/hfs/architecture/next-data.mjs +351 -334
- package/runtime/scripts/hfs/architecture/operation-contract-roots.mjs +39 -37
- package/runtime/scripts/hfs/architecture/owners.mjs +97 -98
- package/runtime/scripts/hfs/architecture/package-shape.mjs +56 -55
- package/runtime/scripts/hfs/architecture/presentation.mjs +138 -130
- package/runtime/scripts/hfs/architecture/reachability.mjs +258 -241
- package/runtime/scripts/hfs/architecture/register-once.mjs +152 -139
- package/runtime/scripts/hfs/architecture/registration.mjs +301 -267
- package/runtime/scripts/hfs/architecture/required-files.mjs +172 -167
- package/runtime/scripts/hfs/architecture/route-files-thin.mjs +85 -77
- package/runtime/scripts/hfs/architecture/schema-owner.mjs +206 -181
- package/runtime/scripts/hfs/architecture/server-action.mjs +48 -48
- package/runtime/scripts/hfs/architecture/side-boundary.mjs +2 -5
- package/runtime/scripts/hfs/architecture/source-names-shape.mjs +261 -259
- package/runtime/scripts/hfs/architecture/source-names.mjs +304 -278
- package/runtime/scripts/hfs/architecture/sql-keys.mjs +277 -194
- package/runtime/scripts/hfs/architecture/sql-owner.mjs +236 -194
- package/runtime/scripts/hfs/architecture/sql-returning.mjs +46 -45
- package/runtime/scripts/hfs/architecture/sql-token-forms.mjs +86 -74
- package/runtime/scripts/hfs/architecture/sql-tokens.mjs +456 -341
- package/runtime/scripts/hfs/architecture/staged-consumers.mjs +35 -30
- package/runtime/scripts/hfs/architecture/surface.mjs +64 -74
- package/runtime/scripts/hfs/architecture/symbols.mjs +209 -216
- package/runtime/scripts/hfs/architecture/test-world-files.mjs +165 -155
- package/runtime/scripts/hfs/architecture/tiers.mjs +161 -154
- package/runtime/scripts/hfs/architecture/transport-owner.mjs +155 -149
- package/runtime/scripts/hfs/architecture/type-context.mjs +255 -250
- package/runtime/scripts/hfs/architecture/typescript.mjs +358 -318
- package/runtime/scripts/hfs/architecture/unit-spec-providers.mjs +110 -92
- package/runtime/scripts/hfs/declaration-shape.mjs +140 -103
- package/runtime/scripts/hfs/declaration-slots.mjs +64 -61
- package/runtime/scripts/hfs/edition-slots.mjs +43 -40
- package/runtime/scripts/hfs/linear-text.mjs +20 -20
- package/runtime/scripts/hfs/param-names.mjs +6 -11
- package/runtime/scripts/hfs/path-findings.mjs +120 -100
- package/runtime/scripts/hfs/repo-identity.mjs +55 -42
- package/runtime/scripts/hfs/rule-catalog.mjs +353 -257
- package/runtime/scripts/hfs/rule-params-shape.mjs +60 -47
- package/runtime/scripts/hfs/rules/database-migrations.mjs +428 -388
- package/runtime/scripts/hfs/rules/fe-no-tests.mjs +37 -36
- package/runtime/scripts/hfs/rules/read.mjs +19 -15
- package/runtime/scripts/hfs/rules/secrets.mjs +1 -1
- package/runtime/scripts/hfs/rules/spec-placement.mjs +12 -13
- package/runtime/scripts/hfs/slot-app-view.mjs +69 -74
- package/runtime/scripts/hfs/slot-classify.mjs +42 -38
- package/runtime/scripts/hfs/slot-errors.mjs +8 -7
- package/runtime/scripts/hfs/slot-imports.mjs +70 -63
- package/runtime/scripts/hfs/slot-manifest-shape.mjs +74 -52
- package/runtime/scripts/hfs/slot-match.mjs +122 -111
- package/runtime/scripts/hfs/slot-path.mjs +0 -2
- package/runtime/scripts/hfs/slot-required.mjs +65 -59
- package/runtime/scripts/hfs/slot-semantic-problems.mjs +138 -112
- package/runtime/scripts/hfs/slot-side-problems.mjs +23 -19
- package/runtime/scripts/hfs/slots.mjs +175 -152
- package/runtime/scripts/hfs/test-world-slot.mjs +0 -1
- package/runtime/scripts/hfs/trailing-slashes.mjs +4 -4
- package/runtime/scripts/hfs/typescript-programs.mjs +66 -69
- package/runtime/scripts/hfs/view.mjs +38 -40
- package/runtime/scripts/lib/dockerfile.mjs +131 -114
- package/runtime/scripts/lib/env.mjs +3 -6
- package/runtime/scripts/lib/event-contract.mjs +73 -78
- package/runtime/scripts/lib/git.mjs +15 -16
- package/runtime/scripts/lib/glob.mjs +23 -14
- package/runtime/scripts/lib/grammar-lint.mjs +33 -37
- package/runtime/scripts/lib/i18n.mjs +32 -35
- package/runtime/scripts/lib/in-order.mjs +57 -38
- package/runtime/scripts/lib/json-clone.mjs +45 -36
- package/runtime/scripts/lib/json.mjs +26 -14
- package/runtime/scripts/lib/language.mjs +133 -129
- package/runtime/scripts/lib/list.mjs +9 -14
- package/runtime/scripts/lib/mutation-fence.mjs +10 -5
- package/runtime/scripts/lib/path-key.mjs +53 -38
- package/runtime/scripts/lib/read-text.mjs +30 -17
- package/runtime/scripts/lib/regex.mjs +1 -2
- package/runtime/scripts/lib/same-text.mjs +0 -1
- package/runtime/scripts/lib/sops-envelope.mjs +148 -120
- package/runtime/scripts/lib/stack-services.mjs +128 -129
- package/runtime/scripts/lib/ts-analysis.mjs +28 -26
- package/runtime/scripts/lib/ts-ast.mjs +36 -42
- package/runtime/scripts/lib/walk.mjs +33 -27
- 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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
23
|
+
return path.resolve(root, ...relative.split('/'));
|
|
26
24
|
}
|
|
27
|
-
|
|
28
25
|
function roots(root, relatives) {
|
|
29
|
-
|
|
26
|
+
return relatives.map(relative => absolute(root, relative));
|
|
30
27
|
}
|
|
31
|
-
|
|
32
28
|
function insideAny(candidates, fileName) {
|
|
33
|
-
|
|
29
|
+
return candidates.some(root => isInside(root, fileName));
|
|
34
30
|
}
|
|
35
|
-
|
|
36
31
|
function insideFeatureLayer(featureRoots, fileName, layer) {
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
if (
|
|
200
|
-
|
|
201
|
-
}
|
|
202
|
-
|
|
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
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
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
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
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
|
-
|
|
288
|
-
|
|
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
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
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
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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
|
-
|
|
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
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
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
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
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
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
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
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
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
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
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
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
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
|
}
|