@starci/eslint-canon-be 3.4.57 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +11 -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.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 +17 -8
- package/runtime/knowledge/hfs/canon-pins.yaml +22 -14
- package/runtime/knowledge/hfs/rules.yaml +23 -0
- package/runtime/scripts/lib/package-at.mjs +5 -5
- 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
|
@@ -29,18 +29,17 @@
|
|
|
29
29
|
* - `no-module-let` refuses mutable module-level state (`let` and `var` at the top of a file).
|
|
30
30
|
* - `one-module-per-file` allows one `@Module` class in a file, so one transport or application module has one home.
|
|
31
31
|
*/
|
|
32
|
-
import { existsSync } from "node:fs"
|
|
33
|
-
import { dirname, join } from "node:path"
|
|
34
|
-
import ts from "typescript"
|
|
35
|
-
import { decoratorName, keyName, walk } from "./lib/ast.
|
|
36
|
-
import { importsFrom } from "./lib/declared.
|
|
37
|
-
import { isAppComposition } from "./lib/app-roles.
|
|
38
|
-
import { hfsOf, inTestWorld } from "./lib/hfs.
|
|
39
|
-
import { isDeclarationFile, isSpecFile, normalizePath } from "./lib/path.
|
|
40
|
-
import { typed } from "./lib/types.
|
|
41
|
-
|
|
42
|
-
const isModuleClass = (node) => node.decorators?.some((decorator) => decoratorName(decorator) === "Module") ?? false
|
|
43
|
-
|
|
32
|
+
import { existsSync } from "node:fs";
|
|
33
|
+
import { dirname, join } from "node:path";
|
|
34
|
+
import ts from "typescript";
|
|
35
|
+
import { decoratorName, keyName, walk } from "./lib/ast.js";
|
|
36
|
+
import { importsFrom } from "./lib/declared.js";
|
|
37
|
+
import { isAppComposition } from "./lib/app-roles.js";
|
|
38
|
+
import { hfsOf, inTestWorld } from "./lib/hfs.js";
|
|
39
|
+
import { isDeclarationFile, isSpecFile, normalizePath } from "./lib/path.js";
|
|
40
|
+
import { typed } from "./lib/types.js";
|
|
41
|
+
import { isNode } from "./lib/rule.js";
|
|
42
|
+
const isModuleClass = (node) => node.decorators?.some((decorator) => decoratorName(decorator) === "Module") ?? false;
|
|
44
43
|
/** `@Global()` is banned everywhere: globality is decided at the app root. */
|
|
45
44
|
export const noGlobalDecorator = {
|
|
46
45
|
meta: {
|
|
@@ -52,34 +51,32 @@ export const noGlobalDecorator = {
|
|
|
52
51
|
},
|
|
53
52
|
},
|
|
54
53
|
create(context) {
|
|
55
|
-
if (isDeclarationFile(context.filename || context.getFilename()))
|
|
56
|
-
|
|
54
|
+
if (isDeclarationFile(context.filename || context.getFilename()))
|
|
55
|
+
return {};
|
|
56
|
+
let aliases = new Map();
|
|
57
57
|
return {
|
|
58
58
|
Program(node) {
|
|
59
|
-
aliases = importsFrom(node, () => true)
|
|
59
|
+
aliases = importsFrom(node, () => true);
|
|
60
60
|
},
|
|
61
61
|
Decorator(node) {
|
|
62
|
-
const expression = node.expression.type === "CallExpression" ? node.expression.callee : node.expression
|
|
63
|
-
const name = expression.type === "Identifier" ? expression.name : null
|
|
64
|
-
const namespaced = expression.type === "MemberExpression" && !expression.computed && keyName(expression.property) === "Global" && expression.object.type === "Identifier" && aliases.get(expression.object.name) === "*"
|
|
65
|
-
if (name === "Global" || (name !== null && aliases.get(name) === "Global") || namespaced)
|
|
62
|
+
const expression = node.expression.type === "CallExpression" ? node.expression.callee : node.expression;
|
|
63
|
+
const name = expression.type === "Identifier" ? expression.name : null;
|
|
64
|
+
const namespaced = expression.type === "MemberExpression" && !expression.computed && keyName(expression.property) === "Global" && expression.object.type === "Identifier" && aliases.get(expression.object.name) === "*";
|
|
65
|
+
if (name === "Global" || (name !== null && aliases.get(name) === "Global") || namespaced)
|
|
66
|
+
context.report({ node, messageId: "global" });
|
|
66
67
|
},
|
|
67
|
-
}
|
|
68
|
+
};
|
|
68
69
|
},
|
|
69
|
-
}
|
|
70
|
-
|
|
70
|
+
};
|
|
71
71
|
/** The app composition files: `apps/<app>/src/app.module.ts` and its groups `compose/<area>.ts`, judged by the app slot's entries. */
|
|
72
|
-
const isAppModule = isAppComposition
|
|
73
|
-
|
|
72
|
+
const isAppModule = isAppComposition;
|
|
74
73
|
/**
|
|
75
74
|
* The test world (slot `be.tests.world`, `src/tests/world`) is the TEST COMPOSITION ROOT: `use-test-world.ts` assembles
|
|
76
75
|
* capability modules with `isGlobal: true` the way `apps/<app>/src/app.module.ts` does in production. A spec (integration,
|
|
77
76
|
* contract, e2e) does not compose and stays refused: it calls `useTestWorld(...)` only.
|
|
78
77
|
*/
|
|
79
|
-
const isWorld = inTestWorld
|
|
80
|
-
|
|
81
|
-
const isTrue = (node) => node?.type === "Literal" && node.value === true
|
|
82
|
-
|
|
78
|
+
const isWorld = inTestWorld;
|
|
79
|
+
const isTrue = (node) => node?.type === "Literal" && node.value === true;
|
|
83
80
|
/** `isGlobal: true` appears only in the app's `app.module.ts`. */
|
|
84
81
|
export const isGlobalOnlyInApp = {
|
|
85
82
|
meta: {
|
|
@@ -91,35 +88,39 @@ export const isGlobalOnlyInApp = {
|
|
|
91
88
|
},
|
|
92
89
|
},
|
|
93
90
|
create(context) {
|
|
94
|
-
const filename = normalizePath(context.filename || context.getFilename())
|
|
95
|
-
if (isDeclarationFile(filename) || isAppModule(hfsOf(context), filename) || isWorld(hfsOf(context), filename))
|
|
91
|
+
const filename = normalizePath(context.filename || context.getFilename());
|
|
92
|
+
if (isDeclarationFile(filename) || isAppModule(hfsOf(context), filename) || isWorld(hfsOf(context), filename))
|
|
93
|
+
return {};
|
|
96
94
|
return {
|
|
97
95
|
Property(node) {
|
|
98
|
-
if (node.computed && node.key.type !== "Literal")
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
96
|
+
if (node.computed && node.key.type !== "Literal")
|
|
97
|
+
return;
|
|
98
|
+
if (!isTrue(node.value))
|
|
99
|
+
return;
|
|
100
|
+
const key = keyName(node.key);
|
|
101
|
+
if (key === "isGlobal")
|
|
102
|
+
context.report({ node, messageId: "isGlobal", data: { key } });
|
|
102
103
|
// a dynamic module literal `{ module: X, global: true }` is the same global registration
|
|
103
104
|
else if (key === "global" && node.parent?.type === "ObjectExpression" && node.parent.properties.some((item) => item.type === "Property" && keyName(item.key) === "module")) {
|
|
104
|
-
context.report({ node, messageId: "isGlobal", data: { key } })
|
|
105
|
+
context.report({ node, messageId: "isGlobal", data: { key } });
|
|
105
106
|
}
|
|
106
107
|
},
|
|
107
108
|
AssignmentExpression(node) {
|
|
108
109
|
if (node.left.type === "MemberExpression" && !node.left.computed && keyName(node.left.property) === "isGlobal" && isTrue(node.right)) {
|
|
109
|
-
context.report({ node, messageId: "isGlobal", data: { key: "isGlobal" } })
|
|
110
|
+
context.report({ node, messageId: "isGlobal", data: { key: "isGlobal" } });
|
|
110
111
|
}
|
|
111
112
|
},
|
|
112
|
-
}
|
|
113
|
+
};
|
|
113
114
|
},
|
|
114
|
-
}
|
|
115
|
-
|
|
115
|
+
};
|
|
116
116
|
/** The module class an `imports` entry names: `X` or `X.register(...)`; null for anything else. */
|
|
117
117
|
const importedModule = (entry) => {
|
|
118
|
-
if (entry.type === "Identifier")
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
118
|
+
if (entry.type === "Identifier")
|
|
119
|
+
return entry;
|
|
120
|
+
if (entry.type === "CallExpression" && entry.callee.type === "MemberExpression" && !entry.callee.computed && entry.callee.object.type === "Identifier")
|
|
121
|
+
return entry.callee.object;
|
|
122
|
+
return null;
|
|
123
|
+
};
|
|
123
124
|
/** A module never imports another owner's module: a capability is reached through its `Inject*()` decorators. */
|
|
124
125
|
export const noCrossOwnerModuleImport = {
|
|
125
126
|
meta: {
|
|
@@ -131,38 +132,45 @@ export const noCrossOwnerModuleImport = {
|
|
|
131
132
|
},
|
|
132
133
|
},
|
|
133
134
|
create(context) {
|
|
134
|
-
const filename = normalizePath(context.filename || context.getFilename())
|
|
135
|
-
if (isDeclarationFile(filename))
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
135
|
+
const filename = normalizePath(context.filename || context.getFilename());
|
|
136
|
+
if (isDeclarationFile(filename))
|
|
137
|
+
return {};
|
|
138
|
+
const hfs = hfsOf(context);
|
|
139
|
+
if ((hfs.slotOf(filename) ?? "").startsWith("be.app."))
|
|
140
|
+
return {};
|
|
141
|
+
const { checker, toTs } = typed(context);
|
|
142
|
+
const here = hfs.ownerOf(filename);
|
|
140
143
|
const declaringOwner = (identifier) => {
|
|
141
|
-
const tsNode = toTs(identifier)
|
|
142
|
-
let symbol = tsNode ? checker.getSymbolAtLocation(tsNode) : undefined
|
|
143
|
-
if (symbol && symbol.flags & ts.SymbolFlags.Alias)
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
144
|
+
const tsNode = toTs(identifier);
|
|
145
|
+
let symbol = tsNode ? checker.getSymbolAtLocation(tsNode) : undefined;
|
|
146
|
+
if (symbol && symbol.flags & ts.SymbolFlags.Alias)
|
|
147
|
+
symbol = checker.getAliasedSymbol(symbol);
|
|
148
|
+
const declaration = symbol?.declarations?.[0];
|
|
149
|
+
return declaration ? hfs.ownerOf(String(declaration.getSourceFile().fileName).replace(/\\/g, "/")) : null;
|
|
150
|
+
};
|
|
147
151
|
return {
|
|
148
152
|
Decorator(node) {
|
|
149
|
-
if (decoratorName(node) !== "Module" || node.expression.type !== "CallExpression")
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
153
|
+
if (decoratorName(node) !== "Module" || node.expression.type !== "CallExpression")
|
|
154
|
+
return;
|
|
155
|
+
const metadata = node.expression.arguments[0];
|
|
156
|
+
if (metadata?.type !== "ObjectExpression")
|
|
157
|
+
return;
|
|
158
|
+
const imports = metadata.properties.find((item) => item.type === "Property" && !item.computed && keyName(item.key) === "imports");
|
|
159
|
+
if (imports?.value.type !== "ArrayExpression")
|
|
160
|
+
return;
|
|
154
161
|
for (const entry of imports.value.elements) {
|
|
155
|
-
const reference = entry ? importedModule(entry) : null
|
|
156
|
-
if (!reference)
|
|
162
|
+
const reference = entry ? importedModule(entry) : null;
|
|
163
|
+
if (!entry || !reference)
|
|
164
|
+
continue;
|
|
157
165
|
// a package module is R90's concern; the same owner is one owner (a transport module and its feature's application module, a representative and its sub-modules)
|
|
158
|
-
const there = declaringOwner(reference)
|
|
159
|
-
if (there !== null && there !== here)
|
|
166
|
+
const there = declaringOwner(reference);
|
|
167
|
+
if (there !== null && there !== here)
|
|
168
|
+
context.report({ node: entry, messageId: "cross", data: { name: reference.name } });
|
|
160
169
|
}
|
|
161
170
|
},
|
|
162
|
-
}
|
|
171
|
+
};
|
|
163
172
|
},
|
|
164
|
-
}
|
|
165
|
-
|
|
173
|
+
};
|
|
166
174
|
/** A configurable module builder names its options type. */
|
|
167
175
|
export const typedModuleDefinition = {
|
|
168
176
|
meta: {
|
|
@@ -174,19 +182,22 @@ export const typedModuleDefinition = {
|
|
|
174
182
|
},
|
|
175
183
|
},
|
|
176
184
|
create(context) {
|
|
177
|
-
if (isDeclarationFile(context.filename || context.getFilename()))
|
|
185
|
+
if (isDeclarationFile(context.filename || context.getFilename()))
|
|
186
|
+
return {};
|
|
178
187
|
return {
|
|
179
188
|
NewExpression(node) {
|
|
180
|
-
if (node.callee.type !== "Identifier" || node.callee.name !== "ConfigurableModuleBuilder")
|
|
181
|
-
|
|
182
|
-
|
|
189
|
+
if (node.callee.type !== "Identifier" || node.callee.name !== "ConfigurableModuleBuilder")
|
|
190
|
+
return;
|
|
191
|
+
// `typeParameters` is the older parser's name for the same type arguments
|
|
192
|
+
const typeArguments = node.typeArguments ?? Reflect.get(node, "typeParameters");
|
|
193
|
+
const typedArgs = isNode(typeArguments) && typeArguments.type === "TSTypeParameterInstantiation" && typeArguments.params?.length > 0;
|
|
194
|
+
if (!typedArgs)
|
|
195
|
+
context.report({ node, messageId: "untyped", data: { example: "Capability" } });
|
|
183
196
|
},
|
|
184
|
-
}
|
|
197
|
+
};
|
|
185
198
|
},
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const OTHER_FACTORIES = new Set(["registerAsync", "forRoot", "forRootAsync", "forFeature", "forFeatureAsync"])
|
|
189
|
-
|
|
199
|
+
};
|
|
200
|
+
const OTHER_FACTORIES = new Set(["registerAsync", "forRoot", "forRootAsync", "forFeature", "forFeatureAsync"]);
|
|
190
201
|
/** The one dynamic-module factory is `static register`. */
|
|
191
202
|
export const staticModuleRegister = {
|
|
192
203
|
meta: {
|
|
@@ -199,32 +210,35 @@ export const staticModuleRegister = {
|
|
|
199
210
|
},
|
|
200
211
|
},
|
|
201
212
|
create(context) {
|
|
202
|
-
if (isDeclarationFile(context.filename || context.getFilename()))
|
|
213
|
+
if (isDeclarationFile(context.filename || context.getFilename()))
|
|
214
|
+
return {};
|
|
203
215
|
return {
|
|
204
216
|
ClassDeclaration(node) {
|
|
205
|
-
if (!isModuleClass(node))
|
|
217
|
+
if (!isModuleClass(node))
|
|
218
|
+
return;
|
|
206
219
|
for (const member of node.body.body) {
|
|
207
|
-
if ((member.type !== "MethodDefinition" && member.type !== "PropertyDefinition") || member.computed || member.key.type !== "Identifier")
|
|
208
|
-
|
|
209
|
-
|
|
220
|
+
if ((member.type !== "MethodDefinition" && member.type !== "PropertyDefinition") || member.computed || member.key.type !== "Identifier")
|
|
221
|
+
continue;
|
|
222
|
+
if (OTHER_FACTORIES.has(member.key.name))
|
|
223
|
+
context.report({ node: member, messageId: "otherName", data: { name: member.key.name } });
|
|
224
|
+
else if (member.type === "MethodDefinition" && member.key.name === "register" && !member.static)
|
|
225
|
+
context.report({ node: member, messageId: "notStatic" });
|
|
210
226
|
}
|
|
211
227
|
},
|
|
212
|
-
}
|
|
228
|
+
};
|
|
213
229
|
},
|
|
214
|
-
}
|
|
215
|
-
|
|
230
|
+
};
|
|
216
231
|
/** Decorators that make a class a provider the container builds. */
|
|
217
|
-
const PROVIDER_DECORATORS = new Set(["Injectable", "Controller", "Resolver", "CommandHandler", "QueryHandler"])
|
|
218
|
-
|
|
232
|
+
const PROVIDER_DECORATORS = new Set(["Injectable", "Controller", "Resolver", "CommandHandler", "QueryHandler"]);
|
|
219
233
|
/** True when the declaration carries a provider decorator. */
|
|
220
234
|
const isProviderDeclaration = (declaration) => {
|
|
221
|
-
if (!ts.isClassDeclaration(declaration) && !ts.isClassExpression(declaration))
|
|
235
|
+
if (!ts.isClassDeclaration(declaration) && !ts.isClassExpression(declaration))
|
|
236
|
+
return false;
|
|
222
237
|
return (ts.getDecorators(declaration) ?? []).some((decorator) => {
|
|
223
|
-
const expression = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression
|
|
224
|
-
return ts.isIdentifier(expression) && PROVIDER_DECORATORS.has(expression.text)
|
|
225
|
-
})
|
|
226
|
-
}
|
|
227
|
-
|
|
238
|
+
const expression = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression;
|
|
239
|
+
return ts.isIdentifier(expression) && PROVIDER_DECORATORS.has(expression.text);
|
|
240
|
+
});
|
|
241
|
+
};
|
|
228
242
|
/** Providers are built by the container, not by `new` (a spec constructs its subject with typed doubles). */
|
|
229
243
|
export const noNewInjectable = {
|
|
230
244
|
meta: {
|
|
@@ -236,21 +250,24 @@ export const noNewInjectable = {
|
|
|
236
250
|
},
|
|
237
251
|
},
|
|
238
252
|
create(context) {
|
|
239
|
-
const filename = normalizePath(context.filename || context.getFilename())
|
|
240
|
-
if (isDeclarationFile(filename) || isSpecFile(filename) || (hfsOf(context).slotOf(filename) ?? "").startsWith("be.tests."))
|
|
241
|
-
|
|
253
|
+
const filename = normalizePath(context.filename || context.getFilename());
|
|
254
|
+
if (isDeclarationFile(filename) || isSpecFile(filename) || (hfsOf(context).slotOf(filename) ?? "").startsWith("be.tests."))
|
|
255
|
+
return {};
|
|
256
|
+
const { checker, toTs } = typed(context);
|
|
242
257
|
return {
|
|
243
258
|
NewExpression(node) {
|
|
244
|
-
if (node.callee.type !== "Identifier")
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
if (symbol
|
|
259
|
+
if (node.callee.type !== "Identifier")
|
|
260
|
+
return;
|
|
261
|
+
const tsNode = toTs(node.callee);
|
|
262
|
+
let symbol = tsNode ? checker.getSymbolAtLocation(tsNode) : undefined;
|
|
263
|
+
if (symbol && symbol.flags & ts.SymbolFlags.Alias)
|
|
264
|
+
symbol = checker.getAliasedSymbol(symbol);
|
|
265
|
+
if (symbol?.declarations?.some(isProviderDeclaration))
|
|
266
|
+
context.report({ node, messageId: "construct", data: { name: node.callee.name } });
|
|
249
267
|
},
|
|
250
|
-
}
|
|
268
|
+
};
|
|
251
269
|
},
|
|
252
|
-
}
|
|
253
|
-
|
|
270
|
+
};
|
|
254
271
|
/** No mutable state at module scope. */
|
|
255
272
|
export const noModuleLet = {
|
|
256
273
|
meta: {
|
|
@@ -262,21 +279,23 @@ export const noModuleLet = {
|
|
|
262
279
|
},
|
|
263
280
|
},
|
|
264
281
|
create(context) {
|
|
265
|
-
if (isDeclarationFile(context.filename || context.getFilename()))
|
|
282
|
+
if (isDeclarationFile(context.filename || context.getFilename()))
|
|
283
|
+
return {};
|
|
266
284
|
const check = (node) => {
|
|
267
|
-
if (node.type === "VariableDeclaration" && node.kind !== "const")
|
|
268
|
-
|
|
285
|
+
if (node.type === "VariableDeclaration" && node.kind !== "const")
|
|
286
|
+
context.report({ node, messageId: "mutable", data: { kind: node.kind } });
|
|
287
|
+
};
|
|
269
288
|
return {
|
|
270
289
|
Program(node) {
|
|
271
290
|
for (const statement of node.body) {
|
|
272
|
-
check(statement)
|
|
273
|
-
if (statement.type === "ExportNamedDeclaration" && statement.declaration)
|
|
291
|
+
check(statement);
|
|
292
|
+
if (statement.type === "ExportNamedDeclaration" && statement.declaration)
|
|
293
|
+
check(statement.declaration);
|
|
274
294
|
}
|
|
275
295
|
},
|
|
276
|
-
}
|
|
296
|
+
};
|
|
277
297
|
},
|
|
278
|
-
}
|
|
279
|
-
|
|
298
|
+
};
|
|
280
299
|
/** One `@Module` class per file. */
|
|
281
300
|
export const oneModulePerFile = {
|
|
282
301
|
meta: {
|
|
@@ -288,92 +307,101 @@ export const oneModulePerFile = {
|
|
|
288
307
|
},
|
|
289
308
|
},
|
|
290
309
|
create(context) {
|
|
291
|
-
if (isDeclarationFile(context.filename || context.getFilename()))
|
|
292
|
-
|
|
310
|
+
if (isDeclarationFile(context.filename || context.getFilename()))
|
|
311
|
+
return {};
|
|
312
|
+
let seen = 0;
|
|
293
313
|
return {
|
|
294
314
|
ClassDeclaration(node) {
|
|
295
|
-
if (!isModuleClass(node))
|
|
296
|
-
|
|
297
|
-
|
|
315
|
+
if (!isModuleClass(node))
|
|
316
|
+
return;
|
|
317
|
+
seen += 1;
|
|
318
|
+
if (seen > 1)
|
|
319
|
+
context.report({ node, messageId: "many" });
|
|
298
320
|
},
|
|
299
|
-
}
|
|
321
|
+
};
|
|
300
322
|
},
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const CAPABILITY_TIERS = new Set(["domain", "platform", "integrations", "projections"])
|
|
323
|
+
};
|
|
324
|
+
const CAPABILITY_TIERS = new Set(["domain", "platform", "integrations", "projections"]);
|
|
304
325
|
/** The tiers whose `<x>.module.ts` files are modules of the product: every one of them has a module definition. */
|
|
305
|
-
const MODULE_TIERS = new Set(["feature", "domain", "platform", "integrations", "projections", "queues", "events"])
|
|
306
|
-
|
|
326
|
+
const MODULE_TIERS = new Set(["feature", "domain", "platform", "integrations", "projections", "queues", "events"]);
|
|
307
327
|
/** `{ inside, name }`: the owner-relative path of a file and the owner's directory name, or null outside an owner. */
|
|
308
328
|
const insideOwner = (hfs, filename) => {
|
|
309
|
-
const root = hfs.ownerOf(filename)
|
|
310
|
-
if (!root)
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
|
|
329
|
+
const root = hfs.ownerOf(filename);
|
|
330
|
+
if (!root)
|
|
331
|
+
return null;
|
|
332
|
+
return { inside: hfs.relative(filename).slice(root.length + 1), name: root.split("/").at(-1), tier: hfs.tierOf(filename) };
|
|
333
|
+
};
|
|
314
334
|
/** True for `static register(options: typeof OPTIONS_TYPE): DynamicModule`, the one allowed override. */
|
|
315
335
|
const isRegisterOverride = (member) => {
|
|
316
|
-
if (!member.static)
|
|
317
|
-
|
|
318
|
-
const
|
|
319
|
-
const
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
336
|
+
if (!member.static)
|
|
337
|
+
return false;
|
|
338
|
+
const fn = member.value;
|
|
339
|
+
const parameter = fn.params?.[0];
|
|
340
|
+
const annotation = parameter?.type === "Identifier" ? parameter.typeAnnotation?.typeAnnotation : null;
|
|
341
|
+
const returns = fn.returnType?.typeAnnotation;
|
|
342
|
+
return (fn.params.length === 1 &&
|
|
323
343
|
annotation?.type === "TSTypeQuery" &&
|
|
324
344
|
annotation.exprName.type === "Identifier" &&
|
|
325
345
|
annotation.exprName.name === "OPTIONS_TYPE" &&
|
|
326
346
|
returns?.type === "TSTypeReference" &&
|
|
327
347
|
returns.typeName.type === "Identifier" &&
|
|
328
|
-
returns.typeName.name === "DynamicModule"
|
|
329
|
-
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/** The method names a builder chain calls, from the `new ConfigurableModuleBuilder<...>()` outward, with each call. */
|
|
348
|
+
returns.typeName.name === "DynamicModule");
|
|
349
|
+
};
|
|
333
350
|
const builderChain = (newExpression) => {
|
|
334
|
-
const calls = []
|
|
335
|
-
|
|
336
|
-
|
|
351
|
+
const calls = [];
|
|
352
|
+
let node = newExpression;
|
|
353
|
+
for (;;) {
|
|
354
|
+
const member = node.parent;
|
|
355
|
+
if (member?.type !== "MemberExpression" || member.object !== node)
|
|
356
|
+
break;
|
|
357
|
+
const call = member.parent;
|
|
358
|
+
if (call?.type !== "CallExpression")
|
|
359
|
+
break;
|
|
360
|
+
calls.push({ name: keyName(member.property), call });
|
|
361
|
+
node = call;
|
|
337
362
|
}
|
|
338
|
-
return calls
|
|
339
|
-
}
|
|
340
|
-
|
|
363
|
+
return calls;
|
|
364
|
+
};
|
|
341
365
|
/** True when the argument is the string literal `register`. */
|
|
342
|
-
const isRegisterName = (node) => node?.type === "Literal" && node.value === "register"
|
|
343
|
-
|
|
366
|
+
const isRegisterName = (node) => node?.type === "Literal" && node.value === "register";
|
|
344
367
|
/** The reasons a builder chain is not the module definition of its kind (an empty list when it is). */
|
|
345
368
|
const chainFaults = (calls, representative) => {
|
|
346
|
-
const missing = []
|
|
347
|
-
const extras = calls.find((entry) => entry.name === "setExtras")
|
|
348
|
-
const named = calls.find((entry) => entry.name === "setClassMethodName")
|
|
369
|
+
const missing = [];
|
|
370
|
+
const extras = calls.find((entry) => entry.name === "setExtras");
|
|
371
|
+
const named = calls.find((entry) => entry.name === "setClassMethodName");
|
|
349
372
|
if (representative) {
|
|
350
|
-
const defaults = extras?.call.arguments[0]
|
|
351
|
-
const localByDefault =
|
|
352
|
-
defaults
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
if (named && !isRegisterName(named.call.arguments[0]))
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
373
|
+
const defaults = extras?.call.arguments[0];
|
|
374
|
+
const localByDefault = defaults?.type === "ObjectExpression" &&
|
|
375
|
+
defaults.properties.some((item) => item.type === "Property" && keyName(item.key) === "isGlobal" && item.value.type === "Literal" && item.value.value === false);
|
|
376
|
+
if (!localByDefault)
|
|
377
|
+
missing.push("`.setExtras({ isGlobal: false }, ...)` is missing or does not default `isGlobal` to a literal `false`");
|
|
378
|
+
if (named && !isRegisterName(named.call.arguments[0]))
|
|
379
|
+
missing.push('`.setClassMethodName(...)` names a factory other than "register"');
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
if (extras)
|
|
383
|
+
missing.push("a sub-module, feature or transport module is never global, so it has no `.setExtras(...)`");
|
|
384
|
+
if (!named || !isRegisterName(named.call.arguments[0]))
|
|
385
|
+
missing.push('`.setClassMethodName("register")` is missing');
|
|
359
386
|
}
|
|
360
|
-
if (calls.at(-1)?.name !== "build")
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
387
|
+
if (calls.at(-1)?.name !== "build")
|
|
388
|
+
missing.push("the chain does not end in `.build()`");
|
|
389
|
+
return missing;
|
|
390
|
+
};
|
|
364
391
|
/** The module scope of a file: its kind, tier and name when it is a `<x>.module.ts` or `<x>.module-definition.ts` of a product tier, else null. */
|
|
365
392
|
const moduleFileOf = (hfs, filename) => {
|
|
366
|
-
const base = filename.split("/").at(-1)
|
|
367
|
-
const suffix = base.endsWith(".module-definition.ts") ? ".module-definition.ts" : base.endsWith(".module.ts") ? ".module.ts" : null
|
|
368
|
-
if (!suffix)
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
const
|
|
374
|
-
|
|
375
|
-
}
|
|
376
|
-
|
|
393
|
+
const base = filename.split("/").at(-1) ?? "";
|
|
394
|
+
const suffix = base.endsWith(".module-definition.ts") ? ".module-definition.ts" : base.endsWith(".module.ts") ? ".module.ts" : null;
|
|
395
|
+
if (!suffix)
|
|
396
|
+
return null;
|
|
397
|
+
const tier = hfs.tierOf(filename);
|
|
398
|
+
if (!MODULE_TIERS.has(tier))
|
|
399
|
+
return null;
|
|
400
|
+
const name = base.slice(0, base.length - suffix.length);
|
|
401
|
+
const where = insideOwner(hfs, filename);
|
|
402
|
+
const representative = CAPABILITY_TIERS.has(tier) && where !== null && where.inside === `${where.name}${suffix}`;
|
|
403
|
+
return { kind: suffix === ".module.ts" ? "module" : "definition", tier, name, representative };
|
|
404
|
+
};
|
|
377
405
|
/**
|
|
378
406
|
* The shape of a module's definition (BE-CONVENTION 1.2, owner ruling module-definition-everywhere): the representative
|
|
379
407
|
* module of a capability builds `new ConfigurableModuleBuilder<XOptions>().setExtras({ isGlobal: false }, ...).build()` and
|
|
@@ -393,55 +421,61 @@ export const capabilityModuleShape = {
|
|
|
393
421
|
},
|
|
394
422
|
},
|
|
395
423
|
create(context) {
|
|
396
|
-
const filename = normalizePath(context.filename || context.getFilename())
|
|
397
|
-
if (isDeclarationFile(filename) || isSpecFile(filename))
|
|
398
|
-
|
|
399
|
-
|
|
424
|
+
const filename = normalizePath(context.filename || context.getFilename());
|
|
425
|
+
if (isDeclarationFile(filename) || isSpecFile(filename))
|
|
426
|
+
return {};
|
|
427
|
+
const scope = moduleFileOf(hfsOf(context), filename);
|
|
428
|
+
if (!scope)
|
|
429
|
+
return {};
|
|
400
430
|
if (scope.kind === "definition") {
|
|
401
431
|
const shape = scope.representative
|
|
402
432
|
? "`new ConfigurableModuleBuilder<XOptions>().setExtras({ isGlobal: false }, (d, e) => ({ ...d, global: e.isGlobal })).build()`"
|
|
403
|
-
: '`new ConfigurableModuleBuilder<XOptions>().setClassMethodName("register").build()`'
|
|
433
|
+
: '`new ConfigurableModuleBuilder<XOptions>().setClassMethodName("register").build()`';
|
|
404
434
|
return {
|
|
405
435
|
Program(program) {
|
|
406
|
-
let found = false
|
|
436
|
+
let found = false;
|
|
407
437
|
walk(program, (node) => {
|
|
408
|
-
if (node.type !== "NewExpression" || node.callee.type !== "Identifier" || node.callee.name !== "ConfigurableModuleBuilder")
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
438
|
+
if (node.type !== "NewExpression" || node.callee.type !== "Identifier" || node.callee.name !== "ConfigurableModuleBuilder")
|
|
439
|
+
return;
|
|
440
|
+
found = true;
|
|
441
|
+
const missing = chainFaults(builderChain(node), scope.representative);
|
|
442
|
+
if (missing.length > 0)
|
|
443
|
+
context.report({ node, messageId: "chain", data: { shape, missing: missing.join("; ") } });
|
|
444
|
+
});
|
|
445
|
+
if (!found)
|
|
446
|
+
context.report({ node: program, loc: { line: 1, column: 0 }, messageId: "chain", data: { shape, missing: "no `new ConfigurableModuleBuilder<XOptions>()` is built here" } });
|
|
414
447
|
},
|
|
415
|
-
}
|
|
448
|
+
};
|
|
416
449
|
}
|
|
417
450
|
return {
|
|
418
451
|
ClassDeclaration(node) {
|
|
419
|
-
if (!isModuleClass(node))
|
|
452
|
+
if (!isModuleClass(node))
|
|
453
|
+
return;
|
|
420
454
|
for (const member of node.body.body) {
|
|
421
|
-
if (member.type !== "MethodDefinition" || member.key.type !== "Identifier" || member.key.name !== "register")
|
|
422
|
-
|
|
423
|
-
|
|
455
|
+
if (member.type !== "MethodDefinition" || member.key.type !== "Identifier" || member.key.name !== "register")
|
|
456
|
+
continue;
|
|
457
|
+
if (!scope.representative)
|
|
458
|
+
context.report({ node: member, messageId: "plain", data: { class: node.id?.name ?? "This class" } });
|
|
459
|
+
else if (!isRegisterOverride(member))
|
|
460
|
+
context.report({ node: member, messageId: "registerSignature", data: { name: scope.name } });
|
|
424
461
|
}
|
|
425
462
|
},
|
|
426
|
-
}
|
|
463
|
+
};
|
|
427
464
|
},
|
|
428
|
-
}
|
|
429
|
-
|
|
465
|
+
};
|
|
430
466
|
/** True when a class declaration carries the Nest `Module` decorator. */
|
|
431
467
|
const isModuleDeclaration = (declaration) => {
|
|
432
|
-
if (!ts.isClassDeclaration(declaration))
|
|
468
|
+
if (!ts.isClassDeclaration(declaration))
|
|
469
|
+
return false;
|
|
433
470
|
return (ts.getDecorators(declaration) ?? []).some((decorator) => {
|
|
434
|
-
const expression = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression
|
|
435
|
-
return ts.isIdentifier(expression) && expression.text === "Module"
|
|
436
|
-
})
|
|
437
|
-
}
|
|
438
|
-
|
|
471
|
+
const expression = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression;
|
|
472
|
+
return ts.isIdentifier(expression) && expression.text === "Module";
|
|
473
|
+
});
|
|
474
|
+
};
|
|
439
475
|
/** The array of an `imports` property (the `@Module({ imports })` metadata or a dynamic module literal), else null. */
|
|
440
|
-
const importsArrayOf = (property) => (!property.computed && keyName(property.key) === "imports" && property.value.type === "ArrayExpression" ? property.value : null)
|
|
441
|
-
|
|
476
|
+
const importsArrayOf = (property) => (!property.computed && keyName(property.key) === "imports" && property.value.type === "ArrayExpression" ? property.value : null);
|
|
442
477
|
/** The PascalCase options type name a module file name implies: `sepay-feed-http` gives `SepayFeedHttpOptions`. */
|
|
443
|
-
const optionsTypeOf = (name) => `${name.replace(/(?:^|-)(\w)/g, (_, letter) => letter.toUpperCase())}Options
|
|
444
|
-
|
|
478
|
+
const optionsTypeOf = (name) => `${name.replace(/(?:^|-)(\w)/g, (_, letter) => letter.toUpperCase())}Options`;
|
|
445
479
|
/**
|
|
446
480
|
* Every Nest module has a module definition and is registered through it (owner ruling module-definition-everywhere): its
|
|
447
481
|
* `<x>.module.ts` has a sibling `<x>.module-definition.ts` and `<x>.options.ts`, its class extends the `ConfigurableModuleClass`
|
|
@@ -461,51 +495,60 @@ export const moduleDefinitionRequired = {
|
|
|
461
495
|
},
|
|
462
496
|
},
|
|
463
497
|
create(context) {
|
|
464
|
-
const filename = normalizePath(context.filename || context.getFilename())
|
|
465
|
-
if (isDeclarationFile(filename) || isSpecFile(filename))
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
const
|
|
498
|
+
const filename = normalizePath(context.filename || context.getFilename());
|
|
499
|
+
if (isDeclarationFile(filename) || isSpecFile(filename))
|
|
500
|
+
return {};
|
|
501
|
+
const hfs = hfsOf(context);
|
|
502
|
+
if (inTestWorld(hfs, filename))
|
|
503
|
+
return {};
|
|
504
|
+
const scope = moduleFileOf(hfs, filename);
|
|
505
|
+
const importedFrom = new Map();
|
|
506
|
+
const { checker, toTs } = typed(context);
|
|
471
507
|
const isModuleClassIdentifier = (identifier) => {
|
|
472
|
-
const tsNode = toTs(identifier)
|
|
473
|
-
let symbol = tsNode ? checker.getSymbolAtLocation(tsNode) : undefined
|
|
474
|
-
if (symbol && symbol.flags & ts.SymbolFlags.Alias)
|
|
475
|
-
|
|
476
|
-
|
|
508
|
+
const tsNode = toTs(identifier);
|
|
509
|
+
let symbol = tsNode ? checker.getSymbolAtLocation(tsNode) : undefined;
|
|
510
|
+
if (symbol && symbol.flags & ts.SymbolFlags.Alias)
|
|
511
|
+
symbol = checker.getAliasedSymbol(symbol);
|
|
512
|
+
return (symbol?.declarations ?? []).some((declaration) => !/[\\/]node_modules[\\/]/.test(declaration.getSourceFile().fileName) && isModuleDeclaration(declaration));
|
|
513
|
+
};
|
|
477
514
|
return {
|
|
478
515
|
ImportDeclaration(node) {
|
|
479
516
|
for (const specifier of node.specifiers) {
|
|
480
|
-
if (specifier.type === "ImportSpecifier")
|
|
517
|
+
if (specifier.type === "ImportSpecifier")
|
|
518
|
+
importedFrom.set(specifier.local.name, { name: specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value, source: String(node.source.value) });
|
|
481
519
|
}
|
|
482
520
|
},
|
|
483
521
|
Program(program) {
|
|
484
|
-
if (scope?.kind !== "module")
|
|
485
|
-
|
|
486
|
-
const
|
|
487
|
-
|
|
488
|
-
if (!existsSync(join(siblings, `${scope.name}.
|
|
522
|
+
if (scope?.kind !== "module")
|
|
523
|
+
return;
|
|
524
|
+
const siblings = dirname(filename);
|
|
525
|
+
const type = optionsTypeOf(scope.name);
|
|
526
|
+
if (!existsSync(join(siblings, `${scope.name}.module-definition.ts`)))
|
|
527
|
+
context.report({ node: program, loc: { line: 1, column: 0 }, messageId: "missingDefinition", data: { name: scope.name, type } });
|
|
528
|
+
if (!existsSync(join(siblings, `${scope.name}.options.ts`)))
|
|
529
|
+
context.report({ node: program, loc: { line: 1, column: 0 }, messageId: "missingOptions", data: { name: scope.name, type } });
|
|
489
530
|
},
|
|
490
531
|
ClassDeclaration(node) {
|
|
491
|
-
if (scope?.kind !== "module" || !isModuleClass(node))
|
|
492
|
-
|
|
493
|
-
const
|
|
532
|
+
if (scope?.kind !== "module" || !isModuleClass(node))
|
|
533
|
+
return;
|
|
534
|
+
const base = node.superClass;
|
|
535
|
+
const imported = base?.type === "Identifier" ? importedFrom.get(base.name) : null;
|
|
494
536
|
if (!imported || imported.name !== "ConfigurableModuleClass" || imported.source !== `./${scope.name}.module-definition`) {
|
|
495
|
-
context.report({ node: node.id ?? node, messageId: "extendsBase", data: { class: node.id?.name ?? "This class", name: scope.name } })
|
|
537
|
+
context.report({ node: node.id ?? node, messageId: "extendsBase", data: { class: node.id?.name ?? "This class", name: scope.name } });
|
|
496
538
|
}
|
|
497
539
|
},
|
|
498
540
|
Property(node) {
|
|
499
|
-
const array = importsArrayOf(node)
|
|
500
|
-
if (!array)
|
|
541
|
+
const array = importsArrayOf(node);
|
|
542
|
+
if (!array)
|
|
543
|
+
return;
|
|
501
544
|
for (const entry of array.elements) {
|
|
502
|
-
if (entry?.type === "Identifier" && isModuleClassIdentifier(entry))
|
|
545
|
+
if (entry?.type === "Identifier" && isModuleClassIdentifier(entry))
|
|
546
|
+
context.report({ node: entry, messageId: "unregistered", data: { name: entry.name } });
|
|
503
547
|
}
|
|
504
548
|
},
|
|
505
|
-
}
|
|
549
|
+
};
|
|
506
550
|
},
|
|
507
|
-
}
|
|
508
|
-
|
|
551
|
+
};
|
|
509
552
|
/** The rules this law contributes to the plugin. */
|
|
510
553
|
export const rules = {
|
|
511
554
|
"no-global-decorator": noGlobalDecorator,
|
|
@@ -518,8 +561,7 @@ export const rules = {
|
|
|
518
561
|
"no-new-injectable": noNewInjectable,
|
|
519
562
|
"no-module-let": noModuleLet,
|
|
520
563
|
"one-module-per-file": oneModulePerFile,
|
|
521
|
-
}
|
|
522
|
-
|
|
564
|
+
};
|
|
523
565
|
/** All start at error: HFS has one module shape and no baseline. */
|
|
524
566
|
export const recommended = {
|
|
525
567
|
"starci-be/no-global-decorator": "error",
|
|
@@ -532,4 +574,4 @@ export const recommended = {
|
|
|
532
574
|
"starci-be/no-new-injectable": "error",
|
|
533
575
|
"starci-be/no-module-let": "error",
|
|
534
576
|
"starci-be/one-module-per-file": "error",
|
|
535
|
-
}
|
|
577
|
+
};
|