@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
|
@@ -3,7 +3,6 @@ import { isComposeGroup, machineKit } from './machine-ast.mjs';
|
|
|
3
3
|
import { callName } from './jwt-ast.mjs';
|
|
4
4
|
import { isTestWorldSlot } from '../test-world-slot.mjs';
|
|
5
5
|
import { byCodeUnit } from '../../lib/list.mjs';
|
|
6
|
-
|
|
7
6
|
/**
|
|
8
7
|
* R45 `register-once` (BE_MODULE_SHAPE), the module graph read from the app roots (owner rule of 2026-09-30, the
|
|
9
8
|
* reference's `CodingModule imports DeviceModule` shape). Each capability has one representative module: the only module
|
|
@@ -20,180 +19,194 @@ import { byCodeUnit } from '../../lib/list.mjs';
|
|
|
20
19
|
* - `isGlobal: true` appears only in an app root.
|
|
21
20
|
*/
|
|
22
21
|
export const REGISTER_ONCE_RULE_IDS = ['BE_MODULE_SHAPE'];
|
|
23
|
-
|
|
24
22
|
const RULE = 'BE_MODULE_SHAPE';
|
|
25
23
|
const CAPABILITY_TIERS = new Set(['domain', 'platform', 'integrations']);
|
|
26
|
-
|
|
24
|
+
const isRegisterCall = (ts, node) => callName(ts, node) === 'register';
|
|
27
25
|
function moduleDeclarations(graph, kit, ts) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
26
|
+
const modules = new Map(); // declaration -> {name, file, capability}
|
|
27
|
+
for (const file of graph.files.values()) {
|
|
28
|
+
const checker = kit.checkerOf(file.sourceFile);
|
|
29
|
+
for (const statement of file.sourceFile.statements) {
|
|
30
|
+
if (!ts.isClassDeclaration(statement) || !statement.name)
|
|
31
|
+
continue;
|
|
32
|
+
const decorators = kit.decorators(statement);
|
|
33
|
+
const isModule = decorators.some(decorator => {
|
|
34
|
+
const call = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression;
|
|
35
|
+
const binding = kit.importBinding(checker, call);
|
|
36
|
+
return binding?.module === '@nestjs/common' && binding.name === 'Module';
|
|
37
|
+
});
|
|
38
|
+
if (isModule)
|
|
39
|
+
modules.set(statement, { name: statement.name.text, file, capability: CAPABILITY_TIERS.has(file.tier ?? '') });
|
|
40
|
+
}
|
|
39
41
|
}
|
|
40
|
-
|
|
41
|
-
return modules;
|
|
42
|
+
return modules;
|
|
42
43
|
}
|
|
43
|
-
|
|
44
44
|
function targetOf(kit, modules, checker, node) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
const declarations = kit.declarationsOf(checker, node);
|
|
46
|
+
for (const declaration of declarations) {
|
|
47
|
+
const info = modules.get(declaration);
|
|
48
|
+
if (info)
|
|
49
|
+
return { declaration, ...info };
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
49
52
|
}
|
|
50
|
-
|
|
51
53
|
function enclosingModule(ts, modules, node) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
for (let current = node.parent; current; current = current.parent) {
|
|
55
|
+
if (ts.isClassDeclaration(current) && modules.has(current))
|
|
56
|
+
return current;
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
56
59
|
}
|
|
57
|
-
|
|
58
60
|
/** Records the reference an element of an imports list, or a register call, makes to a module. */
|
|
59
61
|
function noteReference(scan, element, viaImports) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
const { ts, kit, modules, checker, file, seen, references, isAppRoot } = scan;
|
|
63
|
+
if (seen.has(element))
|
|
64
|
+
return;
|
|
65
|
+
const call = isRegisterCall(ts, element);
|
|
66
|
+
if (ts.isCallExpression(element) && !call)
|
|
67
|
+
return;
|
|
68
|
+
const target = targetOf(kit, modules, checker, call ? element.expression.expression : element);
|
|
69
|
+
if (!target)
|
|
70
|
+
return;
|
|
71
|
+
seen.add(element);
|
|
72
|
+
const owner = enclosingModule(ts, modules, element);
|
|
73
|
+
references.push({ file, node: element, target, register: call, viaImports, importer: owner ?? file.rel, importerOwner: file.owner?.root ?? null,
|
|
74
|
+
options: call ? element.arguments[0] ?? null : null, root: isAppRoot(file) });
|
|
70
75
|
}
|
|
71
|
-
|
|
72
76
|
const isImportsList = (scan, node) => scan.ts.isPropertyAssignment(node) && scan.kit.propertyNameText(node.name) === 'imports' && scan.ts.isArrayLiteralExpression(node.initializer);
|
|
73
|
-
|
|
74
77
|
const isStrayGlobal = (scan, node) => scan.ts.isPropertyAssignment(node) && scan.kit.propertyNameText(node.name) === 'isGlobal'
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
&& node.initializer.kind === scan.ts.SyntaxKind.TrueKeyword && !scan.isAppRoot(scan.file) && !scan.isWorld(scan.file);
|
|
77
79
|
// A composition group's module list is any array of the group: the root spreads it into its imports.
|
|
78
80
|
const isGroupList = (scan, node) => scan.ts.isArrayLiteralExpression(node) && isComposeGroup(scan.file.rel);
|
|
79
|
-
|
|
80
81
|
function visitReferenceNode(scan, node) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
82
|
+
if (isImportsList(scan, node)) {
|
|
83
|
+
for (const element of node.initializer.elements)
|
|
84
|
+
noteReference(scan, element, true);
|
|
85
|
+
}
|
|
86
|
+
else if (isGroupList(scan, node)) {
|
|
87
|
+
for (const element of node.elements)
|
|
88
|
+
noteReference(scan, element, true);
|
|
89
|
+
}
|
|
90
|
+
else if (callName(scan.ts, node) === 'register' && !scan.seen.has(node)) {
|
|
91
|
+
noteReference(scan, node, false);
|
|
92
|
+
}
|
|
93
|
+
if (isStrayGlobal(scan, node)) {
|
|
94
|
+
scan.report(scan.file, node, '`isGlobal: true` appears only in the app root (apps/<app>/src/app.module.ts or a group of apps/<app>/src/compose/), where the representative module of a capability is registered; a module never decides its own globality.');
|
|
95
|
+
}
|
|
96
|
+
return true;
|
|
92
97
|
}
|
|
93
|
-
|
|
94
98
|
function moduleReferences(graph, kit, ts, modules, isWorld, isAppRoot, report) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
99
|
+
// The references to modules: importer (the enclosing module class, else the file), target, node, whether it is a register call.
|
|
100
|
+
const references = [];
|
|
101
|
+
for (const file of graph.files.values()) {
|
|
102
|
+
if (isWorld(file))
|
|
103
|
+
continue; // the test composition root assembles modules; it is not a module importer
|
|
104
|
+
const scan = { ts, kit, modules, file, isWorld, isAppRoot, report, references, checker: kit.checkerOf(file.sourceFile), seen: new Set() };
|
|
105
|
+
kit.walk(file.sourceFile, (node) => visitReferenceNode(scan, node));
|
|
106
|
+
}
|
|
107
|
+
return references;
|
|
103
108
|
}
|
|
104
|
-
|
|
105
109
|
function isTrueGlobal(kit, ts, options) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
110
|
+
if (!options || !ts.isObjectLiteralExpression(options))
|
|
111
|
+
return false;
|
|
112
|
+
const property = kit.propertyOf(options, 'isGlobal');
|
|
113
|
+
return property !== undefined && ts.isPropertyAssignment(property) && property.initializer.kind === ts.SyntaxKind.TrueKeyword;
|
|
109
114
|
}
|
|
110
|
-
|
|
111
115
|
function appRegistrations(rootReferences, appOf) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
const inApps = new Map(); // module declaration -> Set(app names)
|
|
117
|
+
for (const item of rootReferences) {
|
|
118
|
+
const app = appOf(item.file) ?? item.file.rel;
|
|
119
|
+
let apps = inApps.get(item.target.declaration);
|
|
120
|
+
if (!apps) {
|
|
121
|
+
apps = new Set();
|
|
122
|
+
inApps.set(item.target.declaration, apps);
|
|
123
|
+
}
|
|
124
|
+
apps.add(app);
|
|
125
|
+
}
|
|
126
|
+
return inApps;
|
|
119
127
|
}
|
|
120
|
-
|
|
121
128
|
function reportDuplicateAppModules(config, rootReferences, appOf, report) {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
129
|
+
for (const app of config.apps) {
|
|
130
|
+
const seenInApp = new Map();
|
|
131
|
+
for (const item of rootReferences.filter(entry => appOf(entry.file) === app.name)) {
|
|
132
|
+
if (seenInApp.has(item.target.declaration)) {
|
|
133
|
+
report(item.file, item.node, `${item.target.name} is registered more than once in the root of app ${app.name}; a module is listed once per app.`, { module: item.target.name, app: app.name });
|
|
134
|
+
}
|
|
135
|
+
else
|
|
136
|
+
seenInApp.set(item.target.declaration, item.node);
|
|
137
|
+
}
|
|
128
138
|
}
|
|
129
|
-
}
|
|
130
139
|
}
|
|
131
|
-
|
|
132
140
|
function reportCapabilityRegistrations(rootReferences, kit, ts, report) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
141
|
+
for (const item of rootReferences) {
|
|
142
|
+
if (!item.target.capability || !item.viaImports && !item.register)
|
|
143
|
+
continue;
|
|
144
|
+
if (!item.register)
|
|
145
|
+
report(item.file, item.node, `${item.target.name} is listed in imports as a bare class; the representative module of a capability is registered in the app root as ${item.target.name}.register({ isGlobal: true, ...options }).`, { module: item.target.name });
|
|
146
|
+
else if (!isTrueGlobal(kit, ts, item.options))
|
|
147
|
+
report(item.file, item.node, `${item.target.name} is registered in the app root without the literal \`isGlobal: true\`; write ${item.target.name}.register({ isGlobal: true, ...options }).`, { module: item.target.name });
|
|
148
|
+
}
|
|
138
149
|
}
|
|
139
|
-
|
|
140
150
|
/** The references that import a module from a non-app module, grouped by the imported module declaration. */
|
|
141
151
|
function importersByModule(references) {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
152
|
+
const importersOf = new Map(); // module declaration -> [reference]
|
|
153
|
+
for (const item of references.filter(entry => !entry.root && entry.viaImports)) {
|
|
154
|
+
let importers = importersOf.get(item.target.declaration);
|
|
155
|
+
if (!importers) {
|
|
156
|
+
importers = [];
|
|
157
|
+
importersOf.set(item.target.declaration, importers);
|
|
158
|
+
}
|
|
159
|
+
importers.push(item);
|
|
160
|
+
}
|
|
161
|
+
return importersOf;
|
|
148
162
|
}
|
|
149
|
-
|
|
150
163
|
function reportSharedSubModule(target, list, report) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
164
|
+
const distinct = [...new Set(list.map(item => item.importer))];
|
|
165
|
+
const targetOwner = target.file.owner;
|
|
166
|
+
const featureCase = target.file.tier === 'feature' && targetOwner && list.every(item => item.importerOwner === targetOwner.root);
|
|
167
|
+
if (distinct.length <= 1 || featureCase)
|
|
168
|
+
return;
|
|
169
|
+
for (const item of list.filter(entry => entry.importer !== list[0]?.importer)) {
|
|
170
|
+
report(item.file, item.node, `${target.name} is imported by ${distinct.length} modules; a sub-module has exactly one importer, its parent. Another capability's module is consumed through its Inject*() decorators, never imported.`, { module: target.name });
|
|
171
|
+
}
|
|
157
172
|
}
|
|
158
|
-
|
|
159
173
|
function reportNonAppImporters(references, modules, inApps, report) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
174
|
+
// Non-app importers: no importer of an app-registered module, exactly one importer otherwise (the feature case excepted).
|
|
175
|
+
for (const [declaration, list] of importersByModule(references)) {
|
|
176
|
+
const target = modules.get(declaration);
|
|
177
|
+
if (!target)
|
|
178
|
+
continue;
|
|
179
|
+
const apps = inApps.get(declaration);
|
|
180
|
+
if (!apps) {
|
|
181
|
+
reportSharedSubModule(target, list, report);
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
for (const item of list) {
|
|
185
|
+
report(item.file, item.node, `${target.name} is registered in the root of app ${[...apps].sort(byCodeUnit).join(', ')}, so no other module imports it; consume it through its Inject*() decorators.`, { module: target.name });
|
|
186
|
+
}
|
|
170
187
|
}
|
|
171
|
-
}
|
|
172
188
|
}
|
|
173
|
-
|
|
174
189
|
export function checkRegisterOnce(input) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
capabilityModules: [...modules.values()].filter(item => item.capability).length, registrations: references.filter(item => item.register).length,
|
|
198
|
-
rootImports: rootReferences.length } };
|
|
190
|
+
const { config, graph } = input;
|
|
191
|
+
const kit = machineKit(input);
|
|
192
|
+
const { ts } = kit;
|
|
193
|
+
const violations = [];
|
|
194
|
+
const report = (file, node, message, extra = {}) => { violations.push({ ruleId: RULE, path: file.rel, ...kit.at(file.rel, file.sourceFile, node), message, ...extra }); };
|
|
195
|
+
const isAppRoot = file => Boolean(file.slot?.startsWith('be.app.')) && (path.posix.basename(file.rel) === 'app.module.ts' || isComposeGroup(file.rel));
|
|
196
|
+
// The test world (slot be.tests.world) is the test composition root: useTestWorld registers capability modules with
|
|
197
|
+
// `isGlobal: true` the way an app root does. A spec (integration, contract, e2e) is not a composition root.
|
|
198
|
+
const isWorld = file => isTestWorldSlot(file.slot);
|
|
199
|
+
const appOf = file => config.apps.find(app => file.rel === `apps/${app.name}/src/app.module.ts`
|
|
200
|
+
|| (isComposeGroup(file.rel) && file.rel.startsWith(`apps/${app.name}/src/compose/`)))?.name ?? null;
|
|
201
|
+
const modules = moduleDeclarations(graph, kit, ts);
|
|
202
|
+
const references = moduleReferences(graph, kit, ts, modules, isWorld, isAppRoot, report);
|
|
203
|
+
const rootReferences = references.filter(item => item.root);
|
|
204
|
+
const inApps = appRegistrations(rootReferences, appOf);
|
|
205
|
+
// App roots: each module is listed once, capability modules are registered with isGlobal true.
|
|
206
|
+
reportDuplicateAppModules(config, rootReferences, appOf, report);
|
|
207
|
+
reportCapabilityRegistrations(rootReferences, kit, ts, report);
|
|
208
|
+
reportNonAppImporters(references, modules, inApps, report);
|
|
209
|
+
return { violations, coverage: { status: 'checked', apps: config.apps.filter(app => kit.appRoot(app.name)).length, modules: modules.size,
|
|
210
|
+
capabilityModules: [...modules.values()].filter(item => item.capability).length, registrations: references.filter(item => item.register).length,
|
|
211
|
+
rootImports: rootReferences.length } };
|
|
199
212
|
}
|