@starci/eslint-canon-be 3.5.0 → 3.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +13 -2
- package/dist/ambient-id.d.ts +9 -0
- package/{ambient-id.mjs → dist/ambient-id.js} +43 -39
- package/dist/app-composition.d.ts +21 -0
- package/{app-composition.mjs → dist/app-composition.js} +396 -300
- package/dist/async-discipline.d.ts +9 -0
- package/dist/async-discipline.js +77 -0
- package/dist/authorization.d.ts +12 -0
- package/{authorization.mjs → dist/authorization.js} +53 -59
- package/dist/boundary-schema.d.ts +15 -0
- package/{boundary-schema.mjs → dist/boundary-schema.js} +120 -105
- package/dist/builders.d.ts +21 -0
- package/{builders.mjs → dist/builders.js} +162 -146
- package/dist/cli.d.ts +15 -0
- package/{cli.mjs → dist/cli.js} +97 -82
- package/dist/comments.d.ts +52 -0
- package/dist/comments.js +412 -0
- package/dist/config-owner.d.ts +24 -0
- package/{config-owner.mjs → dist/config-owner.js} +256 -219
- package/dist/connections.d.ts +12 -0
- package/{connections.mjs → dist/connections.js} +138 -140
- package/dist/cookies.d.ts +9 -0
- package/{cookies.mjs → dist/cookies.js} +58 -58
- package/dist/cqrs.d.ts +27 -0
- package/{cqrs.mjs → dist/cqrs.js} +341 -282
- package/dist/data-access.d.ts +50 -0
- package/{data-access.mjs → dist/data-access.js} +238 -243
- package/dist/default-deny.d.ts +15 -0
- package/{default-deny.mjs → dist/default-deny.js} +103 -88
- package/dist/e2e-flow.d.ts +25 -0
- package/{e2e-flow.mjs → dist/e2e-flow.js} +113 -112
- package/dist/edge-hardening.d.ts +10 -0
- package/dist/edge-hardening.js +173 -0
- package/dist/error-handling.d.ts +21 -0
- package/{error-handling.mjs → dist/error-handling.js} +289 -239
- package/dist/event-bus.d.ts +14 -0
- package/{event-bus.mjs → dist/event-bus.js} +146 -129
- package/dist/feature-thin.d.ts +12 -0
- package/{feature-thin.mjs → dist/feature-thin.js} +208 -191
- package/dist/function-budget.d.ts +7 -0
- package/{function-budget.mjs → dist/function-budget.js} +24 -27
- package/dist/health-ready.d.ts +10 -0
- package/dist/health-ready.js +703 -0
- package/dist/idempotency.d.ts +10 -0
- package/{idempotency.mjs → dist/idempotency.js} +296 -226
- package/dist/index.d.ts +54 -0
- package/{index.mjs → dist/index.js} +91 -109
- package/dist/infra-owner.d.ts +18 -0
- package/{infra-owner.mjs → dist/infra-owner.js} +58 -51
- package/dist/injection.d.ts +30 -0
- package/{injection.mjs → dist/injection.js} +397 -344
- package/dist/input-bounds.d.ts +15 -0
- package/{input-bounds.mjs → dist/input-bounds.js} +143 -132
- package/dist/jobs.d.ts +17 -0
- package/{jobs.mjs → dist/jobs.js} +116 -99
- package/dist/jwt-alg.d.ts +6 -0
- package/dist/jwt-alg.js +49 -0
- package/dist/lib/app-roles.d.ts +25 -0
- package/{lib/app-roles.mjs → dist/lib/app-roles.js} +15 -17
- package/dist/lib/ast.d.ts +40 -0
- package/dist/lib/ast.js +100 -0
- package/dist/lib/client-idempotency.d.ts +3 -0
- package/{lib/client-idempotency.mjs → dist/lib/client-idempotency.js} +316 -268
- package/dist/lib/config.d.ts +36 -0
- package/{lib/config.mjs → dist/lib/config.js} +24 -27
- package/dist/lib/db-writes.d.ts +29 -0
- package/{lib/db-writes.mjs → dist/lib/db-writes.js} +27 -27
- package/dist/lib/declared.d.ts +77 -0
- package/{lib/declared.mjs → dist/lib/declared.js} +83 -78
- package/dist/lib/doors.d.ts +50 -0
- package/{lib/doors.mjs → dist/lib/doors.js} +45 -50
- package/dist/lib/edition.d.ts +25 -0
- package/{lib/edition.mjs → dist/lib/edition.js} +15 -20
- package/dist/lib/entity-writes.d.ts +7 -0
- package/{lib/entity-writes.mjs → dist/lib/entity-writes.js} +31 -22
- package/dist/lib/hfs-view.d.ts +127 -0
- package/dist/lib/hfs-view.js +1 -0
- package/dist/lib/hfs.d.ts +34 -0
- package/{lib/hfs.mjs → dist/lib/hfs.js} +31 -29
- package/dist/lib/import-source.d.ts +63 -0
- package/dist/lib/import-source.js +134 -0
- package/dist/lib/path.d.ts +8 -0
- package/{lib/path.mjs → dist/lib/path.js} +4 -7
- package/dist/lib/persistence.d.ts +115 -0
- package/{lib/persistence.mjs → dist/lib/persistence.js} +55 -66
- package/dist/lib/ports.d.ts +70 -0
- package/{lib/ports.mjs → dist/lib/ports.js} +62 -66
- package/dist/lib/rule.d.ts +31 -0
- package/dist/lib/rule.js +2 -0
- package/dist/lib/runtime-root.d.ts +4 -0
- package/dist/lib/runtime-root.js +10 -0
- package/dist/lib/schema-values.d.ts +13 -0
- package/{lib/schema-values.mjs → dist/lib/schema-values.js} +67 -59
- package/dist/lib/specifier.d.ts +12 -0
- package/dist/lib/specifier.js +29 -0
- package/dist/lib/subject-values.d.ts +4 -0
- package/dist/lib/subject-values.js +61 -0
- package/dist/lib/transactions.d.ts +18 -0
- package/{lib/transactions.mjs → dist/lib/transactions.js} +17 -15
- package/dist/lib/transport-slots.d.ts +17 -0
- package/{lib/transport-slots.mjs → dist/lib/transport-slots.js} +2 -4
- package/dist/lib/types.d.ts +96 -0
- package/dist/lib/types.js +150 -0
- package/dist/lib/unit-spec.d.ts +48 -0
- package/{lib/unit-spec.mjs → dist/lib/unit-spec.js} +35 -44
- package/dist/lib/webhook-ack.d.ts +4 -0
- package/{lib/webhook-ack.mjs → dist/lib/webhook-ack.js} +78 -62
- package/dist/lib/webhook-handoff-inbox.d.ts +3 -0
- package/{lib/webhook-handoff-inbox.mjs → dist/lib/webhook-handoff-inbox.js} +195 -167
- package/dist/lib/webhook-handoff-intake.d.ts +4 -0
- package/{lib/webhook-handoff-intake.mjs → dist/lib/webhook-handoff-intake.js} +125 -102
- package/dist/lib/webhook-handoff.d.ts +15 -0
- package/{lib/webhook-handoff.mjs → dist/lib/webhook-handoff.js} +107 -100
- package/dist/lib/webhook-verifiers.d.ts +20 -0
- package/{lib/webhook-verifiers.mjs → dist/lib/webhook-verifiers.js} +108 -104
- package/dist/lib/why.d.ts +9 -0
- package/{lib/why.mjs → dist/lib/why.js} +6 -6
- package/dist/log-safety.d.ts +20 -0
- package/dist/log-safety.js +308 -0
- package/dist/module-layering.d.ts +42 -0
- package/dist/module-layering.js +257 -0
- package/dist/module-shape.d.ts +47 -0
- package/{module-shape.mjs → dist/module-shape.js} +278 -236
- package/dist/naming.d.ts +49 -0
- package/dist/naming.js +246 -0
- package/dist/observability.d.ts +25 -0
- package/dist/observability.js +245 -0
- package/dist/operations.d.ts +23 -0
- package/{operations.mjs → dist/operations.js} +410 -332
- package/dist/project-graph.d.ts +9 -0
- package/{project-graph.mjs → dist/project-graph.js} +8 -13
- package/dist/projections.d.ts +11 -0
- package/{projections.mjs → dist/projections.js} +60 -57
- package/dist/query-safety.d.ts +21 -0
- package/{query-safety.mjs → dist/query-safety.js} +92 -108
- package/dist/realtime.d.ts +15 -0
- package/{realtime.mjs → dist/realtime.js} +108 -106
- package/dist/resilience.d.ts +15 -0
- package/dist/resilience.js +319 -0
- package/dist/schema-authority.d.ts +15 -0
- package/{schema-authority.mjs → dist/schema-authority.js} +256 -220
- package/dist/service-deps.d.ts +17 -0
- package/{service-deps.mjs → dist/service-deps.js} +133 -130
- package/dist/service-isolation.d.ts +8 -0
- package/dist/service-isolation.js +76 -0
- package/dist/size-budget.d.ts +9 -0
- package/{size-budget.mjs → dist/size-budget.js} +27 -27
- package/dist/sonar-parity.d.ts +5 -0
- package/{sonar-parity.mjs → dist/sonar-parity.js} +7 -7
- package/dist/spec-no-skip.d.ts +9 -0
- package/dist/spec-no-skip.js +81 -0
- package/dist/spec-quality.d.ts +10 -0
- package/{spec-quality.mjs → dist/spec-quality.js} +103 -87
- package/dist/suppression.d.ts +26 -0
- package/{suppression.mjs → dist/suppression.js} +30 -45
- package/dist/temporal.d.ts +9 -0
- package/{temporal.mjs → dist/temporal.js} +75 -65
- package/dist/test-world.d.ts +28 -0
- package/{test-world.mjs → dist/test-world.js} +102 -83
- package/dist/testing.d.ts +51 -0
- package/dist/testing.js +368 -0
- package/dist/third-party-owner.d.ts +8 -0
- package/{third-party-owner.mjs → dist/third-party-owner.js} +105 -91
- package/dist/transport.d.ts +24 -0
- package/{transport.mjs → dist/transport.js} +279 -240
- package/dist/type-safety.d.ts +25 -0
- package/dist/type-safety.js +297 -0
- package/dist/unit-spec.d.ts +30 -0
- package/{unit-spec.mjs → dist/unit-spec.js} +473 -399
- package/dist/uploads.d.ts +9 -0
- package/{uploads.mjs → dist/uploads.js} +62 -54
- package/dist/user-copy.d.ts +9 -0
- package/{user-copy.mjs → dist/user-copy.js} +76 -67
- package/dist/webhooks.d.ts +16 -0
- package/{webhooks.mjs → dist/webhooks.js} +243 -231
- package/package.json +23 -8
- package/runtime/knowledge/hfs/canon-pins.yaml +18 -11
- package/runtime/scripts/hfs/repo-identity.mjs +5 -4
- package/async-discipline.mjs +0 -83
- package/comments.mjs +0 -416
- package/edge-hardening.mjs +0 -139
- package/health-ready.mjs +0 -539
- package/jwt-alg.mjs +0 -45
- package/lib/ast.mjs +0 -88
- package/lib/import-source.mjs +0 -104
- package/lib/specifier.mjs +0 -27
- package/lib/subject-values.mjs +0 -55
- package/lib/types.mjs +0 -133
- package/log-safety.mjs +0 -303
- package/module-layering.mjs +0 -270
- package/naming.mjs +0 -251
- package/observability.mjs +0 -241
- package/resilience.mjs +0 -304
- package/service-isolation.mjs +0 -75
- package/spec-no-skip.mjs +0 -85
- package/testing.mjs +0 -384
- package/type-safety.mjs +0 -323
|
@@ -19,15 +19,14 @@
|
|
|
19
19
|
* R265 resolves composition from types, including renamed constructors, factories, maps and scheduler tables. All
|
|
20
20
|
* three rules ask the slot view which entry a file matches; none keeps a path of its own.
|
|
21
21
|
*/
|
|
22
|
-
import { lineCount } from "
|
|
23
|
-
import ts from "typescript"
|
|
24
|
-
import { APP_ENV_ROLE, APP_OPTIONS_ROLE, appRoleOf } from "./lib/app-roles.
|
|
25
|
-
import { hfsOf } from "./lib/hfs.
|
|
26
|
-
import { isOwnedBy } from "./lib/declared.
|
|
27
|
-
import { keyName, staticText } from "./lib/ast.
|
|
28
|
-
import { isDeclarationFile, normalizePath } from "./lib/path.
|
|
29
|
-
import { moduleOf, originsOfType, packageOfExport, typed } from "./lib/types.
|
|
30
|
-
|
|
22
|
+
import { lineCount } from "../runtime/scripts/lib/line-count.mjs";
|
|
23
|
+
import ts from "typescript";
|
|
24
|
+
import { APP_ENV_ROLE, APP_OPTIONS_ROLE, appRoleOf } from "./lib/app-roles.js";
|
|
25
|
+
import { hfsOf } from "./lib/hfs.js";
|
|
26
|
+
import { isOwnedBy } from "./lib/declared.js";
|
|
27
|
+
import { keyName, staticText } from "./lib/ast.js";
|
|
28
|
+
import { isDeclarationFile, normalizePath } from "./lib/path.js";
|
|
29
|
+
import { childNode, moduleOf, originsOfType, packageOfExport, resolvedSymbol as resolveAlias, typed } from "./lib/types.js";
|
|
31
30
|
/** Static factories that register a Nest module (a dynamic module), a queue or a flow producer. */
|
|
32
31
|
const REGISTRATION_CALLS = new Set([
|
|
33
32
|
"register",
|
|
@@ -39,55 +38,53 @@ const REGISTRATION_CALLS = new Set([
|
|
|
39
38
|
"registerQueue",
|
|
40
39
|
"registerQueueAsync",
|
|
41
40
|
"registerFlowProducer",
|
|
42
|
-
])
|
|
43
|
-
|
|
41
|
+
]);
|
|
44
42
|
/** Keys whose array value is a composition list whatever it holds. */
|
|
45
|
-
const COMPOSITION_KEYS = new Set(["imports", "modules", "schedulers", "processors"])
|
|
46
|
-
|
|
43
|
+
const COMPOSITION_KEYS = new Set(["imports", "modules", "schedulers", "processors"]);
|
|
47
44
|
/** A name that is a Nest module class. */
|
|
48
|
-
const MODULE_NAME = /Module
|
|
45
|
+
const MODULE_NAME = /Module$/;
|
|
49
46
|
/** A name that is a list of modules, queues, schedulers or processors (the operand of a spread). */
|
|
50
|
-
const LIST_NAME = /(?:Modules|Queues|Schedulers|Processors)
|
|
47
|
+
const LIST_NAME = /(?:Modules|Queues|Schedulers|Processors)$/;
|
|
51
48
|
/** A call that builds a scheduler entry or a queue registration: `orderExpirySchedulerOf(...)`, `ordersQueue(...)`. */
|
|
52
|
-
const ENTRY_CALL = /(?:Scheduler|Queue)(?:Of)
|
|
53
|
-
|
|
49
|
+
const ENTRY_CALL = /(?:Scheduler|Queue)(?:Of)?$/;
|
|
54
50
|
/** Type-only wrappers do not change whether an expression composes modules. */
|
|
55
|
-
const WRAPPERS = new Set(["TSAsExpression", "TSTypeAssertion", "TSSatisfiesExpression", "TSNonNullExpression", "TSInstantiationExpression", "ChainExpression"])
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
51
|
+
const WRAPPERS = new Set(["TSAsExpression", "TSTypeAssertion", "TSSatisfiesExpression", "TSNonNullExpression", "TSInstantiationExpression", "ChainExpression"]);
|
|
52
|
+
const isWrapper = (node) => node !== null && node !== undefined && WRAPPERS.has(node.type);
|
|
53
|
+
function unwrap(node) {
|
|
54
|
+
while (isWrapper(node))
|
|
55
|
+
node = node.expression;
|
|
56
|
+
return node;
|
|
59
57
|
}
|
|
60
|
-
|
|
61
58
|
/** The known name of a member, including a static computed string. */
|
|
62
|
-
const memberName = (node) => node.computed ? staticText(node.property) : keyName(node.property)
|
|
63
|
-
|
|
59
|
+
const memberName = (node) => node.computed ? staticText(node.property) : keyName(node.property);
|
|
64
60
|
/** The last name of an identifier or a statically named member expression, else null. */
|
|
65
61
|
const lastName = (node) => {
|
|
66
|
-
node = unwrap(node)
|
|
67
|
-
if (node?.type === "Identifier")
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
62
|
+
node = unwrap(node);
|
|
63
|
+
if (node?.type === "Identifier")
|
|
64
|
+
return node.name;
|
|
65
|
+
if (node?.type === "MemberExpression")
|
|
66
|
+
return memberName(node);
|
|
67
|
+
return null;
|
|
68
|
+
};
|
|
73
69
|
const compositionOf = (element) => {
|
|
74
|
-
element = unwrap(element)
|
|
75
|
-
if (!element)
|
|
70
|
+
element = unwrap(element);
|
|
71
|
+
if (!element)
|
|
72
|
+
return null;
|
|
76
73
|
if (element.type === "SpreadElement") {
|
|
77
|
-
const argument = unwrap(element.argument)
|
|
78
|
-
const spread = argument?.type === "CallExpression" ? lastName(argument.callee) : lastName(argument)
|
|
79
|
-
return spread !== null && (LIST_NAME.test(spread) || MODULE_NAME.test(spread)) ? "list" : null
|
|
74
|
+
const argument = unwrap(element.argument);
|
|
75
|
+
const spread = argument?.type === "CallExpression" ? lastName(argument.callee) : lastName(argument);
|
|
76
|
+
return spread !== null && (LIST_NAME.test(spread) || MODULE_NAME.test(spread)) ? "list" : null;
|
|
80
77
|
}
|
|
81
78
|
if (element.type === "CallExpression") {
|
|
82
|
-
const callee = unwrap(element.callee)
|
|
83
|
-
if (callee.type === "MemberExpression" && REGISTRATION_CALLS.has(memberName(callee)))
|
|
84
|
-
|
|
85
|
-
|
|
79
|
+
const callee = unwrap(element.callee);
|
|
80
|
+
if (callee.type === "MemberExpression" && REGISTRATION_CALLS.has(memberName(callee)))
|
|
81
|
+
return "registration";
|
|
82
|
+
const name = lastName(callee);
|
|
83
|
+
return name !== null && ENTRY_CALL.test(name) ? "scheduler" : null;
|
|
86
84
|
}
|
|
87
|
-
const name = lastName(element)
|
|
88
|
-
return name !== null && MODULE_NAME.test(name) ? "module" : null
|
|
89
|
-
}
|
|
90
|
-
|
|
85
|
+
const name = lastName(element);
|
|
86
|
+
return name !== null && MODULE_NAME.test(name) ? "module" : null;
|
|
87
|
+
};
|
|
91
88
|
/** Env parsing and options bindings hold no module, queue or scheduler composition. */
|
|
92
89
|
export const appOptionsCompositionFree = {
|
|
93
90
|
meta: {
|
|
@@ -101,108 +98,135 @@ export const appOptionsCompositionFree = {
|
|
|
101
98
|
},
|
|
102
99
|
},
|
|
103
100
|
create(context) {
|
|
104
|
-
const filename = normalizePath(context.filename || context.getFilename())
|
|
105
|
-
if (isDeclarationFile(filename))
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
101
|
+
const filename = normalizePath(context.filename || context.getFilename());
|
|
102
|
+
if (isDeclarationFile(filename))
|
|
103
|
+
return {};
|
|
104
|
+
const role = appRoleOf(hfsOf(context), filename)?.entry;
|
|
105
|
+
if (role !== APP_OPTIONS_ROLE && role !== APP_ENV_ROLE)
|
|
106
|
+
return {};
|
|
107
|
+
const judged = new WeakSet();
|
|
109
108
|
return {
|
|
110
109
|
CallExpression(node) {
|
|
111
|
-
if (role !== APP_ENV_ROLE)
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (
|
|
117
|
-
|
|
110
|
+
if (role !== APP_ENV_ROLE)
|
|
111
|
+
return;
|
|
112
|
+
let element = node;
|
|
113
|
+
while (isWrapper(element.parent))
|
|
114
|
+
element = element.parent;
|
|
115
|
+
if (element.parent?.type === "ArrayExpression")
|
|
116
|
+
return;
|
|
117
|
+
const what = compositionOf(node);
|
|
118
|
+
if (what !== "registration" && what !== "scheduler")
|
|
119
|
+
return;
|
|
120
|
+
context.report({ node, messageId: "call", data: { what: what === "registration" ? "registration call" : "scheduler or queue call" } });
|
|
118
121
|
},
|
|
119
122
|
Property(node) {
|
|
120
|
-
const value = unwrap(node.value)
|
|
121
|
-
if (value?.type !== "ArrayExpression")
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
123
|
+
const value = unwrap(node.value);
|
|
124
|
+
if (value?.type !== "ArrayExpression")
|
|
125
|
+
return;
|
|
126
|
+
const key = node.computed ? staticText(node.key) : keyName(node.key);
|
|
127
|
+
if (key === null || !COMPOSITION_KEYS.has(key))
|
|
128
|
+
return;
|
|
129
|
+
judged.add(value);
|
|
130
|
+
context.report({ node, messageId: "list", data: { key, role } });
|
|
126
131
|
},
|
|
127
132
|
"ArrayExpression:exit"(node) {
|
|
128
|
-
if (judged.has(node))
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
+
if (judged.has(node))
|
|
134
|
+
return;
|
|
135
|
+
const what = node.elements.map(compositionOf).find((kind) => kind !== null);
|
|
136
|
+
if (what === undefined)
|
|
137
|
+
return;
|
|
138
|
+
const label = { module: "Nest module", registration: "module or queue registration", scheduler: "scheduler or queue entry", list: "spread of a module, queue or scheduler list" }[what];
|
|
139
|
+
context.report({ node, messageId: "element", data: { what: label, role } });
|
|
133
140
|
},
|
|
134
|
-
}
|
|
141
|
+
};
|
|
135
142
|
},
|
|
136
|
-
}
|
|
137
|
-
|
|
143
|
+
};
|
|
144
|
+
/** Whether a type is a reference to a generic type (it carries a `target`), the only kind `getTypeArguments` reads arguments from. */
|
|
145
|
+
const isTypeReference = (type) => "target" in type;
|
|
138
146
|
/** Composition is a value's type, independent of the spelling of its class, factory or helper. */
|
|
139
147
|
const compositionTypes = (checker) => {
|
|
140
148
|
const propertyType = (type, name) => {
|
|
141
|
-
const property = type.getProperty(name)
|
|
142
|
-
const declaration = property?.valueDeclaration ?? property?.getDeclarations?.()?.[0]
|
|
143
|
-
return declaration ? checker.getTypeOfSymbolAtLocation(property, declaration) : null
|
|
144
|
-
}
|
|
145
|
-
const constructor = (type) => (type?.getConstructSignatures().length ?? 0) > 0
|
|
146
|
-
const dynamicModule = (type) => constructor(propertyType(type, "module"))
|
|
149
|
+
const property = type.getProperty(name);
|
|
150
|
+
const declaration = property?.valueDeclaration ?? property?.getDeclarations?.()?.[0];
|
|
151
|
+
return property && declaration ? checker.getTypeOfSymbolAtLocation(property, declaration) : null;
|
|
152
|
+
};
|
|
153
|
+
const constructor = (type) => (type?.getConstructSignatures().length ?? 0) > 0;
|
|
154
|
+
const dynamicModule = (type) => constructor(propertyType(type, "module"));
|
|
147
155
|
const moduleConstructor = (type) => {
|
|
148
|
-
if (!constructor(type))
|
|
156
|
+
if (!constructor(type))
|
|
157
|
+
return false;
|
|
149
158
|
for (const declaration of type.getSymbol()?.getDeclarations?.() ?? []) {
|
|
150
|
-
if (!ts.isClassDeclaration(declaration) && !ts.isClassExpression(declaration))
|
|
159
|
+
if (!ts.isClassDeclaration(declaration) && !ts.isClassExpression(declaration))
|
|
160
|
+
continue;
|
|
151
161
|
for (const decorator of ts.getDecorators(declaration) ?? []) {
|
|
152
|
-
const expression = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression
|
|
153
|
-
const symbol = checker.getSymbolAtLocation(ts.isPropertyAccessExpression(expression) ? expression.name : expression)
|
|
154
|
-
const resolved =
|
|
155
|
-
if (resolved?.name === "Module" && resolved.getDeclarations()?.some((origin) => moduleOf(origin, normalizePath(origin.getSourceFile().fileName)) === "@nestjs/common"))
|
|
162
|
+
const expression = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression;
|
|
163
|
+
const symbol = checker.getSymbolAtLocation(ts.isPropertyAccessExpression(expression) ? expression.name : expression);
|
|
164
|
+
const resolved = resolveAlias(checker, symbol);
|
|
165
|
+
if (resolved?.name === "Module" && resolved.getDeclarations()?.some((origin) => moduleOf(origin, normalizePath(origin.getSourceFile().fileName)) === "@nestjs/common"))
|
|
166
|
+
return true;
|
|
156
167
|
}
|
|
157
168
|
}
|
|
158
169
|
// A factory returning DynamicModule identifies a module even if it has no decorator or conventional name.
|
|
159
170
|
return type.getProperties().some((property) => {
|
|
160
|
-
const factory = propertyType(type, property.name)
|
|
161
|
-
return factory?.getCallSignatures().some((signature) => dynamicModule(checker.getReturnTypeOfSignature(signature)))
|
|
162
|
-
})
|
|
163
|
-
}
|
|
171
|
+
const factory = propertyType(type, property.name);
|
|
172
|
+
return factory?.getCallSignatures().some((signature) => dynamicModule(checker.getReturnTypeOfSignature(signature)));
|
|
173
|
+
});
|
|
174
|
+
};
|
|
164
175
|
const arrayElement = (type) => checker.isArrayType(type) || checker.isTupleType(type)
|
|
165
176
|
? checker.getIndexTypeOfType(type, ts.IndexKind.Number)
|
|
166
|
-
: type.getSymbol()?.name === "ReadonlyArray" ? checker.getTypeArguments(type)[0] : null
|
|
167
|
-
const MAX_DEPTH = 12
|
|
177
|
+
: type.getSymbol()?.name === "ReadonlyArray" ? (isTypeReference(type) ? checker.getTypeArguments(type)[0] : undefined) : null;
|
|
178
|
+
const MAX_DEPTH = 12;
|
|
168
179
|
const contains = (type, constructors = false, seen = new Set(), depth = 0) => {
|
|
169
180
|
// A library type graph (the application, an HTTP adapter) can be deep and cyclic through member types: a bounded walk never overflows the stack.
|
|
170
|
-
if (depth > MAX_DEPTH)
|
|
171
|
-
|
|
172
|
-
seen.
|
|
173
|
-
|
|
181
|
+
if (depth > MAX_DEPTH)
|
|
182
|
+
return false;
|
|
183
|
+
if (!type || seen.has(type) || type.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown | ts.TypeFlags.TypeParameter))
|
|
184
|
+
return false;
|
|
185
|
+
seen.add(type);
|
|
186
|
+
if (type.isUnionOrIntersection())
|
|
187
|
+
return type.types.some((part) => contains(part, constructors, new Set(seen), depth + 1));
|
|
174
188
|
// Async bootstrap returns Promise<void>; walk its result rather than recursively instantiating .then/.catch.
|
|
175
|
-
const awaited = checker.getAwaitedType(type)
|
|
176
|
-
if (awaited && awaited !== type)
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (
|
|
189
|
+
const awaited = checker.getAwaitedType(type);
|
|
190
|
+
if (awaited && awaited !== type)
|
|
191
|
+
return contains(awaited, constructors, seen, depth + 1);
|
|
192
|
+
const origins = originsOfType(checker, type);
|
|
193
|
+
if (origins.some((origin) => origin.module === "@nestjs/common" && ["DynamicModule", "Type", "Provider"].includes(origin.name)))
|
|
194
|
+
return true;
|
|
195
|
+
if (constructor(type))
|
|
196
|
+
return constructors || moduleConstructor(type);
|
|
197
|
+
if (dynamicModule(type))
|
|
198
|
+
return true;
|
|
199
|
+
const properties = new Set(type.getProperties().map((property) => property.name));
|
|
200
|
+
if (properties.has("provide") && ["useClass", "useFactory", "useValue", "useExisting"].some((key) => properties.has(key)))
|
|
201
|
+
return true;
|
|
202
|
+
if (properties.has("queue") && ["cron", "everyMs", "pattern", "repeat"].some((key) => properties.has(key)))
|
|
203
|
+
return true;
|
|
184
204
|
// Primitive options values and their library methods never compose an app.
|
|
185
|
-
if (!(type.flags & ts.TypeFlags.Object))
|
|
186
|
-
|
|
187
|
-
|
|
205
|
+
if (!(type.flags & ts.TypeFlags.Object))
|
|
206
|
+
return false;
|
|
207
|
+
const element = arrayElement(type);
|
|
208
|
+
if (element)
|
|
209
|
+
return contains(element, true, seen, depth + 1);
|
|
188
210
|
// Index signatures retain the Type<unknown> contract of a module map, unlike a plain adapter port map.
|
|
189
211
|
for (const index of checker.getIndexInfosOfType(type)) {
|
|
190
|
-
if (contains(index.type, false, new Set(seen), depth + 1))
|
|
212
|
+
if (contains(index.type, false, new Set(seen), depth + 1))
|
|
213
|
+
return true;
|
|
191
214
|
}
|
|
192
215
|
for (const signature of type.getCallSignatures()) {
|
|
193
|
-
if (contains(checker.getReturnTypeOfSignature(signature), false, new Set(seen), depth + 1))
|
|
216
|
+
if (contains(checker.getReturnTypeOfSignature(signature), false, new Set(seen), depth + 1))
|
|
217
|
+
return true;
|
|
194
218
|
}
|
|
195
|
-
return type.getProperties().some((property) => contains(propertyType(type, property.name), false, new Set(seen), depth + 1))
|
|
196
|
-
}
|
|
219
|
+
return type.getProperties().some((property) => contains(propertyType(type, property.name), false, new Set(seen), depth + 1));
|
|
220
|
+
};
|
|
197
221
|
const typedList = (type) => {
|
|
198
|
-
const element = arrayElement(type)
|
|
199
|
-
if (!element || element.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown))
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
|
|
222
|
+
const element = arrayElement(type);
|
|
223
|
+
if (!element || element.flags & (ts.TypeFlags.Any | ts.TypeFlags.Unknown))
|
|
224
|
+
return false;
|
|
225
|
+
const parts = element.isUnion() ? element.types : [element];
|
|
226
|
+
return parts.every((part) => contains(part, true));
|
|
227
|
+
};
|
|
228
|
+
return { arrayElement, contains, typedList };
|
|
229
|
+
};
|
|
206
230
|
/** R265: app values compose only in typed groups, never in env/options/bootstrap lists. */
|
|
207
231
|
export const appCompositionTyped = {
|
|
208
232
|
meta: {
|
|
@@ -216,125 +240,169 @@ export const appCompositionTyped = {
|
|
|
216
240
|
},
|
|
217
241
|
},
|
|
218
242
|
create(context) {
|
|
219
|
-
const filename = normalizePath(context.filename || context.getFilename())
|
|
220
|
-
if (isDeclarationFile(filename))
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
|
|
243
|
+
const filename = normalizePath(context.filename || context.getFilename());
|
|
244
|
+
if (isDeclarationFile(filename))
|
|
245
|
+
return {};
|
|
246
|
+
const role = appRoleOf(hfsOf(context), filename)?.entry;
|
|
247
|
+
const typedRoles = [APP_ENV_ROLE, APP_OPTIONS_ROLE, "main.ts", "compose/<area>.ts"];
|
|
248
|
+
if (!typedRoles.includes(role))
|
|
249
|
+
return {};
|
|
250
|
+
const { checker, toTs } = typed(context);
|
|
251
|
+
const { arrayElement, contains, typedList } = compositionTypes(checker);
|
|
252
|
+
const reported = new WeakSet();
|
|
226
253
|
const hasReport = (node) => {
|
|
227
|
-
for (let ancestor = node; ancestor; ancestor = ancestor.parent)
|
|
228
|
-
|
|
229
|
-
|
|
254
|
+
for (let ancestor = node; ancestor; ancestor = ancestor.parent)
|
|
255
|
+
if (reported.has(ancestor))
|
|
256
|
+
return true;
|
|
257
|
+
return false;
|
|
258
|
+
};
|
|
230
259
|
const report = (node, messageId) => {
|
|
231
|
-
if (hasReport(node))
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
260
|
+
if (hasReport(node))
|
|
261
|
+
return;
|
|
262
|
+
reported.add(node);
|
|
263
|
+
context.report({ node, messageId, data: { role } });
|
|
264
|
+
};
|
|
265
|
+
const typeOf = (node) => checker.getTypeAtLocation(toTs(node));
|
|
266
|
+
const bootCalls = ["create", "createApplicationContext", "createMicroservice"];
|
|
236
267
|
const bootstrapArgument = (node) => {
|
|
237
268
|
// The root module's registration belongs here; inline lists and metadata still belong in compose/.
|
|
238
|
-
if (role !== "main.ts" || node.type !== "CallExpression")
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
const
|
|
269
|
+
if (role !== "main.ts" || node.type !== "CallExpression")
|
|
270
|
+
return false;
|
|
271
|
+
let expression = node;
|
|
272
|
+
while (isWrapper(expression.parent))
|
|
273
|
+
expression = expression.parent;
|
|
274
|
+
const parent = expression.parent;
|
|
275
|
+
if (parent?.type !== "CallExpression" || !parent.arguments.some((argument) => argument === expression) || parent.callee.type !== "MemberExpression")
|
|
276
|
+
return false;
|
|
277
|
+
const owner = (callee) => packageOfExport(context, callee) ?? packageOfExport(context, callee.object);
|
|
244
278
|
// An api boots through NestFactory; a cli app boots its root module through nest-commander's CommandFactory.run (R148).
|
|
245
|
-
return (
|
|
246
|
-
|| (memberName(parent.callee) === "run" && parent.arguments[0] === expression && owner(parent.callee) === "nest-commander")
|
|
247
|
-
}
|
|
279
|
+
return (bootCalls.includes(memberName(parent.callee)) && owner(parent.callee) === "@nestjs/core")
|
|
280
|
+
|| (memberName(parent.callee) === "run" && parent.arguments[0] === expression && owner(parent.callee) === "nest-commander");
|
|
281
|
+
};
|
|
248
282
|
const checkValue = (node) => {
|
|
249
|
-
if (role === "compose/<area>.ts" || hasReport(node) || bootstrapArgument(node))
|
|
250
|
-
|
|
251
|
-
|
|
283
|
+
if (role === "compose/<area>.ts" || hasReport(node) || bootstrapArgument(node))
|
|
284
|
+
return;
|
|
285
|
+
if (contains(typeOf(node)))
|
|
286
|
+
report(node, "outside");
|
|
287
|
+
};
|
|
252
288
|
const checkGroup = (node, value, annotation) => {
|
|
253
|
-
if (role !== "compose/<area>.ts")
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
const
|
|
289
|
+
if (role !== "compose/<area>.ts")
|
|
290
|
+
return;
|
|
291
|
+
const type = typeOf(value);
|
|
292
|
+
const signatures = type.getCallSignatures();
|
|
293
|
+
const first = signatures[0];
|
|
294
|
+
const result = first ? checker.getReturnTypeOfSignature(first) : type;
|
|
257
295
|
if (signatures.length && !arrayElement(result) && !contains(result)) {
|
|
258
|
-
report(node, "business")
|
|
259
|
-
return
|
|
296
|
+
report(node, "business");
|
|
297
|
+
return;
|
|
260
298
|
}
|
|
261
|
-
if (!annotation || !typedList(result))
|
|
262
|
-
|
|
299
|
+
if (!annotation || !typedList(result))
|
|
300
|
+
report(node, "group");
|
|
301
|
+
};
|
|
263
302
|
const annotationOf = (node) => {
|
|
264
|
-
if (!node)
|
|
265
|
-
|
|
266
|
-
if (
|
|
267
|
-
|
|
268
|
-
if (node
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
303
|
+
if (!node)
|
|
304
|
+
return null;
|
|
305
|
+
if (node.type === "TSSatisfiesExpression")
|
|
306
|
+
return node.typeAnnotation;
|
|
307
|
+
if (isWrapper(node))
|
|
308
|
+
return annotationOf(node.expression);
|
|
309
|
+
if (node.type === "VariableDeclarator")
|
|
310
|
+
return node.id.typeAnnotation ?? annotationOf(node.init);
|
|
311
|
+
if ("returnType" in node && node.returnType)
|
|
312
|
+
return node.returnType;
|
|
313
|
+
if (node.type !== "Identifier")
|
|
314
|
+
return null;
|
|
315
|
+
const symbol = checker.getSymbolAtLocation(toTs(node));
|
|
316
|
+
const resolved = resolveAlias(checker, symbol);
|
|
272
317
|
return resolved?.getDeclarations()?.some((declaration) => {
|
|
273
|
-
const initializer = declaration
|
|
274
|
-
return declaration
|
|
275
|
-
}) ?? false
|
|
276
|
-
}
|
|
318
|
+
const initializer = childNode(declaration, "initializer");
|
|
319
|
+
return childNode(declaration, "type") || initializer && (ts.isArrowFunction(initializer) || ts.isFunctionExpression(initializer) || ts.isSatisfiesExpression(initializer)) && initializer.type;
|
|
320
|
+
}) ?? false;
|
|
321
|
+
};
|
|
277
322
|
return {
|
|
278
323
|
ExportNamedDeclaration(node) {
|
|
279
|
-
if (role !== "compose/<area>.ts" || node.exportKind === "type")
|
|
280
|
-
|
|
324
|
+
if (role !== "compose/<area>.ts" || node.exportKind === "type")
|
|
325
|
+
return;
|
|
326
|
+
const declaration = node.declaration;
|
|
281
327
|
if (!declaration) {
|
|
282
328
|
for (const specifier of node.specifiers) {
|
|
283
|
-
if (specifier.exportKind !== "type")
|
|
329
|
+
if (specifier.exportKind !== "type")
|
|
330
|
+
checkGroup(specifier, specifier.local, annotationOf(specifier.local));
|
|
284
331
|
}
|
|
285
|
-
return
|
|
332
|
+
return;
|
|
286
333
|
}
|
|
287
|
-
if (declaration.type === "FunctionDeclaration" && declaration.body)
|
|
288
|
-
|
|
334
|
+
if (declaration.type === "FunctionDeclaration" && declaration.body)
|
|
335
|
+
checkGroup(declaration, declaration, declaration.returnType);
|
|
336
|
+
if (declaration.type !== "VariableDeclaration")
|
|
337
|
+
return;
|
|
289
338
|
for (const binding of declaration.declarations) {
|
|
290
|
-
if (!binding.init)
|
|
291
|
-
|
|
339
|
+
if (!binding.init)
|
|
340
|
+
continue;
|
|
341
|
+
checkGroup(binding, binding.id, annotationOf(binding));
|
|
292
342
|
}
|
|
293
343
|
},
|
|
294
344
|
ExportDefaultDeclaration(node) {
|
|
295
|
-
if (role === "compose/<area>.ts")
|
|
345
|
+
if (role === "compose/<area>.ts")
|
|
346
|
+
checkGroup(node, node.declaration, annotationOf(node.declaration));
|
|
296
347
|
},
|
|
297
348
|
VariableDeclarator(node) {
|
|
298
|
-
if (node.init)
|
|
349
|
+
if (node.init)
|
|
350
|
+
checkValue(node.init);
|
|
299
351
|
},
|
|
300
352
|
FunctionDeclaration(node) {
|
|
301
|
-
if (node.body && role !== "compose/<area>.ts" && contains(typeOf(node)))
|
|
353
|
+
if (node.body && role !== "compose/<area>.ts" && contains(typeOf(node)))
|
|
354
|
+
report(node, "outside");
|
|
302
355
|
},
|
|
303
356
|
ArrowFunctionExpression(node) {
|
|
304
|
-
if (role !== "compose/<area>.ts" || hasReport(node))
|
|
305
|
-
|
|
306
|
-
|
|
357
|
+
if (role !== "compose/<area>.ts" || hasReport(node))
|
|
358
|
+
return;
|
|
359
|
+
const signature = typeOf(node).getCallSignatures()[0];
|
|
360
|
+
if (signature && !contains(checker.getReturnTypeOfSignature(signature)))
|
|
361
|
+
report(node, "business");
|
|
307
362
|
},
|
|
308
|
-
IfStatement(node) { if (role === "compose/<area>.ts")
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
363
|
+
IfStatement(node) { if (role === "compose/<area>.ts")
|
|
364
|
+
report(node, "business"); },
|
|
365
|
+
SwitchStatement(node) { if (role === "compose/<area>.ts")
|
|
366
|
+
report(node, "business"); },
|
|
367
|
+
ConditionalExpression(node) { if (role === "compose/<area>.ts")
|
|
368
|
+
report(node, "business"); },
|
|
369
|
+
ForStatement(node) { if (role === "compose/<area>.ts")
|
|
370
|
+
report(node, "business"); },
|
|
371
|
+
ForOfStatement(node) { if (role === "compose/<area>.ts")
|
|
372
|
+
report(node, "business"); },
|
|
373
|
+
WhileStatement(node) { if (role === "compose/<area>.ts")
|
|
374
|
+
report(node, "business"); },
|
|
314
375
|
ArrayExpression: checkValue,
|
|
315
376
|
ObjectExpression: checkValue,
|
|
316
377
|
CallExpression: checkValue,
|
|
317
378
|
ReturnStatement(node) {
|
|
318
|
-
if (node.argument)
|
|
379
|
+
if (node.argument)
|
|
380
|
+
checkValue(node.argument);
|
|
319
381
|
},
|
|
320
|
-
}
|
|
382
|
+
};
|
|
321
383
|
},
|
|
322
|
-
}
|
|
323
|
-
|
|
384
|
+
};
|
|
324
385
|
/** Resolve an imported or local binding without relying on its local spelling. */
|
|
325
386
|
const resolvedSymbol = (checker, node) => {
|
|
326
|
-
const symbol = checker.getSymbolAtLocation(ts.isPropertyAccessExpression(node) ? node.name : node)
|
|
327
|
-
return
|
|
328
|
-
}
|
|
329
|
-
|
|
387
|
+
const symbol = checker.getSymbolAtLocation(ts.isPropertyAccessExpression(node) ? node.name : node);
|
|
388
|
+
return resolveAlias(checker, symbol);
|
|
389
|
+
};
|
|
390
|
+
/** Whether a value is a TypeScript symbol (it carries numeric `flags` and an `escapedName`). */
|
|
391
|
+
const isSymbol = (value) => typeof value === "object" && value !== null && "flags" in value && typeof value.flags === "number" && "escapedName" in value;
|
|
392
|
+
/** The symbol the binder gave a node (a module's own symbol for an external-module source file), if any. */
|
|
393
|
+
const ownSymbol = (node) => {
|
|
394
|
+
const value = Reflect.get(node, "symbol");
|
|
395
|
+
return isSymbol(value) ? value : undefined;
|
|
396
|
+
};
|
|
330
397
|
/** The app's declared name comes from its matching env filename, not its kind's slot name. */
|
|
331
398
|
const appEnvNames = (filename, role) => {
|
|
332
|
-
const root = filename.slice(0, filename.lastIndexOf("/"))
|
|
333
|
-
const app = role === APP_ENV_ROLE ? filename.split("/").at(-1).slice(0, -".env.ts".length) : root.split("/").at(-2)
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
399
|
+
const root = filename.slice(0, filename.lastIndexOf("/"));
|
|
400
|
+
const app = role === APP_ENV_ROLE ? (filename.split("/").at(-1) ?? "").slice(0, -".env.ts".length) : root.split("/").at(-2);
|
|
401
|
+
if (app === undefined)
|
|
402
|
+
throw new TypeError("Cannot read properties of undefined (reading 'replace')");
|
|
403
|
+
const pascal = app.replace(/(?:^|[-_])([a-z\d])/g, (_, letter) => letter.toUpperCase());
|
|
404
|
+
return { file: `${root}/${app}.env.ts`, reader: `read${pascal}Env` };
|
|
405
|
+
};
|
|
338
406
|
/** R289: the typed app env reader owns parsing; main acquires one source and delegates once. */
|
|
339
407
|
export const appEnvRequired = {
|
|
340
408
|
meta: {
|
|
@@ -348,79 +416,98 @@ export const appEnvRequired = {
|
|
|
348
416
|
},
|
|
349
417
|
},
|
|
350
418
|
create(context) {
|
|
351
|
-
const filename = normalizePath(context.filename || context.getFilename())
|
|
352
|
-
if (isDeclarationFile(filename))
|
|
353
|
-
|
|
354
|
-
const
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
const
|
|
359
|
-
const
|
|
419
|
+
const filename = normalizePath(context.filename || context.getFilename());
|
|
420
|
+
if (isDeclarationFile(filename))
|
|
421
|
+
return {};
|
|
422
|
+
const hfs = hfsOf(context);
|
|
423
|
+
const role = appRoleOf(hfs, filename)?.entry;
|
|
424
|
+
if (role !== APP_ENV_ROLE && role !== "main.ts")
|
|
425
|
+
return {};
|
|
426
|
+
const { checker, toTs } = typed(context);
|
|
427
|
+
const names = appEnvNames(filename, role);
|
|
428
|
+
const ownedEnv = (type) => originsOfType(checker, type).some((origin) => origin.name === "EnvSource" && isOwnedBy(hfs, origin.file, "platform", "config"));
|
|
429
|
+
const envValue = (node) => node && ownedEnv(checker.getTypeAtLocation(toTs(node)));
|
|
360
430
|
const matchingReader = (node) => {
|
|
361
|
-
const symbol = resolvedSymbol(checker, toTs(node))
|
|
362
|
-
return symbol?.name === names.reader && symbol.getDeclarations()?.some((declaration) => normalizePath(declaration.getSourceFile().fileName) === names.file)
|
|
363
|
-
}
|
|
431
|
+
const symbol = resolvedSymbol(checker, toTs(node));
|
|
432
|
+
return symbol?.name === names.reader && symbol.getDeclarations()?.some((declaration) => normalizePath(declaration.getSourceFile().fileName) === names.file);
|
|
433
|
+
};
|
|
364
434
|
const envContract = (node) => {
|
|
365
|
-
const source = toTs(node)
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
const
|
|
370
|
-
|
|
371
|
-
const
|
|
435
|
+
const source = toTs(node);
|
|
436
|
+
const moduleSymbol = ownSymbol(source);
|
|
437
|
+
if (!moduleSymbol)
|
|
438
|
+
return false;
|
|
439
|
+
const exported = checker.getExportsOfModule(moduleSymbol);
|
|
440
|
+
const reader = exported.find((symbol) => symbol.name === names.reader);
|
|
441
|
+
const declaration = reader?.valueDeclaration ?? reader?.getDeclarations()?.[0];
|
|
442
|
+
if (!reader || !declaration)
|
|
443
|
+
return false;
|
|
444
|
+
const signatures = checker.getTypeOfSymbolAtLocation(reader, declaration).getCallSignatures();
|
|
372
445
|
return signatures.some((signature) => {
|
|
373
|
-
const parameters = signature.getParameters()
|
|
374
|
-
if (parameters.length !== 1 || !signature.declaration?.type)
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
const
|
|
446
|
+
const parameters = signature.getParameters();
|
|
447
|
+
if (parameters.length !== 1 || !signature.declaration?.type)
|
|
448
|
+
return false;
|
|
449
|
+
const parameter = parameters[0];
|
|
450
|
+
const valueDeclaration = parameter?.valueDeclaration;
|
|
451
|
+
if (!parameter || !valueDeclaration || !childNode(valueDeclaration, "type") || !ownedEnv(checker.getTypeOfSymbolAtLocation(parameter, valueDeclaration)))
|
|
452
|
+
return false;
|
|
453
|
+
const result = checker.getReturnTypeOfSignature(signature);
|
|
378
454
|
return result.getSymbol()?.getDeclarations()?.some((item) => ts.isInterfaceDeclaration(item)
|
|
379
|
-
&& item.getSourceFile() === source && exported.some((symbol) => symbol.name === item.name.text))
|
|
380
|
-
})
|
|
381
|
-
}
|
|
382
|
-
let sources = 0
|
|
383
|
-
let delegates = 0
|
|
384
|
-
let inline = false
|
|
385
|
-
const reported = new WeakSet()
|
|
455
|
+
&& item.getSourceFile() === source && exported.some((symbol) => symbol.name === item.name.text));
|
|
456
|
+
});
|
|
457
|
+
};
|
|
458
|
+
let sources = 0;
|
|
459
|
+
let delegates = 0;
|
|
460
|
+
let inline = false;
|
|
461
|
+
const reported = new WeakSet();
|
|
386
462
|
const reportInline = (node) => {
|
|
387
|
-
for (let parent = node; parent; parent = parent.parent)
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
463
|
+
for (let parent = node; parent; parent = parent.parent)
|
|
464
|
+
if (reported.has(parent))
|
|
465
|
+
return;
|
|
466
|
+
reported.add(node);
|
|
467
|
+
inline = true;
|
|
468
|
+
context.report({ node, messageId: "inline" });
|
|
469
|
+
};
|
|
392
470
|
return {
|
|
393
471
|
CallExpression(node) {
|
|
394
|
-
if (role !== "main.ts")
|
|
395
|
-
|
|
472
|
+
if (role !== "main.ts")
|
|
473
|
+
return;
|
|
474
|
+
const declaration = checker.getResolvedSignature(toTs(node))?.declaration;
|
|
396
475
|
if (declaration && ts.isMethodDeclaration(declaration) && declaration.name.getText() === "fromProcess"
|
|
397
476
|
&& envValue(node) && isOwnedBy(hfs, normalizePath(declaration.getSourceFile().fileName), "platform", "config")) {
|
|
398
|
-
sources += 1
|
|
399
|
-
if (sources > 1 || node.arguments.length)
|
|
400
|
-
|
|
477
|
+
sources += 1;
|
|
478
|
+
if (sources > 1 || node.arguments.length)
|
|
479
|
+
reportInline(node);
|
|
480
|
+
return;
|
|
401
481
|
}
|
|
402
482
|
if (matchingReader(node.callee) && node.arguments.length === 1 && envValue(node.arguments[0])) {
|
|
403
|
-
delegates += 1
|
|
404
|
-
if (delegates > 1)
|
|
405
|
-
|
|
483
|
+
delegates += 1;
|
|
484
|
+
if (delegates > 1)
|
|
485
|
+
reportInline(node);
|
|
486
|
+
return;
|
|
406
487
|
}
|
|
407
|
-
const callee = unwrap(node.callee)
|
|
408
|
-
if (callee.type === "MemberExpression" && envValue(callee.object) || node.arguments.some(envValue))
|
|
488
|
+
const callee = unwrap(node.callee);
|
|
489
|
+
if (callee.type === "MemberExpression" && envValue(callee.object) || node.arguments.some(envValue))
|
|
490
|
+
reportInline(node);
|
|
409
491
|
},
|
|
410
492
|
MemberExpression(node) {
|
|
411
|
-
if (role !== "main.ts")
|
|
412
|
-
|
|
413
|
-
if (
|
|
493
|
+
if (role !== "main.ts")
|
|
494
|
+
return;
|
|
495
|
+
if (memberName(node) === "env" && lastName(node.object) === "process")
|
|
496
|
+
reportInline(node);
|
|
497
|
+
if (envValue(node.object) && !node.parent?.type.startsWith("CallExpression") && memberName(node) !== "fromProcess")
|
|
498
|
+
reportInline(node);
|
|
414
499
|
},
|
|
415
500
|
"Program:exit"(node) {
|
|
416
501
|
if (role === APP_ENV_ROLE) {
|
|
417
|
-
if (!envContract(node))
|
|
418
|
-
|
|
502
|
+
if (!envContract(node))
|
|
503
|
+
context.report({ node, messageId: "shape", data: names });
|
|
504
|
+
}
|
|
505
|
+
else if (!inline && (sources !== 1 || delegates !== 1))
|
|
506
|
+
context.report({ node, messageId: "delegate", data: names });
|
|
419
507
|
},
|
|
420
|
-
}
|
|
508
|
+
};
|
|
421
509
|
},
|
|
422
|
-
}
|
|
423
|
-
|
|
510
|
+
};
|
|
424
511
|
/** R289: module lists in the app root contain only spreads of its own compose groups. */
|
|
425
512
|
export const appModuleListInline = {
|
|
426
513
|
meta: {
|
|
@@ -432,43 +519,51 @@ export const appModuleListInline = {
|
|
|
432
519
|
},
|
|
433
520
|
},
|
|
434
521
|
create(context) {
|
|
435
|
-
const filename = normalizePath(context.filename || context.getFilename())
|
|
436
|
-
if (isDeclarationFile(filename))
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
const
|
|
522
|
+
const filename = normalizePath(context.filename || context.getFilename());
|
|
523
|
+
if (isDeclarationFile(filename))
|
|
524
|
+
return {};
|
|
525
|
+
const hfs = hfsOf(context);
|
|
526
|
+
if (appRoleOf(hfs, filename)?.entry !== "app.module.ts")
|
|
527
|
+
return {};
|
|
528
|
+
const { checker, toTs } = typed(context);
|
|
529
|
+
const { contains } = compositionTypes(checker);
|
|
530
|
+
const composeRoot = filename.slice(0, filename.lastIndexOf("/")) + "/compose/";
|
|
442
531
|
const groupSpread = (node) => {
|
|
443
|
-
if (node.type !== "SpreadElement")
|
|
444
|
-
|
|
445
|
-
const
|
|
446
|
-
const
|
|
532
|
+
if (node.type !== "SpreadElement")
|
|
533
|
+
return false;
|
|
534
|
+
const value = unwrap(node.argument);
|
|
535
|
+
const reference = value.type === "CallExpression" ? unwrap(value.callee) : value;
|
|
536
|
+
const symbol = resolvedSymbol(checker, toTs(reference));
|
|
447
537
|
return symbol?.getDeclarations()?.some((declaration) => {
|
|
448
|
-
const file = normalizePath(declaration.getSourceFile().fileName)
|
|
449
|
-
return file.startsWith(composeRoot) && appRoleOf(hfs, file)?.entry === "compose/<area>.ts"
|
|
450
|
-
}) ?? false
|
|
451
|
-
}
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
538
|
+
const file = normalizePath(declaration.getSourceFile().fileName);
|
|
539
|
+
return file.startsWith(composeRoot) && appRoleOf(hfs, file)?.entry === "compose/<area>.ts";
|
|
540
|
+
}) ?? false;
|
|
541
|
+
};
|
|
542
|
+
const providerTokens = ["APP_GUARD", "APP_FILTER"];
|
|
543
|
+
const globalProvider = (element) => {
|
|
544
|
+
const node = unwrap(element);
|
|
545
|
+
if (node?.type !== "ObjectExpression")
|
|
546
|
+
return false;
|
|
547
|
+
const binding = node.properties.find((property) => property.type === "Property" && keyName(property.key) === "provide");
|
|
548
|
+
const value = binding && unwrap(binding.value);
|
|
549
|
+
if (!value || !providerTokens.includes(resolvedSymbol(checker, toTs(value))?.name))
|
|
550
|
+
return false;
|
|
551
|
+
return packageOfExport(context, value) === "@nestjs/core";
|
|
552
|
+
};
|
|
460
553
|
return {
|
|
461
554
|
ArrayExpression(node) {
|
|
462
|
-
const parent = node.parent
|
|
463
|
-
const key = parent?.type === "Property" ? parent.computed ? staticText(parent.key) : keyName(parent.key) : null
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
555
|
+
const parent = node.parent;
|
|
556
|
+
const key = parent?.type === "Property" ? parent.computed ? staticText(parent.key) : keyName(parent.key) : null;
|
|
557
|
+
const listKeys = [...COMPOSITION_KEYS, "providers"];
|
|
558
|
+
if (!listKeys.includes(key) && !contains(checker.getTypeAtLocation(toTs(node))))
|
|
559
|
+
return;
|
|
560
|
+
const violation = node.elements.find((element) => !element || !groupSpread(element) && !(key === "providers" && globalProvider(element)));
|
|
561
|
+
if (violation || node.elements.includes(null))
|
|
562
|
+
context.report({ node: violation ?? node, messageId: "inline" });
|
|
467
563
|
},
|
|
468
|
-
}
|
|
564
|
+
};
|
|
469
565
|
},
|
|
470
|
-
}
|
|
471
|
-
|
|
566
|
+
};
|
|
472
567
|
/** Each composition file of an app stays within the line budget its app slot names. */
|
|
473
568
|
export const appFileBudget = {
|
|
474
569
|
meta: {
|
|
@@ -480,28 +575,30 @@ export const appFileBudget = {
|
|
|
480
575
|
},
|
|
481
576
|
},
|
|
482
577
|
create(context) {
|
|
483
|
-
const filename = normalizePath(context.filename || context.getFilename())
|
|
484
|
-
if (isDeclarationFile(filename))
|
|
485
|
-
|
|
486
|
-
const
|
|
487
|
-
const
|
|
488
|
-
|
|
578
|
+
const filename = normalizePath(context.filename || context.getFilename());
|
|
579
|
+
if (isDeclarationFile(filename))
|
|
580
|
+
return {};
|
|
581
|
+
const hfs = hfsOf(context);
|
|
582
|
+
const role = appRoleOf(hfs, filename);
|
|
583
|
+
const max = role ? hfs.slot(role.slot)?.budget?.[role.entry] : undefined;
|
|
584
|
+
if (!role || max === undefined || !Number.isInteger(max))
|
|
585
|
+
return {};
|
|
489
586
|
const fix = role.entry === APP_ENV_ROLE
|
|
490
587
|
? "Keep typed, fail-fast environment parsing only here; move module composition into `compose/<area>.ts` and business code into its owning module."
|
|
491
588
|
: role.entry === APP_OPTIONS_ROLE
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
589
|
+
? "Keep options types and port bindings here; move environment parsing into `<app>.env.ts` and module, queue or scheduler lists into `compose/<area>.ts`."
|
|
590
|
+
: role.entry === "main.ts"
|
|
591
|
+
? "Move environment parsing into `<app>.env.ts` and module composition into `compose/<area>.ts`; keep the bootstrap here."
|
|
592
|
+
: "Move one area of the composition into its own group `apps/<app>/src/compose/<area>.ts` and spread it in `app.module.ts`.";
|
|
496
593
|
return {
|
|
497
594
|
"Program:exit"(node) {
|
|
498
|
-
const lines = lineCount((context.sourceCode || context.getSourceCode()).text)
|
|
499
|
-
if (lines > max)
|
|
595
|
+
const lines = lineCount((context.sourceCode || context.getSourceCode()).text);
|
|
596
|
+
if (lines > max)
|
|
597
|
+
context.report({ node, loc: { line: 1, column: 0 }, messageId: "over", data: { role: role.entry, lines, max, slot: role.slot, fix } });
|
|
500
598
|
},
|
|
501
|
-
}
|
|
599
|
+
};
|
|
502
600
|
},
|
|
503
|
-
}
|
|
504
|
-
|
|
601
|
+
};
|
|
505
602
|
/** The rules this law contributes to the plugin. */
|
|
506
603
|
export const rules = {
|
|
507
604
|
"app-options-composition-free": appOptionsCompositionFree,
|
|
@@ -509,8 +606,7 @@ export const rules = {
|
|
|
509
606
|
"app-env-required": appEnvRequired,
|
|
510
607
|
"app-module-list-inline": appModuleListInline,
|
|
511
608
|
"app-file-budget": appFileBudget,
|
|
512
|
-
}
|
|
513
|
-
|
|
609
|
+
};
|
|
514
610
|
/** Every rule starts at error; an app already over a budget migrates its lists into compose/. */
|
|
515
611
|
export const recommended = {
|
|
516
612
|
"starci-be/app-options-composition-free": "error",
|
|
@@ -518,4 +614,4 @@ export const recommended = {
|
|
|
518
614
|
"starci-be/app-env-required": "error",
|
|
519
615
|
"starci-be/app-module-list-inline": "error",
|
|
520
616
|
"starci-be/app-file-budget": "error",
|
|
521
|
-
}
|
|
617
|
+
};
|