@starci/eslint-canon-be 3.8.20 → 3.9.2
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 +16 -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
|
@@ -1,338 +1,372 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import { canonical } from './config.mjs';
|
|
3
3
|
import { referencedExports, relativePath, unwrapExpression } from './typescript.mjs';
|
|
4
|
-
import { commonJsRequireReasons, decoratorCallee, moduleExportsOf, mutableDecoratorKind, programSourcesOf, selectedNode, valueSymbol } from './ast-walks.mjs';
|
|
4
|
+
import { commonJsRequireReasons, decoratorCallee, moduleExportsOf, mutableDecoratorKind, nodeDecorators, programSourcesOf, selectedNode, valueSymbol } from './ast-walks.mjs';
|
|
5
5
|
import { sourceLocation } from '../../lib/ts-ast.mjs';
|
|
6
6
|
import { byCodeUnit } from '../../lib/list.mjs';
|
|
7
|
-
|
|
8
7
|
const REGISTRATION_RULE_IDS = ['BE_MODULE_HANDLER_REGISTRATION', 'BE_MODULE_PROVIDER_REREGISTRATION'];
|
|
9
8
|
const FRAMEWORK = new Map([
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
['Module', '@nestjs/common'],
|
|
10
|
+
['CommandHandler', '@nestjs/cqrs'],
|
|
11
|
+
['QueryHandler', '@nestjs/cqrs'],
|
|
13
12
|
]);
|
|
14
|
-
|
|
15
13
|
function frameworkDecorator(ts, checker, decorator, targets) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
const selected = selectedNode(ts, decoratorCallee(ts, decorator));
|
|
15
|
+
if (!selected)
|
|
16
|
+
return null;
|
|
17
|
+
const symbol = valueSymbol(ts, checker, selected);
|
|
18
|
+
for (const [name, target] of targets)
|
|
19
|
+
if (symbol === target)
|
|
20
|
+
return name;
|
|
21
|
+
return null;
|
|
21
22
|
}
|
|
22
|
-
|
|
23
23
|
/* This module's framework map keys decorator names, not symbols - invert it (first name wins, as the old
|
|
24
24
|
* `for...of` scan did) for the shared symbol-keyed lookup. */
|
|
25
25
|
const mutableFrameworkAlias = (ts, checker, decorator, targets) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
const bySymbol = new Map();
|
|
27
|
+
for (const [name, symbol] of targets)
|
|
28
|
+
if (!bySymbol.has(symbol))
|
|
29
|
+
bySymbol.set(symbol, name);
|
|
30
|
+
return mutableDecoratorKind(ts, checker, decorator, bySymbol);
|
|
29
31
|
};
|
|
30
|
-
|
|
31
32
|
function collectFrameworkStatement(config, context, checker, sourceFile, statement, targets, reasons) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
33
|
+
const bound = moduleExportsOf(context.ts, checker, statement);
|
|
34
|
+
if (!bound || ![...FRAMEWORK.values()].includes(bound.specifier))
|
|
35
|
+
return;
|
|
36
|
+
const expected = new Set([...FRAMEWORK].filter(([, packageName]) => packageName === bound.specifier).map(([name]) => name));
|
|
37
|
+
const selected = referencedExports(context.ts, statement, expected);
|
|
38
|
+
if (!selected.length)
|
|
39
|
+
return;
|
|
40
|
+
if (!bound.symbol) {
|
|
41
|
+
reasons.push(`${relativePath(config.root, sourceFile.fileName)} cannot resolve ${bound.specifier}`);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
for (const name of selected) {
|
|
45
|
+
const target = bound.exports.get(name);
|
|
46
|
+
if (!target) {
|
|
47
|
+
reasons.push(`${relativePath(config.root, sourceFile.fileName)} cannot resolve ${name} from ${bound.specifier}`);
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
targets.set(name, target);
|
|
46
51
|
}
|
|
47
|
-
targets.set(name, target);
|
|
48
|
-
}
|
|
49
52
|
}
|
|
50
|
-
|
|
51
53
|
function frameworkTargets(config, context, checker, localFiles) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
for (const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
const targets = new Map();
|
|
55
|
+
const reasons = [];
|
|
56
|
+
const files = programSourcesOf(context, checker, localFiles);
|
|
57
|
+
if (!files)
|
|
58
|
+
return { targets, reasons: ['a TypeScript program checker could not be associated with its source'] };
|
|
59
|
+
for (const sourceFile of files) {
|
|
60
|
+
for (const statement of sourceFile.statements)
|
|
61
|
+
collectFrameworkStatement(config, context, checker, sourceFile, statement, targets, reasons);
|
|
62
|
+
commonJsRequireReasons(context.ts, checker, sourceFile, (specifier) => [...FRAMEWORK.values()].includes(specifier), reasons, relativePath(config.root, sourceFile.fileName), 'whose decorator identity cannot be proved', 'Nest framework binding');
|
|
63
|
+
}
|
|
64
|
+
return { targets, reasons };
|
|
62
65
|
}
|
|
63
|
-
|
|
64
66
|
function classToken(ts, checker, node, localFiles) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
const symbol = valueSymbol(ts, checker, node);
|
|
68
|
+
const declarations = (symbol?.getDeclarations?.() ?? []).filter((declaration) => ts.isClassDeclaration(declaration)) ?? [];
|
|
69
|
+
const local = declarations.filter(declaration => localFiles.has(canonical(declaration.getSourceFile().fileName)));
|
|
70
|
+
const keys = [...new Set(local.map(declaration => `${canonical(declaration.getSourceFile().fileName)}#${declaration.getStart(declaration.getSourceFile())}`))];
|
|
71
|
+
return { key: keys.length === 1 ? keys[0] ?? null : null, external: declarations.length > 0 && local.length === 0 };
|
|
70
72
|
}
|
|
71
|
-
|
|
72
73
|
function localClassKey(ts, checker, node, localFiles) {
|
|
73
|
-
|
|
74
|
+
return classToken(ts, checker, node, localFiles).key;
|
|
74
75
|
}
|
|
75
|
-
|
|
76
76
|
function propertyName(ts, property) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
if (!property.name)
|
|
78
|
+
return null;
|
|
79
|
+
if (ts.isIdentifier(property.name) || ts.isStringLiteralLike(property.name))
|
|
80
|
+
return property.name.text;
|
|
81
|
+
return null;
|
|
80
82
|
}
|
|
81
|
-
|
|
82
83
|
function inspectTokenElement(ts, checker, element, localFiles, field, tokens) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
84
|
+
if (ts.isSpreadElement(element))
|
|
85
|
+
return true;
|
|
86
|
+
let key;
|
|
87
|
+
let node = element;
|
|
88
|
+
if (ts.isObjectLiteralExpression(element)) {
|
|
89
|
+
if (element.properties.some(property => ts.isSpreadAssignment(property)))
|
|
90
|
+
return true;
|
|
91
|
+
const providers = element.properties.filter(property => propertyName(ts, property) === 'provide');
|
|
92
|
+
const [provider] = providers;
|
|
93
|
+
if (providers.length !== 1 || !provider || !ts.isPropertyAssignment(provider))
|
|
94
|
+
return true;
|
|
95
|
+
node = provider.initializer;
|
|
96
|
+
key = localClassKey(ts, checker, node, localFiles);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
const token = classToken(ts, checker, element, localFiles);
|
|
100
|
+
key = token.key;
|
|
101
|
+
if (!key)
|
|
102
|
+
return field === 'providers' && !token.external;
|
|
103
|
+
}
|
|
104
|
+
if (key) {
|
|
105
|
+
let nodes = tokens.get(key);
|
|
106
|
+
if (!nodes) {
|
|
107
|
+
nodes = [];
|
|
108
|
+
tokens.set(key, nodes);
|
|
109
|
+
}
|
|
110
|
+
nodes.push(node);
|
|
111
|
+
}
|
|
112
|
+
return false;
|
|
102
113
|
}
|
|
103
|
-
|
|
104
114
|
function tokenEntries(ts, checker, initializer, localFiles, field) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
115
|
+
const array = unwrapExpression(ts, initializer);
|
|
116
|
+
if (!ts.isArrayLiteralExpression(array))
|
|
117
|
+
return { tokens: new Map(), unknown: true };
|
|
118
|
+
const tokens = new Map();
|
|
119
|
+
let unknown = false;
|
|
120
|
+
for (const element of array.elements) {
|
|
121
|
+
if (inspectTokenElement(ts, checker, element, localFiles, field, tokens))
|
|
122
|
+
unknown = true;
|
|
123
|
+
}
|
|
124
|
+
return { tokens, unknown };
|
|
113
125
|
}
|
|
114
|
-
|
|
115
126
|
function metadataTokens(ts, checker, metadata, field, localFiles) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
127
|
+
const object = unwrapExpression(ts, metadata);
|
|
128
|
+
if (!ts.isObjectLiteralExpression(object))
|
|
129
|
+
return { tokens: new Map(), unknown: true };
|
|
130
|
+
if (object.properties.some(property => ts.isSpreadAssignment(property)))
|
|
131
|
+
return { tokens: new Map(), unknown: true };
|
|
132
|
+
const matches = object.properties.filter(property => propertyName(ts, property) === field);
|
|
133
|
+
if (!matches.length)
|
|
134
|
+
return { tokens: new Map(), unknown: false };
|
|
135
|
+
const [match] = matches;
|
|
136
|
+
if (matches.length !== 1 || !match || !ts.isPropertyAssignment(match))
|
|
137
|
+
return { tokens: new Map(), unknown: true };
|
|
138
|
+
return tokenEntries(ts, checker, match.initializer, localFiles, field);
|
|
123
139
|
}
|
|
124
|
-
|
|
125
140
|
function moduleRecord(config, context, sourceFile, declaration, decorator, checker, localFiles) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
+
const call = decorator.expression;
|
|
142
|
+
const location = declaration.name ?? declaration;
|
|
143
|
+
const base = {
|
|
144
|
+
key: declaration.name ? localClassKey(context.ts, checker, declaration.name, localFiles) : null,
|
|
145
|
+
name: declaration.name?.text ?? '(anonymous)',
|
|
146
|
+
path: relativePath(config.root, sourceFile.fileName),
|
|
147
|
+
...sourceLocation(sourceFile, location),
|
|
148
|
+
providers: new Map(),
|
|
149
|
+
exports: new Map(),
|
|
150
|
+
unknown: false,
|
|
151
|
+
};
|
|
152
|
+
const [metadata] = context.ts.isCallExpression(call) ? call.arguments : [];
|
|
153
|
+
if (!context.ts.isCallExpression(call) || call.arguments.length !== 1 || !metadata || !base.key)
|
|
154
|
+
return { ...base, unknown: true };
|
|
155
|
+
const providers = metadataTokens(context.ts, checker, metadata, 'providers', localFiles);
|
|
156
|
+
const exports = metadataTokens(context.ts, checker, metadata, 'exports', localFiles);
|
|
157
|
+
return { ...base, providers: providers.tokens, exports: exports.tokens, unknown: providers.unknown || exports.unknown };
|
|
141
158
|
}
|
|
142
|
-
|
|
143
159
|
function registrationFinding(module, node, ruleId, message, extra = {}) {
|
|
144
|
-
|
|
160
|
+
return { ruleId, path: module.path, ...sourceLocation(node.getSourceFile(), node), module: module.name, message, ...extra };
|
|
145
161
|
}
|
|
146
|
-
|
|
147
162
|
const modulesByFileOf = (config, modules) => {
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
163
|
+
const byFile = new Map();
|
|
164
|
+
for (const module of modules) {
|
|
165
|
+
const file = canonical(path.resolve(config.root, ...module.path.split('/')));
|
|
166
|
+
let list = byFile.get(file);
|
|
167
|
+
if (!list) {
|
|
168
|
+
list = [];
|
|
169
|
+
byFile.set(file, list);
|
|
170
|
+
}
|
|
171
|
+
list.push(module);
|
|
172
|
+
}
|
|
173
|
+
return byFile;
|
|
155
174
|
};
|
|
156
|
-
|
|
157
175
|
/** The modules whose file the runtime import edges reach from `rootFile`, in first-visit order; each is added to `bound`. */
|
|
158
176
|
const reachableModules = (context, byFile, rootFile, bound) => {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
177
|
+
const queue = [rootFile];
|
|
178
|
+
const seen = new Set();
|
|
179
|
+
const reachable = [];
|
|
180
|
+
for (const file of queue) {
|
|
181
|
+
if (seen.has(file))
|
|
182
|
+
continue;
|
|
183
|
+
seen.add(file);
|
|
184
|
+
for (const module of byFile.get(file) ?? []) {
|
|
185
|
+
reachable.push(module);
|
|
186
|
+
bound.add(module);
|
|
187
|
+
}
|
|
188
|
+
for (const edge of context.edges.get(file) ?? [])
|
|
189
|
+
if (edge.runtime && !seen.has(edge.to))
|
|
190
|
+
queue.push(edge.to);
|
|
168
191
|
}
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
return reachable;
|
|
192
|
+
return reachable;
|
|
172
193
|
};
|
|
173
|
-
|
|
174
194
|
/** A module belongs to an app only when its runtime source is reachable from that app's composition root. */
|
|
175
195
|
function applicationGraphs(config, context, modules) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
196
|
+
const roots = modules.filter(module => /^apps\/[^/]+\/src\/app\.module\.ts$/.test(module.path))
|
|
197
|
+
.sort((a, b) => a.path.localeCompare(b.path));
|
|
198
|
+
// Small architecture fixtures without app composition retain the original single-graph relation.
|
|
199
|
+
if (!roots.length)
|
|
200
|
+
return [modules];
|
|
201
|
+
const byFile = modulesByFileOf(config, modules);
|
|
202
|
+
const bound = new Set();
|
|
203
|
+
const graphs = roots.map(root => reachableModules(context, byFile, canonical(path.resolve(config.root, ...root.path.split('/'))), bound));
|
|
204
|
+
// A module outside every proven app graph can still contain a duplicate in its own metadata.
|
|
205
|
+
return [...graphs, ...modules.filter(module => !bound.has(module)).map(module => [module])];
|
|
185
206
|
}
|
|
186
|
-
|
|
187
207
|
function decoratorKinds(ts, checker, node, framework) {
|
|
188
|
-
|
|
189
|
-
return decorators.map(decorator => ({ decorator, kind: frameworkDecorator(ts, checker, decorator, framework.targets) }));
|
|
208
|
+
return nodeDecorators(ts, node).map(decorator => ({ decorator, kind: frameworkDecorator(ts, checker, decorator, framework.targets) }));
|
|
190
209
|
}
|
|
191
|
-
|
|
192
210
|
function recordMutableDecoratorReasons(config, ts, checker, sourceFile, kinds, framework, reasons) {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
211
|
+
for (const { decorator, kind } of kinds) {
|
|
212
|
+
const dynamic = kind ? null : mutableFrameworkAlias(ts, checker, decorator, framework.targets);
|
|
213
|
+
if (dynamic)
|
|
214
|
+
reasons.push(`${relativePath(config.root, sourceFile.fileName)} uses mutable ${dynamic} decorator identity`);
|
|
215
|
+
}
|
|
197
216
|
}
|
|
198
|
-
|
|
199
217
|
function recordModuleDecorator(site, node, kinds, found) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
218
|
+
const { config, context, sourceFile, checker, localFiles } = site;
|
|
219
|
+
const { modules, reasons } = found;
|
|
220
|
+
const moduleDecorators = kinds.filter(item => item.kind === 'Module');
|
|
221
|
+
const [moduleDecorator] = moduleDecorators;
|
|
222
|
+
if (moduleDecorators.length === 1 && moduleDecorator)
|
|
223
|
+
modules.push(moduleRecord(config, context, sourceFile, node, moduleDecorator.decorator, checker, localFiles));
|
|
224
|
+
else if (moduleDecorators.length > 1)
|
|
225
|
+
reasons.push(`${relativePath(config.root, sourceFile.fileName)} has multiple resolved @Module decorators`);
|
|
205
226
|
}
|
|
206
|
-
|
|
207
227
|
function recordHandlerDecorator(site, node, kinds, found) {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
228
|
+
const { config, context, sourceFile, checker, localFiles } = site;
|
|
229
|
+
const { handlers, reasons } = found;
|
|
230
|
+
const { ts } = context;
|
|
231
|
+
const handlerDecorators = kinds.filter((item) => item.kind === 'CommandHandler' || item.kind === 'QueryHandler');
|
|
232
|
+
const [handlerDecorator] = handlerDecorators;
|
|
233
|
+
if (handlerDecorators.length === 1 && handlerDecorator)
|
|
234
|
+
handlers.push({
|
|
235
|
+
key: node.name ? localClassKey(ts, checker, node.name, localFiles) : null,
|
|
236
|
+
name: node.name?.text ?? '(anonymous)',
|
|
237
|
+
kind: handlerDecorator.kind,
|
|
238
|
+
path: relativePath(config.root, sourceFile.fileName),
|
|
239
|
+
...sourceLocation(sourceFile, node.name ?? node),
|
|
240
|
+
});
|
|
241
|
+
else if (handlerDecorators.length > 1)
|
|
242
|
+
reasons.push(`${relativePath(config.root, sourceFile.fileName)} has multiple resolved CQRS handler decorators`);
|
|
220
243
|
}
|
|
221
|
-
|
|
222
244
|
function inspectRegistrationClass(site, node, found) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
245
|
+
const { config, context, sourceFile, checker, framework } = site;
|
|
246
|
+
const { ts } = context;
|
|
247
|
+
if (!ts.isClassDeclaration(node))
|
|
248
|
+
return;
|
|
249
|
+
const kinds = decoratorKinds(ts, checker, node, framework);
|
|
250
|
+
recordMutableDecoratorReasons(config, ts, checker, sourceFile, kinds, framework, found.reasons);
|
|
251
|
+
recordModuleDecorator(site, node, kinds, found);
|
|
252
|
+
recordHandlerDecorator(site, node, kinds, found);
|
|
230
253
|
}
|
|
231
|
-
|
|
232
254
|
function discoverRegistrations(config, context, localFiles) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
255
|
+
const modules = [];
|
|
256
|
+
const handlers = [];
|
|
257
|
+
const reasons = [];
|
|
258
|
+
const found = { modules, handlers, reasons };
|
|
259
|
+
const frameworkByChecker = new Map();
|
|
260
|
+
for (const sourceFile of context.files) {
|
|
261
|
+
const checker = context.checkerFor(sourceFile.fileName);
|
|
262
|
+
if (!checker)
|
|
263
|
+
continue;
|
|
264
|
+
let framework = frameworkByChecker.get(checker);
|
|
265
|
+
if (!framework) {
|
|
266
|
+
framework = frameworkTargets(config, context, checker, localFiles);
|
|
267
|
+
frameworkByChecker.set(checker, framework);
|
|
268
|
+
}
|
|
269
|
+
reasons.push(...framework.reasons);
|
|
270
|
+
const site = { config, context, sourceFile, checker, localFiles, framework };
|
|
271
|
+
const visit = (node) => {
|
|
272
|
+
inspectRegistrationClass(site, node, found);
|
|
273
|
+
context.ts.forEachChild(node, visit);
|
|
274
|
+
};
|
|
275
|
+
visit(sourceFile);
|
|
276
|
+
}
|
|
277
|
+
return { modules, handlers, reasons };
|
|
251
278
|
}
|
|
252
|
-
|
|
253
279
|
function providerOwnersOf(modules) {
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
280
|
+
const providerOwners = new Map();
|
|
281
|
+
for (const module of modules) {
|
|
282
|
+
for (const key of module.providers.keys()) {
|
|
283
|
+
if (!module.exports.has(key))
|
|
284
|
+
continue;
|
|
285
|
+
let owners = providerOwners.get(key);
|
|
286
|
+
if (!owners) {
|
|
287
|
+
owners = [];
|
|
288
|
+
providerOwners.set(key, owners);
|
|
289
|
+
}
|
|
290
|
+
owners.push(module);
|
|
291
|
+
}
|
|
260
292
|
}
|
|
261
|
-
|
|
262
|
-
return providerOwners;
|
|
293
|
+
return providerOwners;
|
|
263
294
|
}
|
|
264
|
-
|
|
265
295
|
const byModulePath = (a, b) => a.module.path.localeCompare(b.module.path) || a.node.getStart() - b.node.getStart();
|
|
266
|
-
|
|
267
296
|
/** The registrations of `key` in a graph that follow the first one of its owner module: the owner registers it once, every other is a duplicate. */
|
|
268
297
|
const duplicateRegistrations = (graph, key, owner) => {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
298
|
+
const registrations = graph.flatMap(module => (module.providers.get(key) ?? []).map((node) => ({ module, node })))
|
|
299
|
+
.sort(byModulePath);
|
|
300
|
+
let keptOwnerRegistration = false;
|
|
301
|
+
return registrations.filter(registration => {
|
|
302
|
+
if (registration.module !== owner || keptOwnerRegistration)
|
|
303
|
+
return true;
|
|
304
|
+
keptOwnerRegistration = true;
|
|
305
|
+
return false;
|
|
306
|
+
});
|
|
277
307
|
};
|
|
278
|
-
|
|
279
308
|
function reregistrationViolations(config, context, modules, providerOwners) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
309
|
+
const violations = [];
|
|
310
|
+
const reportedRegistrations = new Set();
|
|
311
|
+
const report = (key, owner, duplicate) => {
|
|
312
|
+
const identity = `${key}\0${duplicate.module.path}\0${duplicate.node.getStart()}`;
|
|
313
|
+
if (reportedRegistrations.has(identity))
|
|
314
|
+
return;
|
|
315
|
+
reportedRegistrations.add(identity);
|
|
316
|
+
violations.push(registrationFinding(duplicate.module, duplicate.node, 'BE_MODULE_PROVIDER_REREGISTRATION', `Class-token provider exported by ${owner.name} is registered again by ${duplicate.module.name} in one application graph; import the owning module and preserve one class-token registration.`, { ownerModule: owner.name, ownerPath: owner.path }));
|
|
317
|
+
};
|
|
318
|
+
for (const graph of applicationGraphs(config, context, modules))
|
|
319
|
+
for (const [key] of providerOwners) {
|
|
320
|
+
const owners = graph.filter(module => module.providers.has(key) && module.exports.has(key))
|
|
321
|
+
.sort((a, b) => a.path.localeCompare(b.path));
|
|
322
|
+
const [owner] = owners;
|
|
323
|
+
if (!owner)
|
|
324
|
+
continue;
|
|
325
|
+
for (const duplicate of duplicateRegistrations(graph, key, owner))
|
|
326
|
+
report(key, owner, duplicate);
|
|
327
|
+
}
|
|
328
|
+
return violations;
|
|
298
329
|
}
|
|
299
|
-
|
|
300
330
|
function handlerRegistrationViolations(modules, handlers, selected) {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
331
|
+
const violations = [];
|
|
332
|
+
for (const handler of handlers.filter(item => item.key && selected.handlerDecorators.includes(item.kind))) {
|
|
333
|
+
const registrations = modules.flatMap(module => (module.providers.get(handler.key ?? '') ?? []).map((node) => ({ module, node })));
|
|
334
|
+
if (registrations.length !== 1)
|
|
335
|
+
violations.push({
|
|
336
|
+
ruleId: 'BE_MODULE_HANDLER_REGISTRATION', path: handler.path, line: handler.line, column: handler.column,
|
|
337
|
+
handler: handler.name, decorator: handler.kind,
|
|
338
|
+
message: registrations.length === 0
|
|
339
|
+
? `${handler.kind} ${handler.name} is not registered as a direct class-token provider in a resolved Nest module.`
|
|
340
|
+
: `${handler.kind} ${handler.name} has multiple direct module registrations; one owner must preserve its handler identity.`,
|
|
341
|
+
modules: registrations.map(registration => ({ name: registration.module.name, path: registration.module.path,
|
|
342
|
+
...sourceLocation(registration.node.getSourceFile(), registration.node) })),
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
return violations;
|
|
315
346
|
}
|
|
316
|
-
|
|
317
347
|
/** Prove only static exported class-token identity and selected CQRS handler registration. */
|
|
318
348
|
export function checkModuleRegistration(config, context) {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
349
|
+
const selected = config.backend.moduleRegistration;
|
|
350
|
+
if (!selected)
|
|
351
|
+
return { violations: [], coverage: { status: 'unavailable', reason: 'hfs.json does not select Nest module-registration identity checks' } };
|
|
352
|
+
const localFiles = new Set(context.files.map(file => canonical(file.fileName)));
|
|
353
|
+
const { modules, handlers, reasons } = discoverRegistrations(config, context, localFiles);
|
|
354
|
+
for (const module of modules)
|
|
355
|
+
if (module.unknown)
|
|
356
|
+
reasons.push(`${module.path} has dynamic or unresolvable @Module providers/exports metadata`);
|
|
357
|
+
for (const handler of handlers) {
|
|
358
|
+
if (!handler.key)
|
|
359
|
+
reasons.push(`${handler.path} handler class identity is not resolvable`);
|
|
360
|
+
if (!selected.handlerDecorators.includes(handler.kind))
|
|
361
|
+
reasons.push(`${handler.path} uses unselected ${handler.kind}`);
|
|
362
|
+
}
|
|
363
|
+
const providerOwners = providerOwnersOf(modules);
|
|
364
|
+
const violations = reregistrationViolations(config, context, modules, providerOwners);
|
|
365
|
+
violations.push(...handlerRegistrationViolations(modules, handlers, selected));
|
|
366
|
+
const coverage = reasons.length
|
|
367
|
+
? { status: 'unavailable', reason: 'one or more Nest module-registration relations are not statically provable', details: [...new Set(reasons)].sort(byCodeUnit) }
|
|
368
|
+
: { status: 'checked', modules: modules.length, exportedClassTokenProviders: providerOwners.size, handlers: handlers.length,
|
|
369
|
+
selectedHandlerDecorators: selected.handlerDecorators };
|
|
370
|
+
return { violations, coverage };
|
|
336
371
|
}
|
|
337
|
-
|
|
338
372
|
export { REGISTRATION_RULE_IDS };
|