@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
|
@@ -20,39 +20,34 @@
|
|
|
20
20
|
* `<C>_ERROR_KINDS: Record<<C>ErrorCode, ErrorKind>` table, and an empty `<C>Error extends DomainError<<C>ErrorCode>`.
|
|
21
21
|
* Code uniqueness across the repository is the architecture machine's job, not a single file's.
|
|
22
22
|
*/
|
|
23
|
-
import { some, walk } from "./lib/ast.
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
isOwnedBy,
|
|
30
|
-
isOwnedType,
|
|
31
|
-
ownerName,
|
|
32
|
-
partsOf,
|
|
33
|
-
typeOf,
|
|
34
|
-
} from "./lib/declared.mjs"
|
|
35
|
-
import { hfsOf } from "./lib/hfs.mjs"
|
|
36
|
-
import { normalizePath } from "./lib/path.mjs"
|
|
37
|
-
import { typed } from "./lib/types.mjs"
|
|
38
|
-
|
|
23
|
+
import { nameOrValue, some, walk } from "./lib/ast.js";
|
|
24
|
+
import { derives, derivesFromBuiltinError, derivesFromDomainError, errorHomeOf, isOwnedBy, isOwnedType, ownerName, partsOf, typeOf, } from "./lib/declared.js";
|
|
25
|
+
import { hfsOf } from "./lib/hfs.js";
|
|
26
|
+
import { normalizePath } from "./lib/path.js";
|
|
27
|
+
import { typed } from "./lib/types.js";
|
|
28
|
+
import { isNode } from "./lib/rule.js";
|
|
39
29
|
/** True when `name` is used as a value in `node` (not just as the object of `name.message`). */
|
|
40
30
|
const carriesCaught = (node, name) => {
|
|
41
|
-
if (!name)
|
|
42
|
-
|
|
31
|
+
if (!name)
|
|
32
|
+
return false;
|
|
33
|
+
let carried = false;
|
|
43
34
|
walk(node, (child) => {
|
|
44
|
-
if (child.type !== "Identifier" || child.name !== name)
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
35
|
+
if (child.type !== "Identifier" || child.name !== name)
|
|
36
|
+
return;
|
|
37
|
+
let inner = child;
|
|
38
|
+
while (inner.parent && (inner.parent.type === "TSAsExpression" || inner.parent.type === "TSNonNullExpression" || inner.parent.type === "TSTypeAssertion"))
|
|
39
|
+
inner = inner.parent;
|
|
40
|
+
const parent = inner.parent;
|
|
41
|
+
if (parent?.type === "MemberExpression" && parent.object === inner)
|
|
42
|
+
return;
|
|
43
|
+
carried = true;
|
|
44
|
+
});
|
|
45
|
+
return carried;
|
|
46
|
+
};
|
|
47
|
+
const paramName = (fn) => {
|
|
48
|
+
const first = fn.params?.[0];
|
|
49
|
+
return first?.type === "Identifier" ? first.name : null;
|
|
50
|
+
};
|
|
56
51
|
/** Every failure is rethrown, logged through the logger port, or returned as an outcome carrying its cause. */
|
|
57
52
|
export const catchMustAccount = {
|
|
58
53
|
meta: {
|
|
@@ -61,101 +56,112 @@ export const catchMustAccount = {
|
|
|
61
56
|
schema: [],
|
|
62
57
|
messages: {
|
|
63
58
|
empty: "This `catch` is empty, so the failure vanishes. Rethrow it, log it through the `Logger` of `platform/logging`, or return a typed outcome carrying it as `cause`.",
|
|
64
|
-
swallowed:
|
|
65
|
-
"This `catch` neither rethrows, logs through the `Logger` of `platform/logging`, nor returns an outcome carrying the caught error, so the failure leaves no trace. Rethrow it, log it through the `Logger`, or return a typed outcome with `cause`.",
|
|
59
|
+
swallowed: "This `catch` neither rethrows, logs through the `Logger` of `platform/logging`, nor returns an outcome carrying the caught error, so the failure leaves no trace. Rethrow it, log it through the `Logger`, or return a typed outcome with `cause`.",
|
|
66
60
|
},
|
|
67
61
|
},
|
|
68
62
|
create(context) {
|
|
69
63
|
/** A call of a method on a receiver whose type is the `Logger` port declared by `platform/logging`. */
|
|
70
|
-
const isLoggerCall = (node) =>
|
|
71
|
-
node.type === "CallExpression" &&
|
|
64
|
+
const isLoggerCall = (node) => node.type === "CallExpression" &&
|
|
72
65
|
node.callee.type === "MemberExpression" &&
|
|
73
|
-
isOwnedType(context, node.callee.object, "Logger", "platform", "logging")
|
|
74
|
-
const accounts = (body, param) =>
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
(node) =>
|
|
78
|
-
node.type === "ThrowStatement" ||
|
|
79
|
-
isLoggerCall(node) ||
|
|
80
|
-
(node.type === "ReturnStatement" && node.argument !== null && carriesCaught(node.argument, param)),
|
|
81
|
-
{ intoFunctions: false },
|
|
82
|
-
)
|
|
66
|
+
isOwnedType(context, node.callee.object, "Logger", "platform", "logging");
|
|
67
|
+
const accounts = (body, param) => some(body, (node) => node.type === "ThrowStatement" ||
|
|
68
|
+
isLoggerCall(node) ||
|
|
69
|
+
(node.type === "ReturnStatement" && node.argument !== null && carriesCaught(node.argument, param)), { intoFunctions: false });
|
|
83
70
|
const checkBlock = (reportNode, body, param) => {
|
|
84
|
-
if (body.body.length === 0)
|
|
85
|
-
|
|
86
|
-
|
|
71
|
+
if (body.body.length === 0)
|
|
72
|
+
context.report({ node: reportNode, messageId: "empty" });
|
|
73
|
+
else if (!accounts(body, param))
|
|
74
|
+
context.report({ node: reportNode, messageId: "swallowed" });
|
|
75
|
+
};
|
|
87
76
|
return {
|
|
88
77
|
CatchClause(node) {
|
|
89
|
-
checkBlock(node, node.body, node.param?.type === "Identifier" ? node.param.name : null)
|
|
78
|
+
checkBlock(node, node.body, node.param?.type === "Identifier" ? node.param.name : null);
|
|
90
79
|
},
|
|
91
80
|
CallExpression(node) {
|
|
92
|
-
if (node.callee.type !== "MemberExpression" || node.callee.computed)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
81
|
+
if (node.callee.type !== "MemberExpression" || node.callee.computed)
|
|
82
|
+
return;
|
|
83
|
+
if (node.callee.property.type !== "Identifier" || node.callee.property.name !== "catch")
|
|
84
|
+
return;
|
|
85
|
+
const handler = node.arguments[0];
|
|
86
|
+
if (!handler || (handler.type !== "ArrowFunctionExpression" && handler.type !== "FunctionExpression"))
|
|
87
|
+
return;
|
|
96
88
|
if (handler.body.type === "BlockStatement") {
|
|
97
|
-
checkBlock(handler, handler.body, paramName(handler))
|
|
98
|
-
}
|
|
99
|
-
|
|
89
|
+
checkBlock(handler, handler.body, paramName(handler));
|
|
90
|
+
}
|
|
91
|
+
else if (!isLoggerCall(handler.body) && !carriesCaught(handler.body, paramName(handler))) {
|
|
92
|
+
context.report({ node: handler, messageId: "swallowed" });
|
|
100
93
|
}
|
|
101
94
|
},
|
|
102
|
-
}
|
|
95
|
+
};
|
|
103
96
|
},
|
|
104
|
-
}
|
|
105
|
-
|
|
97
|
+
};
|
|
106
98
|
/** The statements of a catch body that escape it: nested functions, nested handlers and guarded `try` blocks are not. */
|
|
107
99
|
const escapingThrows = (body) => {
|
|
108
|
-
const found = []
|
|
100
|
+
const found = [];
|
|
109
101
|
const visit = (node) => {
|
|
110
|
-
if (!node
|
|
111
|
-
|
|
112
|
-
if (node.type === "
|
|
113
|
-
|
|
102
|
+
if (!isNode(node))
|
|
103
|
+
return;
|
|
104
|
+
if (node.type === "FunctionDeclaration" || node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression")
|
|
105
|
+
return;
|
|
106
|
+
if (node.type === "CatchClause")
|
|
107
|
+
return;
|
|
108
|
+
if (node.type === "ThrowStatement")
|
|
109
|
+
found.push(node);
|
|
114
110
|
if (node.type === "TryStatement") {
|
|
115
111
|
// a throw of the guarded block lands in the nested handler, which is judged on its own
|
|
116
|
-
if (!node.handler)
|
|
117
|
-
|
|
118
|
-
|
|
112
|
+
if (!node.handler)
|
|
113
|
+
visit(node.block);
|
|
114
|
+
visit(node.finalizer);
|
|
115
|
+
return;
|
|
119
116
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
|
|
117
|
+
const entries = Object.entries(node);
|
|
118
|
+
for (const [key, value] of entries) {
|
|
119
|
+
if (key === "parent" || key === "loc" || key === "range")
|
|
120
|
+
continue;
|
|
121
|
+
if (Array.isArray(value)) {
|
|
122
|
+
const items = value;
|
|
123
|
+
items.forEach(visit);
|
|
124
|
+
}
|
|
125
|
+
else
|
|
126
|
+
visit(value);
|
|
124
127
|
}
|
|
125
|
-
}
|
|
126
|
-
body.body.forEach(visit)
|
|
127
|
-
return found
|
|
128
|
-
}
|
|
129
|
-
|
|
128
|
+
};
|
|
129
|
+
body.body.forEach(visit);
|
|
130
|
+
return found;
|
|
131
|
+
};
|
|
130
132
|
/** The variable `identifier` names at its position, or null. */
|
|
131
133
|
const variableOf = (sourceCode, identifier) => {
|
|
132
134
|
for (let scope = sourceCode.getScope(identifier); scope; scope = scope.upper) {
|
|
133
|
-
const variable = scope.set.get(identifier.name)
|
|
134
|
-
if (variable)
|
|
135
|
+
const variable = scope.set.get(identifier.name);
|
|
136
|
+
if (variable)
|
|
137
|
+
return variable;
|
|
135
138
|
}
|
|
136
|
-
return null
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
+
return null;
|
|
140
|
+
};
|
|
139
141
|
/**
|
|
140
142
|
* True when the thrown value carries the caught one: it is the caught binding, it uses it as a value, or it is a variable
|
|
141
143
|
* whose initializer or an assignment uses it. Anything the rule cannot see through is taken as carrying, so it never
|
|
142
144
|
* reports a throw that might keep the cause.
|
|
143
145
|
*/
|
|
144
146
|
const throwCarriesCaught = (sourceCode, argument, caught) => {
|
|
145
|
-
if (carriesCaught(argument, caught))
|
|
146
|
-
|
|
147
|
-
|
|
147
|
+
if (carriesCaught(argument, caught))
|
|
148
|
+
return true;
|
|
149
|
+
let value = argument;
|
|
150
|
+
while (value.type === "TSAsExpression" || value.type === "TSNonNullExpression" || value.type === "TSTypeAssertion")
|
|
151
|
+
value = value.expression;
|
|
148
152
|
if (value.type === "Identifier") {
|
|
149
|
-
const variable = variableOf(sourceCode, value)
|
|
153
|
+
const variable = variableOf(sourceCode, value);
|
|
150
154
|
// an unresolved global or an import cannot carry this catch's value, but a parameter may hold anything
|
|
151
|
-
if (!variable)
|
|
152
|
-
|
|
153
|
-
if (variable.defs.some((def) => def.
|
|
154
|
-
|
|
155
|
+
if (!variable)
|
|
156
|
+
return false;
|
|
157
|
+
if (variable.defs.some((def) => def.type === "Parameter"))
|
|
158
|
+
return true;
|
|
159
|
+
if (variable.defs.some((def) => def.node.type === "VariableDeclarator" && def.node.init && carriesCaught(def.node.init, caught)))
|
|
160
|
+
return true;
|
|
161
|
+
return variable.references.some((reference) => reference.isWrite() && reference.writeExpr && carriesCaught(reference.writeExpr, caught));
|
|
155
162
|
}
|
|
156
|
-
return false
|
|
157
|
-
}
|
|
158
|
-
|
|
163
|
+
return false;
|
|
164
|
+
};
|
|
159
165
|
/** A catch that replaces the caught failure passes the caught value on as the replacement's `cause` (BE-ERROR-4). */
|
|
160
166
|
export const replacementThrowCarriesCause = {
|
|
161
167
|
meta: {
|
|
@@ -163,64 +169,70 @@ export const replacementThrowCarriesCause = {
|
|
|
163
169
|
docs: { description: "A throw that escapes a catch rethrows the caught value or carries it (as `cause`) in the replacement." },
|
|
164
170
|
schema: [],
|
|
165
171
|
messages: {
|
|
166
|
-
dropped:
|
|
167
|
-
|
|
168
|
-
unbound:
|
|
169
|
-
"This `throw` replaces a failure its `catch` never bound, so the original error is lost. Bind it (`catch (error)`) and pass it as `cause` of the capability error, or rethrow it.",
|
|
172
|
+
dropped: "This `throw` replaces the caught failure without carrying it, so the stack and the original error are lost. Pass the exact caught value as `cause` of the capability error (`new <C>Error({ code, cause: {{name}} })`) or rethrow it.",
|
|
173
|
+
unbound: "This `throw` replaces a failure its `catch` never bound, so the original error is lost. Bind it (`catch (error)`) and pass it as `cause` of the capability error, or rethrow it.",
|
|
170
174
|
},
|
|
171
175
|
},
|
|
172
176
|
create(context) {
|
|
173
|
-
const sourceCode = context.sourceCode || context.getSourceCode()
|
|
177
|
+
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
174
178
|
const check = (body, param) => {
|
|
175
|
-
const caught = param?.type === "Identifier" ? param.name : null
|
|
179
|
+
const caught = param?.type === "Identifier" ? param.name : null;
|
|
176
180
|
for (const statement of escapingThrows(body)) {
|
|
177
|
-
const argument = statement.argument
|
|
181
|
+
const argument = statement.argument;
|
|
178
182
|
if (caught === null) {
|
|
179
|
-
context.report({ node: statement, messageId: "unbound" })
|
|
180
|
-
continue
|
|
183
|
+
context.report({ node: statement, messageId: "unbound" });
|
|
184
|
+
continue;
|
|
181
185
|
}
|
|
182
|
-
if (throwCarriesCaught(sourceCode, argument, caught))
|
|
183
|
-
|
|
186
|
+
if (throwCarriesCaught(sourceCode, argument, caught))
|
|
187
|
+
continue;
|
|
188
|
+
context.report({ node: statement, messageId: "dropped", data: { name: caught } });
|
|
184
189
|
}
|
|
185
|
-
}
|
|
190
|
+
};
|
|
186
191
|
return {
|
|
187
192
|
CatchClause(node) {
|
|
188
193
|
// a destructured binding names parts of the failure, not the failure itself; the rule cannot tell which part is kept
|
|
189
|
-
if (node.param && node.param.type !== "Identifier")
|
|
190
|
-
|
|
194
|
+
if (node.param && node.param.type !== "Identifier")
|
|
195
|
+
return;
|
|
196
|
+
check(node.body, node.param);
|
|
191
197
|
},
|
|
192
198
|
CallExpression(node) {
|
|
193
|
-
if (node.callee.type !== "MemberExpression" || node.callee.computed)
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (handler.
|
|
199
|
-
|
|
199
|
+
if (node.callee.type !== "MemberExpression" || node.callee.computed)
|
|
200
|
+
return;
|
|
201
|
+
if (node.callee.property.type !== "Identifier" || node.callee.property.name !== "catch")
|
|
202
|
+
return;
|
|
203
|
+
const handler = node.arguments[0];
|
|
204
|
+
if (!handler || (handler.type !== "ArrowFunctionExpression" && handler.type !== "FunctionExpression"))
|
|
205
|
+
return;
|
|
206
|
+
if (handler.body.type !== "BlockStatement")
|
|
207
|
+
return;
|
|
208
|
+
if (handler.params[0] && handler.params[0].type !== "Identifier")
|
|
209
|
+
return;
|
|
210
|
+
check(handler.body, handler.params[0]);
|
|
200
211
|
},
|
|
201
|
-
}
|
|
212
|
+
};
|
|
202
213
|
},
|
|
203
|
-
}
|
|
204
|
-
|
|
214
|
+
};
|
|
205
215
|
/**
|
|
206
216
|
* The test world (slot `be.tests.world`) is the TEST COMPOSITION ROOT and owns no capability folder: its one error class
|
|
207
217
|
* `TestWorldError` lives in `test-world.error.ts` at the world root, which is the world's `errors/<capability>.error.ts`.
|
|
208
218
|
* Only that file is a home; a nested `fakes/**` file, a spec and every other owner stay judged by `errors/<c>.error.ts`.
|
|
209
219
|
*/
|
|
210
220
|
const isWorldErrorHome = (hfs, filename) => {
|
|
211
|
-
const placed = hfs.classify(filename)
|
|
212
|
-
return placed.slot === "be.tests.world" && placed.path === `${placed.root}/test-world.error.ts
|
|
213
|
-
}
|
|
214
|
-
|
|
221
|
+
const placed = hfs.classify(filename);
|
|
222
|
+
return placed.slot === "be.tests.world" && placed.path === `${placed.root}/test-world.error.ts`;
|
|
223
|
+
};
|
|
215
224
|
/** True when a class of a unit spec (`<name>.spec.ts`) is local to it: neither exported by declaration nor by an `export { Name }` list. */
|
|
216
225
|
const isSpecLocalClass = (filename, node) => {
|
|
217
|
-
|
|
218
|
-
if (
|
|
219
|
-
|
|
220
|
-
if (
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
226
|
+
const id = node.id;
|
|
227
|
+
if (!/\.spec\.[cm]?ts$/.test(filename) || !id)
|
|
228
|
+
return false;
|
|
229
|
+
if (node.parent?.type === "ExportNamedDeclaration" || node.parent?.type === "ExportDefaultDeclaration")
|
|
230
|
+
return false;
|
|
231
|
+
const program = node.parent?.type === "Program" ? node.parent : null;
|
|
232
|
+
if (!program)
|
|
233
|
+
return node.type === "ClassDeclaration" || node.type === "ClassExpression";
|
|
234
|
+
return !program.body.some((statement) => statement.type === "ExportNamedDeclaration" && !statement.source && statement.specifiers.some((specifier) => nameOrValue(specifier.local) === id.name));
|
|
235
|
+
};
|
|
224
236
|
/** An error class is declared at its owner in `errors/<capability>.error.ts` and derives from `DomainError`. */
|
|
225
237
|
export const errorHome = {
|
|
226
238
|
meta: {
|
|
@@ -229,59 +241,64 @@ export const errorHome = {
|
|
|
229
241
|
schema: [],
|
|
230
242
|
messages: {
|
|
231
243
|
place: "`{{name}}` derives from `DomainError` but is not declared in `errors/{{owner}}.error.ts` of its owner. An owner has one error class, in that file; move it there.",
|
|
232
|
-
mustExtendDomainError:
|
|
233
|
-
"`{{name}}` derives from the built-in `Error` without deriving from `DomainError` (`AbstractException`, a framework exception or a bare `extends Error`). Extend `DomainError` from `platform/errors` in the owner's `errors/<capability>.error.ts`.",
|
|
244
|
+
mustExtendDomainError: "`{{name}}` derives from the built-in `Error` without deriving from `DomainError` (`AbstractException`, a framework exception or a bare `extends Error`). Extend `DomainError` from `platform/errors` in the owner's `errors/<capability>.error.ts`.",
|
|
234
245
|
},
|
|
235
246
|
},
|
|
236
247
|
create(context) {
|
|
237
|
-
const hfs = hfsOf(context)
|
|
238
|
-
const filename = normalizePath(context.filename)
|
|
248
|
+
const hfs = hfsOf(context);
|
|
249
|
+
const filename = normalizePath(context.filename);
|
|
239
250
|
const check = (node) => {
|
|
240
|
-
if (!node.id)
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
251
|
+
if (!node.id)
|
|
252
|
+
return;
|
|
253
|
+
const type = typeOf(context, node.id);
|
|
254
|
+
if (!type)
|
|
255
|
+
return;
|
|
256
|
+
const isDomainErrorHost = node.id.name === "DomainError" && isOwnedBy(hfs, filename, "platform", "errors");
|
|
257
|
+
if (isDomainErrorHost)
|
|
258
|
+
return;
|
|
245
259
|
if (derivesFromDomainError(context, type)) {
|
|
246
|
-
if (isWorldErrorHome(hfs, filename))
|
|
260
|
+
if (isWorldErrorHome(hfs, filename))
|
|
261
|
+
return;
|
|
247
262
|
// A spec-local subclass of the abstract base is a test double for code that takes any DomainError, not an error family.
|
|
248
|
-
if (isSpecLocalClass(filename, node))
|
|
249
|
-
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
263
|
+
if (isSpecLocalClass(filename, node))
|
|
264
|
+
return;
|
|
265
|
+
const home = errorHomeOf(hfs, filename);
|
|
266
|
+
const owner = ownerName(hfs.ownerOf(filename));
|
|
267
|
+
if (!home || home.capability !== owner)
|
|
268
|
+
context.report({ node: node.id, messageId: "place", data: { name: node.id.name, owner: owner ?? "<capability>" } });
|
|
254
269
|
}
|
|
255
|
-
|
|
256
|
-
|
|
270
|
+
else if (derivesFromBuiltinError(context, type)) {
|
|
271
|
+
context.report({ node: node.id, messageId: "mustExtendDomainError", data: { name: node.id.name } });
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
return { ClassDeclaration: check, ClassExpression: check };
|
|
257
275
|
},
|
|
258
|
-
}
|
|
259
|
-
|
|
276
|
+
};
|
|
260
277
|
/** The variable a thrown identifier names is the parameter of a `catch` clause or of a promise `.catch` handler. */
|
|
261
278
|
const isCaughtValue = (context, identifier) => {
|
|
262
279
|
for (let scope = context.sourceCode.getScope(identifier); scope; scope = scope.upper) {
|
|
263
|
-
const variable = scope.set.get(identifier.name)
|
|
264
|
-
if (!variable)
|
|
280
|
+
const variable = scope.set.get(identifier.name);
|
|
281
|
+
if (!variable)
|
|
282
|
+
continue;
|
|
265
283
|
return variable.defs.some((definition) => {
|
|
266
|
-
if (definition.type === "CatchClause")
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
284
|
+
if (definition.type === "CatchClause")
|
|
285
|
+
return true;
|
|
286
|
+
if (definition.type !== "Parameter")
|
|
287
|
+
return false;
|
|
288
|
+
const fn = definition.node;
|
|
289
|
+
const call = fn.parent;
|
|
290
|
+
return ((fn.type === "ArrowFunctionExpression" || fn.type === "FunctionExpression") &&
|
|
272
291
|
call?.type === "CallExpression" &&
|
|
273
292
|
call.arguments[0] === fn &&
|
|
274
293
|
call.callee.type === "MemberExpression" &&
|
|
275
294
|
!call.callee.computed &&
|
|
276
295
|
call.callee.property.type === "Identifier" &&
|
|
277
296
|
call.callee.property.name === "catch" &&
|
|
278
|
-
fn.params[0] === definition.name
|
|
279
|
-
|
|
280
|
-
})
|
|
297
|
+
fn.params[0] === definition.name);
|
|
298
|
+
});
|
|
281
299
|
}
|
|
282
|
-
return false
|
|
283
|
-
}
|
|
284
|
-
|
|
300
|
+
return false;
|
|
301
|
+
};
|
|
285
302
|
/** Every thrown value is a `DomainError` of the owner that throws it. */
|
|
286
303
|
export const throwDomainError = {
|
|
287
304
|
meta: {
|
|
@@ -296,49 +313,72 @@ export const throwDomainError = {
|
|
|
296
313
|
},
|
|
297
314
|
},
|
|
298
315
|
create(context) {
|
|
299
|
-
const hfs = hfsOf(context)
|
|
300
|
-
const filename = normalizePath(context.filename)
|
|
301
|
-
const { checker } = typed(context)
|
|
302
|
-
const isHttpException = (type) => derives(checker, type, (name, file) => name === "HttpException" && /\/node_modules\/@nestjs\/common\//.test(file))
|
|
316
|
+
const hfs = hfsOf(context);
|
|
317
|
+
const filename = normalizePath(context.filename);
|
|
318
|
+
const { checker } = typed(context);
|
|
319
|
+
const isHttpException = (type) => derives(checker, type, (name, file) => name === "HttpException" && /\/node_modules\/@nestjs\/common\//.test(file));
|
|
303
320
|
return {
|
|
304
321
|
ThrowStatement(node) {
|
|
305
|
-
const thrown = node.argument
|
|
306
|
-
if (!thrown)
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
const
|
|
322
|
+
const thrown = node.argument;
|
|
323
|
+
if (!thrown)
|
|
324
|
+
return;
|
|
325
|
+
if (thrown.type === "Identifier" && isCaughtValue(context, thrown))
|
|
326
|
+
return;
|
|
327
|
+
const type = typeOf(context, thrown);
|
|
328
|
+
const parts = partsOf(type);
|
|
329
|
+
const foreign = parts.find((part) => !derivesFromDomainError(context, part));
|
|
311
330
|
if (parts.length === 0 || foreign) {
|
|
312
331
|
if (foreign && isHttpException(foreign)) {
|
|
313
|
-
context.report({ node: thrown, messageId: "framework", data: { name: foreign.getSymbol()?.name ?? "HttpException" } })
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
context.report({ node: thrown, messageId: "notDomainError" })
|
|
332
|
+
context.report({ node: thrown, messageId: "framework", data: { name: foreign.getSymbol()?.name ?? "HttpException" } });
|
|
333
|
+
}
|
|
334
|
+
else if (foreign && derivesFromBuiltinError(context, foreign)) {
|
|
335
|
+
context.report({ node: thrown, messageId: "bareError" });
|
|
318
336
|
}
|
|
319
|
-
|
|
337
|
+
else {
|
|
338
|
+
context.report({ node: thrown, messageId: "notDomainError" });
|
|
339
|
+
}
|
|
340
|
+
return;
|
|
320
341
|
}
|
|
321
|
-
if (hfs.tierOf(filename) !== "domain")
|
|
342
|
+
if (hfs.tierOf(filename) !== "domain")
|
|
343
|
+
return;
|
|
322
344
|
for (const part of parts) {
|
|
323
|
-
const declarations = part.getSymbol()?.declarations ?? []
|
|
324
|
-
const platform = declarations.find((declaration) => hfs.tierOf(String(declaration.getSourceFile().fileName).replace(/\\/g, "/")) === "platform")
|
|
345
|
+
const declarations = part.getSymbol()?.declarations ?? [];
|
|
346
|
+
const platform = declarations.find((declaration) => hfs.tierOf(String(declaration.getSourceFile().fileName).replace(/\\/g, "/")) === "platform");
|
|
325
347
|
if (platform) {
|
|
326
|
-
context.report({ node: thrown, messageId: "platformThrown", data: { name: part.getSymbol()
|
|
327
|
-
return
|
|
348
|
+
context.report({ node: thrown, messageId: "platformThrown", data: { name: part.getSymbol()?.name } });
|
|
349
|
+
return;
|
|
328
350
|
}
|
|
329
351
|
}
|
|
330
352
|
},
|
|
331
|
-
}
|
|
353
|
+
};
|
|
332
354
|
},
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
const
|
|
337
|
-
const
|
|
338
|
-
|
|
355
|
+
};
|
|
356
|
+
const words = (kebab) => kebab.split("-");
|
|
357
|
+
/** The first letter of a word in upper case; an empty word fails as reading a missing letter does. */
|
|
358
|
+
const initial = (word) => {
|
|
359
|
+
const first = word[0];
|
|
360
|
+
if (first === undefined)
|
|
361
|
+
throw new TypeError("Cannot read properties of undefined (reading 'toUpperCase')");
|
|
362
|
+
return first.toUpperCase();
|
|
363
|
+
};
|
|
364
|
+
const pascal = (kebab) => words(kebab).map((word) => initial(word) + word.slice(1)).join("");
|
|
365
|
+
const upperSnake = (kebab) => words(kebab).join("_").toUpperCase();
|
|
339
366
|
/** The exported declaration inside an `export ...` statement, else null. */
|
|
340
|
-
const exportedDeclaration = (statement) => (statement.type === "ExportNamedDeclaration" ? statement.declaration : null)
|
|
341
|
-
|
|
367
|
+
const exportedDeclaration = (statement) => (statement.type === "ExportNamedDeclaration" ? statement.declaration : null);
|
|
368
|
+
/** The name a declarator binds when it binds an identifier, else undefined. */
|
|
369
|
+
const declaratorName = (declarator) => (declarator.id.type === "Identifier" ? declarator.id.name : undefined);
|
|
370
|
+
/** The name of a declaration's `id` when that id is an identifier, else undefined. */
|
|
371
|
+
const declaredName = (declaration) => {
|
|
372
|
+
const id = "id" in declaration ? declaration.id : null;
|
|
373
|
+
return id?.type === "Identifier" ? id.name : undefined;
|
|
374
|
+
};
|
|
375
|
+
/** The params of the type-argument list a node holds under `key` (`typeArguments`, or the older parser's `typeParameters`), else undefined. */
|
|
376
|
+
const typeParamsUnder = (node, key) => {
|
|
377
|
+
if (!node)
|
|
378
|
+
return undefined;
|
|
379
|
+
const value = Reflect.get(node, key);
|
|
380
|
+
return isNode(value) && value.type === "TSTypeParameterInstantiation" ? value.params : undefined;
|
|
381
|
+
};
|
|
342
382
|
/** The one shape of an owner's `errors/<capability>.error.ts`. */
|
|
343
383
|
export const errorFamilyShape = {
|
|
344
384
|
meta: {
|
|
@@ -356,70 +396,81 @@ export const errorFamilyShape = {
|
|
|
356
396
|
},
|
|
357
397
|
},
|
|
358
398
|
create(context) {
|
|
359
|
-
const hfs = hfsOf(context)
|
|
360
|
-
const home = errorHomeOf(hfs, normalizePath(context.filename))
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
const
|
|
365
|
-
const
|
|
399
|
+
const hfs = hfsOf(context);
|
|
400
|
+
const home = errorHomeOf(hfs, normalizePath(context.filename));
|
|
401
|
+
// the home's capability is the required group of its pattern, so it is always present
|
|
402
|
+
if (!home || home.capability === undefined)
|
|
403
|
+
return {};
|
|
404
|
+
const data = { pascal: pascal(home.capability), upper: upperSnake(home.capability) };
|
|
405
|
+
const codeName = `${data.pascal}ErrorCode`;
|
|
406
|
+
const kindsName = `${data.upper}_ERROR_KINDS`;
|
|
407
|
+
const className = `${data.pascal}Error`;
|
|
366
408
|
return {
|
|
367
409
|
Program(program) {
|
|
368
|
-
const declared = program.body.map(exportedDeclaration).filter(Boolean)
|
|
369
|
-
const enums = declared.filter((declaration) => declaration.type === "TSEnumDeclaration")
|
|
370
|
-
const code = enums.find((declaration) => declaration.id.name === codeName)
|
|
371
|
-
if (!code)
|
|
410
|
+
const declared = program.body.map(exportedDeclaration).filter((declaration) => Boolean(declaration));
|
|
411
|
+
const enums = declared.filter((declaration) => declaration.type === "TSEnumDeclaration");
|
|
412
|
+
const code = enums.find((declaration) => declaration.id.name === codeName);
|
|
413
|
+
if (!code)
|
|
414
|
+
context.report({ node: program, loc: { line: 1, column: 0 }, messageId: "noCode", data });
|
|
372
415
|
else {
|
|
373
|
-
const prefix = new RegExp(`^${data.upper}_[A-Z0-9]+(?:_[A-Z0-9]+)*$`)
|
|
416
|
+
const prefix = new RegExp(`^${data.upper}_[A-Z0-9]+(?:_[A-Z0-9]+)*$`);
|
|
374
417
|
for (const member of code.body?.members ?? code.members) {
|
|
375
|
-
const value = member.initializer
|
|
376
|
-
const text = value?.type === "Literal" && typeof value.value === "string" ? value.value : null
|
|
418
|
+
const value = member.initializer;
|
|
419
|
+
const text = value?.type === "Literal" && typeof value.value === "string" ? value.value : null;
|
|
377
420
|
if (text === null || !prefix.test(text) || /_(?:EXCEPTION|ERROR)$/.test(text)) {
|
|
378
|
-
context.report({ node: member, messageId: "memberValue", data: { ...data, member: member.id
|
|
421
|
+
context.report({ node: member, messageId: "memberValue", data: { ...data, member: nameOrValue(member.id) } });
|
|
379
422
|
}
|
|
380
423
|
}
|
|
381
424
|
}
|
|
382
|
-
const kinds = declared.find((declaration) => declaration.type === "VariableDeclaration" && declaration.declarations.some((d) => d
|
|
383
|
-
|
|
425
|
+
const kinds = declared.find((declaration) => declaration.type === "VariableDeclaration" && declaration.declarations.some((d) => declaratorName(d) === kindsName));
|
|
426
|
+
// the declarator is found whenever `kinds` is, since `kinds` is the declaration holding it
|
|
427
|
+
const declarator = kinds?.declarations.find((d) => declaratorName(d) === kindsName);
|
|
428
|
+
if (!declarator)
|
|
429
|
+
context.report({ node: program, loc: { line: 1, column: 0 }, messageId: "noKinds", data });
|
|
384
430
|
else {
|
|
385
|
-
const
|
|
386
|
-
const
|
|
387
|
-
const
|
|
388
|
-
const
|
|
389
|
-
const keyOk =
|
|
390
|
-
const valueOk = args.length === 2 &&
|
|
391
|
-
if (!isRecord || args.length !== 2 || !keyOk || !valueOk)
|
|
431
|
+
const annotation = declarator.id.typeAnnotation?.typeAnnotation;
|
|
432
|
+
const args = typeParamsUnder(annotation, "typeArguments") ?? typeParamsUnder(annotation, "typeParameters") ?? [];
|
|
433
|
+
const isRecord = annotation?.type === "TSTypeReference" && annotation.typeName.type === "Identifier" && annotation.typeName.name === "Record";
|
|
434
|
+
const [keyArg, valueArg] = args;
|
|
435
|
+
const keyOk = keyArg?.type === "TSTypeReference" && keyArg.typeName.type === "Identifier" && keyArg.typeName.name === codeName;
|
|
436
|
+
const valueOk = args.length === 2 && valueArg?.type === "TSTypeReference" && isOwnedType(context, valueArg, "ErrorKind", "platform", "errors");
|
|
437
|
+
if (!isRecord || args.length !== 2 || !keyOk || !valueOk)
|
|
438
|
+
context.report({ node: declarator.id, messageId: "kindsType", data });
|
|
392
439
|
}
|
|
393
|
-
const cls = declared.find((declaration) => declaration.type === "ClassDeclaration" && declaration.id?.name === className)
|
|
394
|
-
if (!cls)
|
|
440
|
+
const cls = declared.find((declaration) => declaration.type === "ClassDeclaration" && declaration.id?.name === className);
|
|
441
|
+
if (!cls)
|
|
442
|
+
context.report({ node: program, loc: { line: 1, column: 0 }, messageId: "noClass", data });
|
|
395
443
|
else {
|
|
396
|
-
const parent = cls.superClass
|
|
397
|
-
const args = cls
|
|
398
|
-
const parentOk = parent && isOwnedType(context, parent, "DomainError", "platform", "errors")
|
|
399
|
-
const
|
|
400
|
-
|
|
444
|
+
const parent = cls.superClass;
|
|
445
|
+
const args = typeParamsUnder(cls, "superTypeArguments") ?? typeParamsUnder(cls, "superTypeParameters") ?? [];
|
|
446
|
+
const parentOk = parent && isOwnedType(context, parent, "DomainError", "platform", "errors");
|
|
447
|
+
const [codeArg] = args;
|
|
448
|
+
const argOk = args.length === 1 && codeArg?.type === "TSTypeReference" && codeArg.typeName.type === "Identifier" && codeArg.typeName.name === codeName;
|
|
449
|
+
if (!parentOk || !argOk || cls.body.body.length > 0)
|
|
450
|
+
context.report({ node: cls.id, messageId: "classShape", data });
|
|
401
451
|
}
|
|
402
452
|
for (const statement of program.body) {
|
|
403
|
-
const declaration = exportedDeclaration(statement)
|
|
404
|
-
const isExport = statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration" || statement.type === "ExportAllDeclaration"
|
|
405
|
-
if (!isExport)
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
453
|
+
const declaration = exportedDeclaration(statement);
|
|
454
|
+
const isExport = statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration" || statement.type === "ExportAllDeclaration";
|
|
455
|
+
if (!isExport)
|
|
456
|
+
continue;
|
|
457
|
+
const name = declaration?.type === "VariableDeclaration"
|
|
458
|
+
? declaration.declarations.map(declaratorName).find((n) => n !== kindsName)
|
|
459
|
+
: declaration ? declaredName(declaration) : undefined;
|
|
410
460
|
if (declaration === null || declaration === undefined) {
|
|
411
|
-
context.report({ node: statement, messageId: "extra", data: { ...data, name: statement.type } })
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
461
|
+
context.report({ node: statement, messageId: "extra", data: { ...data, name: statement.type } });
|
|
462
|
+
}
|
|
463
|
+
else if (name !== undefined && name !== codeName && name !== kindsName && name !== className) {
|
|
464
|
+
context.report({ node: declaration, messageId: "extra", data: { ...data, name } });
|
|
465
|
+
}
|
|
466
|
+
else if (name === undefined && declaration.type !== "VariableDeclaration") {
|
|
467
|
+
context.report({ node: declaration, messageId: "extra", data: { ...data, name: declaration.type } });
|
|
416
468
|
}
|
|
417
469
|
}
|
|
418
470
|
},
|
|
419
|
-
}
|
|
471
|
+
};
|
|
420
472
|
},
|
|
421
|
-
}
|
|
422
|
-
|
|
473
|
+
};
|
|
423
474
|
/** The rules this law contributes to the plugin. */
|
|
424
475
|
export const rules = {
|
|
425
476
|
"catch-must-account": catchMustAccount,
|
|
@@ -427,8 +478,7 @@ export const rules = {
|
|
|
427
478
|
"error-home": errorHome,
|
|
428
479
|
"throw-domain-error": throwDomainError,
|
|
429
480
|
"error-family-shape": errorFamilyShape,
|
|
430
|
-
}
|
|
431
|
-
|
|
481
|
+
};
|
|
432
482
|
/** All start at error: HFS has no baseline, and the migration lanes clear the debt before a repository adopts them. */
|
|
433
483
|
export const recommended = {
|
|
434
484
|
"starci-be/catch-must-account": "error",
|
|
@@ -436,4 +486,4 @@ export const recommended = {
|
|
|
436
486
|
"starci-be/error-home": "error",
|
|
437
487
|
"starci-be/throw-domain-error": "error",
|
|
438
488
|
"starci-be/error-family-shape": "error",
|
|
439
|
-
}
|
|
489
|
+
};
|