@starci/eslint-canon-be 3.5.0 → 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 +15 -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 +17 -10
- 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
|
@@ -15,22 +15,17 @@
|
|
|
15
15
|
* A receiver is recognised by its TYPE, an entity by its declaration (a class decorated with typeorm's `@Entity`), a builder file by
|
|
16
16
|
* its slot; nothing is matched by a name.
|
|
17
17
|
*/
|
|
18
|
-
import { basename } from "node:path"
|
|
19
|
-
import ts from "typescript"
|
|
20
|
-
import { INSERTING_SQL, isDatabaseReceiver, methodOf, queryText, WRITING_SQL } from "./lib/db-writes.
|
|
21
|
-
import { hfsOf } from "./lib/hfs.
|
|
22
|
-
import { moduleOf, typed } from "./lib/types.
|
|
23
|
-
|
|
18
|
+
import { basename } from "node:path";
|
|
19
|
+
import ts from "typescript";
|
|
20
|
+
import { INSERTING_SQL, isDatabaseReceiver, methodOf, queryText, WRITING_SQL } from "./lib/db-writes.js";
|
|
21
|
+
import { hfsOf } from "./lib/hfs.js";
|
|
22
|
+
import { moduleOf, resolvedSymbol, typed } from "./lib/types.js";
|
|
24
23
|
/** The file name of a linted path, in forward-slash form. */
|
|
25
|
-
const baseOf = (filename) => basename(String(filename || "").replace(/\\/g, "/"))
|
|
26
|
-
|
|
24
|
+
const baseOf = (filename) => basename(String(filename || "").replace(/\\/g, "/"));
|
|
27
25
|
// -- spec-no-raw-insert ----------------------------------------------------------------------------
|
|
28
|
-
|
|
29
|
-
const WRITE_METHODS = new Set(["save", "insert", "upsert", "update", "delete", "remove", "softDelete", "softRemove", "recover", "restore"])
|
|
30
|
-
|
|
26
|
+
const WRITE_METHODS = new Set(["save", "insert", "upsert", "update", "delete", "remove", "softDelete", "softRemove", "recover", "restore"]);
|
|
31
27
|
/** A unit service spec, an integration spec or an e2e spec. */
|
|
32
|
-
const isSpecName = (name) => /\.(?:spec|integration-spec|e2e-spec)\.[cm]?ts$/.test(name)
|
|
33
|
-
|
|
28
|
+
const isSpecName = (name) => /\.(?:spec|integration-spec|e2e-spec)\.[cm]?ts$/.test(name);
|
|
34
29
|
/** A spec arranges rows through a builder, never by writing them itself. */
|
|
35
30
|
export const specNoRawInsert = {
|
|
36
31
|
meta: {
|
|
@@ -43,48 +38,52 @@ export const specNoRawInsert = {
|
|
|
43
38
|
},
|
|
44
39
|
},
|
|
45
40
|
create(context) {
|
|
46
|
-
if (!isSpecName(baseOf(context.filename || context.getFilename())))
|
|
47
|
-
|
|
41
|
+
if (!isSpecName(baseOf(context.filename || context.getFilename())))
|
|
42
|
+
return {};
|
|
43
|
+
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
48
44
|
return {
|
|
49
45
|
CallExpression(node) {
|
|
50
|
-
const callee = node.callee
|
|
51
|
-
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (!
|
|
46
|
+
const callee = node.callee;
|
|
47
|
+
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
|
|
48
|
+
return;
|
|
49
|
+
const method = callee.property.name;
|
|
50
|
+
if (!WRITE_METHODS.has(method) && method !== "query")
|
|
51
|
+
return;
|
|
52
|
+
if (!isDatabaseReceiver(context, callee.object))
|
|
53
|
+
return;
|
|
55
54
|
if (method === "query") {
|
|
56
|
-
const text = queryText(node.arguments[0], sourceCode.getScope(node))
|
|
57
|
-
if (text !== null && WRITING_SQL.test(text))
|
|
58
|
-
|
|
55
|
+
const text = queryText(node.arguments[0], sourceCode.getScope(node));
|
|
56
|
+
if (text !== null && WRITING_SQL.test(text))
|
|
57
|
+
context.report({ node, messageId: "sql" });
|
|
58
|
+
return;
|
|
59
59
|
}
|
|
60
|
-
context.report({ node, messageId: "write", data: { method } })
|
|
60
|
+
context.report({ node, messageId: "write", data: { method } });
|
|
61
61
|
},
|
|
62
|
-
}
|
|
62
|
+
};
|
|
63
63
|
},
|
|
64
|
-
}
|
|
65
|
-
|
|
64
|
+
};
|
|
66
65
|
// -- spec-no-repeated-row-literal ------------------------------------------------------------------
|
|
67
|
-
|
|
68
66
|
/** True when a class declaration carries typeorm's `@Entity(...)`, resolved by where the decorator is declared. */
|
|
69
67
|
const isEntityClass = (checker, declaration) => {
|
|
70
|
-
if (!ts.isClassDeclaration(declaration))
|
|
68
|
+
if (!ts.isClassDeclaration(declaration))
|
|
69
|
+
return false;
|
|
71
70
|
return (ts.getDecorators(declaration) ?? []).some((decorator) => {
|
|
72
|
-
const callee = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression
|
|
73
|
-
const symbol = checker.getSymbolAtLocation(callee)
|
|
74
|
-
if (!symbol)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
|
|
71
|
+
const callee = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression;
|
|
72
|
+
const symbol = checker.getSymbolAtLocation(callee);
|
|
73
|
+
if (!symbol)
|
|
74
|
+
return false;
|
|
75
|
+
const target = resolvedSymbol(checker, symbol);
|
|
76
|
+
return (target?.getDeclarations?.() ?? []).some((found) => moduleOf(found, String(found.getSourceFile().fileName).replace(/\\/g, "/")) === "typeorm");
|
|
77
|
+
});
|
|
78
|
+
};
|
|
80
79
|
/** The entity class declarations a type stands for: itself, a union member, or the argument of a `Partial<Entity>` style alias. */
|
|
81
80
|
const entityClassesOf = (checker, type) => {
|
|
82
|
-
if (!type)
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
81
|
+
if (!type)
|
|
82
|
+
return [];
|
|
83
|
+
const parts = type.isUnion?.() ? type.types : [type];
|
|
84
|
+
const candidates = parts.flatMap((part) => [part, ...(part.aliasTypeArguments ?? [])]);
|
|
85
|
+
return candidates.flatMap((candidate) => (candidate.getSymbol?.()?.getDeclarations?.() ?? []).filter((declaration) => isEntityClass(checker, declaration)));
|
|
86
|
+
};
|
|
88
87
|
/** A spec builds each persistence entity as an object literal at most once; further rows come from a builder. */
|
|
89
88
|
export const specNoRepeatedRowLiteral = {
|
|
90
89
|
meta: {
|
|
@@ -96,48 +95,50 @@ export const specNoRepeatedRowLiteral = {
|
|
|
96
95
|
},
|
|
97
96
|
},
|
|
98
97
|
create(context) {
|
|
99
|
-
if (!isSpecName(baseOf(context.filename || context.getFilename())))
|
|
100
|
-
|
|
101
|
-
const
|
|
98
|
+
if (!isSpecName(baseOf(context.filename || context.getFilename())))
|
|
99
|
+
return {};
|
|
100
|
+
const { checker, toTs } = typed(context);
|
|
101
|
+
const firstLine = new Map();
|
|
102
102
|
return {
|
|
103
103
|
ObjectExpression(node) {
|
|
104
|
-
if (node.properties.length === 0 || node.properties.some((property) => property.type === "SpreadElement"))
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
if (node.properties.length === 0 || node.properties.some((property) => property.type === "SpreadElement"))
|
|
105
|
+
return;
|
|
106
|
+
const tsNode = toTs(node);
|
|
107
|
+
const [entity] = entityClassesOf(checker, tsNode && checker.getContextualType(tsNode));
|
|
108
|
+
if (!entity)
|
|
109
|
+
return;
|
|
110
|
+
const seen = firstLine.get(entity);
|
|
111
|
+
if (seen === undefined)
|
|
112
|
+
firstLine.set(entity, node.loc.start.line);
|
|
113
|
+
else
|
|
114
|
+
context.report({ node, messageId: "repeated", data: { entity: entity.name?.text ?? "entity", line: String(seen) } });
|
|
111
115
|
},
|
|
112
|
-
}
|
|
116
|
+
};
|
|
113
117
|
},
|
|
114
|
-
}
|
|
115
|
-
|
|
118
|
+
};
|
|
116
119
|
// -- persisting-builder-in-builders-slot -----------------------------------------------------------
|
|
117
|
-
|
|
118
|
-
const BUILDERS = "be.tests.fixtures.builders"
|
|
120
|
+
const BUILDERS = "be.tests.fixtures.builders";
|
|
119
121
|
/** The spec slots of the test tree; a spec is judged by the spec rules, not as a builder. */
|
|
120
|
-
const SPEC_SLOTS = new Set(["be.tests.integration", "be.tests.e2e", "be.tests.contract"])
|
|
121
|
-
const CREATING_METHODS = new Set(["save", "insert", "upsert"])
|
|
122
|
-
|
|
122
|
+
const SPEC_SLOTS = new Set(["be.tests.integration", "be.tests.e2e", "be.tests.contract"]);
|
|
123
|
+
const CREATING_METHODS = new Set(["save", "insert", "upsert"]);
|
|
123
124
|
/** A file of the test tree that is not a spec and is not the builders slot. */
|
|
124
|
-
const isTestSupport = (slot) => typeof slot === "string" && slot.startsWith("be.tests.") && slot !== BUILDERS && !SPEC_SLOTS.has(slot)
|
|
125
|
-
|
|
125
|
+
const isTestSupport = (slot) => typeof slot === "string" && slot.startsWith("be.tests.") && slot !== BUILDERS && !SPEC_SLOTS.has(slot);
|
|
126
126
|
/** The top-level statement that holds a node. */
|
|
127
127
|
const topStatementOf = (node) => {
|
|
128
|
-
let current = node
|
|
129
|
-
while (current.parent && current.parent.type !== "Program")
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
128
|
+
let current = node;
|
|
129
|
+
while (current.parent && current.parent.type !== "Program")
|
|
130
|
+
current = current.parent;
|
|
131
|
+
return current;
|
|
132
|
+
};
|
|
133
133
|
/** The names a top-level statement declares. */
|
|
134
134
|
const declaredNames = (statement) => {
|
|
135
|
-
const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement
|
|
136
|
-
if (!declaration)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
135
|
+
const declaration = statement.type === "ExportNamedDeclaration" ? statement.declaration : statement;
|
|
136
|
+
if (!declaration)
|
|
137
|
+
return [];
|
|
138
|
+
if (declaration.type === "VariableDeclaration")
|
|
139
|
+
return declaration.declarations.flatMap((entry) => (entry.id.type === "Identifier" ? [entry.id.name] : []));
|
|
140
|
+
return "id" in declaration && declaration.id && declaration.id.type === "Identifier" ? [declaration.id.name] : [];
|
|
141
|
+
};
|
|
141
142
|
/** A module of the test tree that exports something creating persisted rows is a builder and lives in the builders slot. */
|
|
142
143
|
export const persistingBuilderInBuildersSlot = {
|
|
143
144
|
meta: {
|
|
@@ -149,45 +150,52 @@ export const persistingBuilderInBuildersSlot = {
|
|
|
149
150
|
},
|
|
150
151
|
},
|
|
151
152
|
create(context) {
|
|
152
|
-
if (!isTestSupport(hfsOf(context).slotOf(context.filename || context.getFilename())))
|
|
153
|
-
|
|
154
|
-
const
|
|
155
|
-
const
|
|
153
|
+
if (!isTestSupport(hfsOf(context).slotOf(context.filename || context.getFilename())))
|
|
154
|
+
return {};
|
|
155
|
+
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
156
|
+
const writes = new Set();
|
|
157
|
+
const references = new Map();
|
|
156
158
|
const isCreation = (node) => {
|
|
157
|
-
const method = methodOf(node)
|
|
158
|
-
if (!method || !isDatabaseReceiver(context, node.callee.object))
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
159
|
+
const method = methodOf(node);
|
|
160
|
+
if (!method || node.callee.type !== "MemberExpression" || !isDatabaseReceiver(context, node.callee.object))
|
|
161
|
+
return false;
|
|
162
|
+
if (CREATING_METHODS.has(method))
|
|
163
|
+
return true;
|
|
164
|
+
return method === "query" && INSERTING_SQL.test(queryText(node.arguments[0], sourceCode.getScope(node)) ?? "");
|
|
165
|
+
};
|
|
162
166
|
return {
|
|
163
167
|
CallExpression(node) {
|
|
164
|
-
if (isCreation(node))
|
|
168
|
+
if (isCreation(node))
|
|
169
|
+
writes.add(topStatementOf(node));
|
|
165
170
|
},
|
|
166
171
|
Identifier(node) {
|
|
167
|
-
const statement = topStatementOf(node)
|
|
168
|
-
|
|
169
|
-
|
|
172
|
+
const statement = topStatementOf(node);
|
|
173
|
+
let names = references.get(statement);
|
|
174
|
+
if (!names) {
|
|
175
|
+
names = new Set();
|
|
176
|
+
references.set(statement, names);
|
|
177
|
+
}
|
|
178
|
+
names.add(node.name);
|
|
170
179
|
},
|
|
171
180
|
"Program:exit"(program) {
|
|
172
|
-
const exported = new Set(program.body.flatMap((statement) => (statement.type === "ExportNamedDeclaration" && !statement.declaration && !statement.source ? statement.specifiers.map((specifier) => specifier.local.name) : [])))
|
|
173
|
-
const writerNames = new Set(program.body.filter((statement) => writes.has(statement)).flatMap(declaredNames))
|
|
181
|
+
const exported = new Set(program.body.flatMap((statement) => (statement.type === "ExportNamedDeclaration" && !statement.declaration && !statement.source ? statement.specifiers.map((specifier) => specifier.local.name) : [])));
|
|
182
|
+
const writerNames = new Set(program.body.filter((statement) => writes.has(statement)).flatMap(declaredNames));
|
|
174
183
|
for (const statement of program.body) {
|
|
175
|
-
const isExported = statement.type === "ExportNamedDeclaration" ? Boolean(statement.declaration) : declaredNames(statement).some((name) => exported.has(name))
|
|
176
|
-
if (!isExported)
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
184
|
+
const isExported = statement.type === "ExportNamedDeclaration" ? Boolean(statement.declaration) : declaredNames(statement).some((name) => exported.has(name));
|
|
185
|
+
if (!isExported)
|
|
186
|
+
continue;
|
|
187
|
+
const uses = references.get(statement) ?? new Set();
|
|
188
|
+
if (!writes.has(statement) && ![...uses].some((name) => writerNames.has(name)))
|
|
189
|
+
continue;
|
|
190
|
+
context.report({ node: statement, messageId: "misplaced", data: { name: declaredNames(statement)[0] ?? "This export" } });
|
|
180
191
|
}
|
|
181
192
|
},
|
|
182
|
-
}
|
|
193
|
+
};
|
|
183
194
|
},
|
|
184
|
-
}
|
|
185
|
-
|
|
195
|
+
};
|
|
186
196
|
// -- builder-arranges-only -------------------------------------------------------------------------
|
|
187
|
-
|
|
188
|
-
const
|
|
189
|
-
const RANDOM_FUNCTIONS = new Set(["randomUUID", "randomBytes", "randomInt", "randomFillSync", "randomFill", "getRandomValues"])
|
|
190
|
-
|
|
197
|
+
const JEST_GLOBALS = new Set(["expect", "jest", "describe", "it", "test", "beforeAll", "beforeEach", "afterAll", "afterEach", "fail"]);
|
|
198
|
+
const RANDOM_FUNCTIONS = new Set(["randomUUID", "randomBytes", "randomInt", "randomFillSync", "randomFill", "getRandomValues"]);
|
|
191
199
|
/** A builder arranges data only: no assertion, deterministic defaults. */
|
|
192
200
|
export const builderArrangesOnly = {
|
|
193
201
|
meta: {
|
|
@@ -200,48 +208,53 @@ export const builderArrangesOnly = {
|
|
|
200
208
|
},
|
|
201
209
|
},
|
|
202
210
|
create(context) {
|
|
203
|
-
if (hfsOf(context).slotOf(context.filename || context.getFilename()) !== BUILDERS)
|
|
204
|
-
|
|
211
|
+
if (hfsOf(context).slotOf(context.filename || context.getFilename()) !== BUILDERS)
|
|
212
|
+
return {};
|
|
213
|
+
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
205
214
|
/** True when the identifier is not declared in the file (a framework global, not a local named `test`). */
|
|
206
215
|
const isGlobal = (node) => {
|
|
207
216
|
for (let scope = sourceCode.getScope(node); scope; scope = scope.upper) {
|
|
208
|
-
const variable = scope.set.get(node.name)
|
|
209
|
-
if (variable)
|
|
217
|
+
const variable = scope.set.get(node.name);
|
|
218
|
+
if (variable)
|
|
219
|
+
return variable.defs.length === 0;
|
|
210
220
|
}
|
|
211
|
-
return true
|
|
212
|
-
}
|
|
221
|
+
return true;
|
|
222
|
+
};
|
|
213
223
|
return {
|
|
214
224
|
ImportDeclaration(node) {
|
|
215
|
-
if (["expect", "@jest/globals"].includes(node.source.value))
|
|
225
|
+
if (["expect", "@jest/globals"].includes(node.source.value))
|
|
226
|
+
context.report({ node, messageId: "assertion", data: { name: node.source.value } });
|
|
216
227
|
},
|
|
217
228
|
Identifier(node) {
|
|
218
|
-
const parent = node.parent
|
|
219
|
-
const used = (parent.type === "CallExpression" && parent.callee === node) || (parent.type === "MemberExpression" && parent.object === node)
|
|
220
|
-
if (used && JEST_GLOBALS.has(node.name) && isGlobal(node))
|
|
229
|
+
const parent = node.parent;
|
|
230
|
+
const used = (parent.type === "CallExpression" && parent.callee === node) || (parent.type === "MemberExpression" && parent.object === node);
|
|
231
|
+
if (used && JEST_GLOBALS.has(node.name) && isGlobal(node))
|
|
232
|
+
context.report({ node, messageId: "assertion", data: { name: node.name } });
|
|
221
233
|
},
|
|
222
234
|
CallExpression(node) {
|
|
223
|
-
const callee = node.callee
|
|
235
|
+
const callee = node.callee;
|
|
224
236
|
if (callee.type === "Identifier" && RANDOM_FUNCTIONS.has(callee.name)) {
|
|
225
|
-
context.report({ node, messageId: "random", data: { name: `${callee.name}()` } })
|
|
226
|
-
return
|
|
237
|
+
context.report({ node, messageId: "random", data: { name: `${callee.name}()` } });
|
|
238
|
+
return;
|
|
227
239
|
}
|
|
228
|
-
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier" || callee.object.type !== "Identifier")
|
|
229
|
-
|
|
230
|
-
const
|
|
231
|
-
const
|
|
232
|
-
const
|
|
233
|
-
const
|
|
234
|
-
|
|
240
|
+
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier" || callee.object.type !== "Identifier")
|
|
241
|
+
return;
|
|
242
|
+
const owner = callee.object.name;
|
|
243
|
+
const method = callee.property.name;
|
|
244
|
+
const clock = owner === "Date" && method === "now";
|
|
245
|
+
const dice = owner === "Math" && method === "random";
|
|
246
|
+
const crypto = RANDOM_FUNCTIONS.has(method) || (/^(?:crypto|webcrypto)$/.test(owner) && method.startsWith("random"));
|
|
247
|
+
if (clock || dice || crypto)
|
|
248
|
+
context.report({ node, messageId: "random", data: { name: `${owner}.${method}()` } });
|
|
235
249
|
},
|
|
236
250
|
NewExpression(node) {
|
|
237
|
-
if (node.callee.type === "Identifier" && node.callee.name === "Date" && node.arguments.length === 0)
|
|
251
|
+
if (node.callee.type === "Identifier" && node.callee.name === "Date" && node.arguments.length === 0)
|
|
252
|
+
context.report({ node, messageId: "random", data: { name: "new Date()" } });
|
|
238
253
|
},
|
|
239
|
-
}
|
|
254
|
+
};
|
|
240
255
|
},
|
|
241
|
-
}
|
|
242
|
-
|
|
256
|
+
};
|
|
243
257
|
// -- tests-keep-constraints ------------------------------------------------------------------------
|
|
244
|
-
|
|
245
258
|
const CONSTRAINT_SQL = [
|
|
246
259
|
/session_replication_role/i,
|
|
247
260
|
/\bDISABLE\s+TRIGGER\b/i,
|
|
@@ -250,9 +263,8 @@ const CONSTRAINT_SQL = [
|
|
|
250
263
|
/\bSET\s+CONSTRAINTS\b[\s\S]*\bDEFERRED\b/i,
|
|
251
264
|
/\bALTER\s+TABLE\b[\s\S]*\bDISABLE\b/i,
|
|
252
265
|
/\bDROP\s+CONSTRAINT\b/i,
|
|
253
|
-
]
|
|
254
|
-
const CONSTRAINT_METHODS = new Set(["dropForeignKey", "dropForeignKeys", "dropCheckConstraint", "dropCheckConstraints", "dropUniqueConstraint", "dropUniqueConstraints"])
|
|
255
|
-
|
|
266
|
+
];
|
|
267
|
+
const CONSTRAINT_METHODS = new Set(["dropForeignKey", "dropForeignKeys", "dropCheckConstraint", "dropCheckConstraints", "dropUniqueConstraint", "dropUniqueConstraints"]);
|
|
256
268
|
/** The test tree keeps every database constraint on. */
|
|
257
269
|
export const testsKeepConstraints = {
|
|
258
270
|
meta: {
|
|
@@ -265,27 +277,32 @@ export const testsKeepConstraints = {
|
|
|
265
277
|
},
|
|
266
278
|
},
|
|
267
279
|
create(context) {
|
|
268
|
-
const slot = hfsOf(context).slotOf(context.filename || context.getFilename())
|
|
269
|
-
if (typeof slot !== "string" || !slot.startsWith("be.tests."))
|
|
270
|
-
|
|
280
|
+
const slot = hfsOf(context).slotOf(context.filename || context.getFilename());
|
|
281
|
+
if (typeof slot !== "string" || !slot.startsWith("be.tests."))
|
|
282
|
+
return {};
|
|
283
|
+
const sourceCode = context.sourceCode || context.getSourceCode();
|
|
271
284
|
const check = (node, text) => {
|
|
272
|
-
const found = CONSTRAINT_SQL.find((pattern) => pattern.test(text ?? ""))
|
|
273
|
-
|
|
274
|
-
|
|
285
|
+
const found = CONSTRAINT_SQL.find((pattern) => pattern.test(text ?? ""));
|
|
286
|
+
const what = found ? text?.match(found) : null;
|
|
287
|
+
if (found && what)
|
|
288
|
+
context.report({ node, messageId: "sql", data: { what: what[0] } });
|
|
289
|
+
};
|
|
275
290
|
return {
|
|
276
291
|
CallExpression(node) {
|
|
277
|
-
const method = methodOf(node)
|
|
278
|
-
if (!method || !isDatabaseReceiver(context, node.callee.object))
|
|
279
|
-
|
|
280
|
-
|
|
292
|
+
const method = methodOf(node);
|
|
293
|
+
if (!method || node.callee.type !== "MemberExpression" || !isDatabaseReceiver(context, node.callee.object))
|
|
294
|
+
return;
|
|
295
|
+
if (method === "query")
|
|
296
|
+
check(node, queryText(node.arguments[0], sourceCode.getScope(node)));
|
|
297
|
+
else if (CONSTRAINT_METHODS.has(method))
|
|
298
|
+
context.report({ node, messageId: "method", data: { method } });
|
|
281
299
|
},
|
|
282
300
|
TaggedTemplateExpression(node) {
|
|
283
|
-
check(node, queryText(node, null))
|
|
301
|
+
check(node, queryText(node, null));
|
|
284
302
|
},
|
|
285
|
-
}
|
|
303
|
+
};
|
|
286
304
|
},
|
|
287
|
-
}
|
|
288
|
-
|
|
305
|
+
};
|
|
289
306
|
/** The rules this law contributes to the plugin. */
|
|
290
307
|
export const rules = {
|
|
291
308
|
"persisting-builder-in-builders-slot": persistingBuilderInBuildersSlot,
|
|
@@ -293,8 +310,7 @@ export const rules = {
|
|
|
293
310
|
"spec-no-repeated-row-literal": specNoRepeatedRowLiteral,
|
|
294
311
|
"builder-arranges-only": builderArrangesOnly,
|
|
295
312
|
"tests-keep-constraints": testsKeepConstraints,
|
|
296
|
-
}
|
|
297
|
-
|
|
313
|
+
};
|
|
298
314
|
/** Every rule of this law ships at `error`. */
|
|
299
315
|
export const recommended = {
|
|
300
316
|
"starci-be/persisting-builder-in-builders-slot": "error",
|
|
@@ -302,4 +318,4 @@ export const recommended = {
|
|
|
302
318
|
"starci-be/spec-no-repeated-row-literal": "error",
|
|
303
319
|
"starci-be/builder-arranges-only": "error",
|
|
304
320
|
"starci-be/tests-keep-constraints": "error",
|
|
305
|
-
}
|
|
321
|
+
};
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Recommended, RuleModule } from "./lib/rule.js";
|
|
2
|
+
/** The cli app boots with CommandFactory.run and never serves HTTP or a microservice. */
|
|
3
|
+
export declare const cliBootstrap: RuleModule;
|
|
4
|
+
/** A nest-commander command is declared only where the cli feature root keeps it, one per file, a sub-command a CommandRunner. */
|
|
5
|
+
export declare const cliCommandShape: RuleModule;
|
|
6
|
+
/** nest-commander belongs to the cli app and the cli feature root; nothing else parses arguments or opens an action door. */
|
|
7
|
+
export declare const cliOwner: RuleModule;
|
|
8
|
+
/** The rules this law contributes to the plugin. */
|
|
9
|
+
export declare const rules: {
|
|
10
|
+
"cli-bootstrap": RuleModule;
|
|
11
|
+
"cli-command-shape": RuleModule;
|
|
12
|
+
"cli-owner": RuleModule;
|
|
13
|
+
};
|
|
14
|
+
/** Every rule is an error from the start: HFS keeps no baseline. */
|
|
15
|
+
export declare const recommended: Recommended;
|