@starci/eslint-canon-be 3.5.0 → 3.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/README.md +13 -2
- package/dist/ambient-id.d.ts +9 -0
- package/{ambient-id.mjs → dist/ambient-id.js} +43 -39
- package/dist/app-composition.d.ts +21 -0
- package/{app-composition.mjs → dist/app-composition.js} +396 -300
- package/dist/async-discipline.d.ts +9 -0
- package/dist/async-discipline.js +77 -0
- package/dist/authorization.d.ts +12 -0
- package/{authorization.mjs → dist/authorization.js} +53 -59
- package/dist/boundary-schema.d.ts +15 -0
- package/{boundary-schema.mjs → dist/boundary-schema.js} +120 -105
- package/dist/builders.d.ts +21 -0
- package/{builders.mjs → dist/builders.js} +162 -146
- package/dist/cli.d.ts +15 -0
- package/{cli.mjs → dist/cli.js} +97 -82
- package/dist/comments.d.ts +52 -0
- package/dist/comments.js +412 -0
- package/dist/config-owner.d.ts +24 -0
- package/{config-owner.mjs → dist/config-owner.js} +256 -219
- package/dist/connections.d.ts +12 -0
- package/{connections.mjs → dist/connections.js} +138 -140
- package/dist/cookies.d.ts +9 -0
- package/{cookies.mjs → dist/cookies.js} +58 -58
- package/dist/cqrs.d.ts +27 -0
- package/{cqrs.mjs → dist/cqrs.js} +341 -282
- package/dist/data-access.d.ts +50 -0
- package/{data-access.mjs → dist/data-access.js} +238 -243
- package/dist/default-deny.d.ts +15 -0
- package/{default-deny.mjs → dist/default-deny.js} +103 -88
- package/dist/e2e-flow.d.ts +25 -0
- package/{e2e-flow.mjs → dist/e2e-flow.js} +113 -112
- package/dist/edge-hardening.d.ts +10 -0
- package/dist/edge-hardening.js +173 -0
- package/dist/error-handling.d.ts +21 -0
- package/{error-handling.mjs → dist/error-handling.js} +289 -239
- package/dist/event-bus.d.ts +14 -0
- package/{event-bus.mjs → dist/event-bus.js} +146 -129
- package/dist/feature-thin.d.ts +12 -0
- package/{feature-thin.mjs → dist/feature-thin.js} +208 -191
- package/dist/function-budget.d.ts +7 -0
- package/{function-budget.mjs → dist/function-budget.js} +24 -27
- package/dist/health-ready.d.ts +10 -0
- package/dist/health-ready.js +703 -0
- package/dist/idempotency.d.ts +10 -0
- package/{idempotency.mjs → dist/idempotency.js} +296 -226
- package/dist/index.d.ts +54 -0
- package/{index.mjs → dist/index.js} +91 -109
- package/dist/infra-owner.d.ts +18 -0
- package/{infra-owner.mjs → dist/infra-owner.js} +58 -51
- package/dist/injection.d.ts +30 -0
- package/{injection.mjs → dist/injection.js} +397 -344
- package/dist/input-bounds.d.ts +15 -0
- package/{input-bounds.mjs → dist/input-bounds.js} +143 -132
- package/dist/jobs.d.ts +17 -0
- package/{jobs.mjs → dist/jobs.js} +116 -99
- package/dist/jwt-alg.d.ts +6 -0
- package/dist/jwt-alg.js +49 -0
- package/dist/lib/app-roles.d.ts +25 -0
- package/{lib/app-roles.mjs → dist/lib/app-roles.js} +15 -17
- package/dist/lib/ast.d.ts +40 -0
- package/dist/lib/ast.js +100 -0
- package/dist/lib/client-idempotency.d.ts +3 -0
- package/{lib/client-idempotency.mjs → dist/lib/client-idempotency.js} +316 -268
- package/dist/lib/config.d.ts +36 -0
- package/{lib/config.mjs → dist/lib/config.js} +24 -27
- package/dist/lib/db-writes.d.ts +29 -0
- package/{lib/db-writes.mjs → dist/lib/db-writes.js} +27 -27
- package/dist/lib/declared.d.ts +77 -0
- package/{lib/declared.mjs → dist/lib/declared.js} +83 -78
- package/dist/lib/doors.d.ts +50 -0
- package/{lib/doors.mjs → dist/lib/doors.js} +45 -50
- package/dist/lib/edition.d.ts +25 -0
- package/{lib/edition.mjs → dist/lib/edition.js} +15 -20
- package/dist/lib/entity-writes.d.ts +7 -0
- package/{lib/entity-writes.mjs → dist/lib/entity-writes.js} +31 -22
- package/dist/lib/hfs-view.d.ts +127 -0
- package/dist/lib/hfs-view.js +1 -0
- package/dist/lib/hfs.d.ts +34 -0
- package/{lib/hfs.mjs → dist/lib/hfs.js} +31 -29
- package/dist/lib/import-source.d.ts +63 -0
- package/dist/lib/import-source.js +134 -0
- package/dist/lib/path.d.ts +8 -0
- package/{lib/path.mjs → dist/lib/path.js} +4 -7
- package/dist/lib/persistence.d.ts +115 -0
- package/{lib/persistence.mjs → dist/lib/persistence.js} +55 -66
- package/dist/lib/ports.d.ts +70 -0
- package/{lib/ports.mjs → dist/lib/ports.js} +62 -66
- package/dist/lib/rule.d.ts +31 -0
- package/dist/lib/rule.js +2 -0
- package/dist/lib/runtime-root.d.ts +4 -0
- package/dist/lib/runtime-root.js +10 -0
- package/dist/lib/schema-values.d.ts +13 -0
- package/{lib/schema-values.mjs → dist/lib/schema-values.js} +67 -59
- package/dist/lib/specifier.d.ts +12 -0
- package/dist/lib/specifier.js +29 -0
- package/dist/lib/subject-values.d.ts +4 -0
- package/dist/lib/subject-values.js +61 -0
- package/dist/lib/transactions.d.ts +18 -0
- package/{lib/transactions.mjs → dist/lib/transactions.js} +17 -15
- package/dist/lib/transport-slots.d.ts +17 -0
- package/{lib/transport-slots.mjs → dist/lib/transport-slots.js} +2 -4
- package/dist/lib/types.d.ts +96 -0
- package/dist/lib/types.js +150 -0
- package/dist/lib/unit-spec.d.ts +48 -0
- package/{lib/unit-spec.mjs → dist/lib/unit-spec.js} +35 -44
- package/dist/lib/webhook-ack.d.ts +4 -0
- package/{lib/webhook-ack.mjs → dist/lib/webhook-ack.js} +78 -62
- package/dist/lib/webhook-handoff-inbox.d.ts +3 -0
- package/{lib/webhook-handoff-inbox.mjs → dist/lib/webhook-handoff-inbox.js} +195 -167
- package/dist/lib/webhook-handoff-intake.d.ts +4 -0
- package/{lib/webhook-handoff-intake.mjs → dist/lib/webhook-handoff-intake.js} +125 -102
- package/dist/lib/webhook-handoff.d.ts +15 -0
- package/{lib/webhook-handoff.mjs → dist/lib/webhook-handoff.js} +107 -100
- package/dist/lib/webhook-verifiers.d.ts +20 -0
- package/{lib/webhook-verifiers.mjs → dist/lib/webhook-verifiers.js} +108 -104
- package/dist/lib/why.d.ts +9 -0
- package/{lib/why.mjs → dist/lib/why.js} +6 -6
- package/dist/log-safety.d.ts +20 -0
- package/dist/log-safety.js +308 -0
- package/dist/module-layering.d.ts +42 -0
- package/dist/module-layering.js +257 -0
- package/dist/module-shape.d.ts +47 -0
- package/{module-shape.mjs → dist/module-shape.js} +278 -236
- package/dist/naming.d.ts +49 -0
- package/dist/naming.js +246 -0
- package/dist/observability.d.ts +25 -0
- package/dist/observability.js +245 -0
- package/dist/operations.d.ts +23 -0
- package/{operations.mjs → dist/operations.js} +410 -332
- package/dist/project-graph.d.ts +9 -0
- package/{project-graph.mjs → dist/project-graph.js} +8 -13
- package/dist/projections.d.ts +11 -0
- package/{projections.mjs → dist/projections.js} +60 -57
- package/dist/query-safety.d.ts +21 -0
- package/{query-safety.mjs → dist/query-safety.js} +92 -108
- package/dist/realtime.d.ts +15 -0
- package/{realtime.mjs → dist/realtime.js} +108 -106
- package/dist/resilience.d.ts +15 -0
- package/dist/resilience.js +319 -0
- package/dist/schema-authority.d.ts +15 -0
- package/{schema-authority.mjs → dist/schema-authority.js} +256 -220
- package/dist/service-deps.d.ts +17 -0
- package/{service-deps.mjs → dist/service-deps.js} +133 -130
- package/dist/service-isolation.d.ts +8 -0
- package/dist/service-isolation.js +76 -0
- package/dist/size-budget.d.ts +9 -0
- package/{size-budget.mjs → dist/size-budget.js} +27 -27
- package/dist/sonar-parity.d.ts +5 -0
- package/{sonar-parity.mjs → dist/sonar-parity.js} +7 -7
- package/dist/spec-no-skip.d.ts +9 -0
- package/dist/spec-no-skip.js +81 -0
- package/dist/spec-quality.d.ts +10 -0
- package/{spec-quality.mjs → dist/spec-quality.js} +103 -87
- package/dist/suppression.d.ts +26 -0
- package/{suppression.mjs → dist/suppression.js} +30 -45
- package/dist/temporal.d.ts +9 -0
- package/{temporal.mjs → dist/temporal.js} +75 -65
- package/dist/test-world.d.ts +28 -0
- package/{test-world.mjs → dist/test-world.js} +102 -83
- package/dist/testing.d.ts +51 -0
- package/dist/testing.js +368 -0
- package/dist/third-party-owner.d.ts +8 -0
- package/{third-party-owner.mjs → dist/third-party-owner.js} +105 -91
- package/dist/transport.d.ts +24 -0
- package/{transport.mjs → dist/transport.js} +279 -240
- package/dist/type-safety.d.ts +25 -0
- package/dist/type-safety.js +297 -0
- package/dist/unit-spec.d.ts +30 -0
- package/{unit-spec.mjs → dist/unit-spec.js} +473 -399
- package/dist/uploads.d.ts +9 -0
- package/{uploads.mjs → dist/uploads.js} +62 -54
- package/dist/user-copy.d.ts +9 -0
- package/{user-copy.mjs → dist/user-copy.js} +76 -67
- package/dist/webhooks.d.ts +16 -0
- package/{webhooks.mjs → dist/webhooks.js} +243 -231
- package/package.json +23 -8
- package/runtime/knowledge/hfs/canon-pins.yaml +18 -11
- package/runtime/scripts/hfs/repo-identity.mjs +5 -4
- package/async-discipline.mjs +0 -83
- package/comments.mjs +0 -416
- package/edge-hardening.mjs +0 -139
- package/health-ready.mjs +0 -539
- package/jwt-alg.mjs +0 -45
- package/lib/ast.mjs +0 -88
- package/lib/import-source.mjs +0 -104
- package/lib/specifier.mjs +0 -27
- package/lib/subject-values.mjs +0 -55
- package/lib/types.mjs +0 -133
- package/log-safety.mjs +0 -303
- package/module-layering.mjs +0 -270
- package/naming.mjs +0 -251
- package/observability.mjs +0 -241
- package/resilience.mjs +0 -304
- package/service-isolation.mjs +0 -75
- package/spec-no-skip.mjs +0 -85
- package/testing.mjs +0 -384
- package/type-safety.mjs +0 -323
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Recommended, RuleModule } from "./lib/rule.js";
|
|
2
|
+
/** The schema is decided by migrations run by the cli migrate command, never by the running process. */
|
|
3
|
+
export declare const noRuntimeSchema: RuleModule;
|
|
4
|
+
/** An ORM entity type never appears in a contract, DTO, command or query, transport signature or handler `execute`. */
|
|
5
|
+
export declare const noEntityInContract: RuleModule;
|
|
6
|
+
/** A migration can be undone. */
|
|
7
|
+
export declare const migrationDownReversible: RuleModule;
|
|
8
|
+
/** The rules this law contributes to the plugin. */
|
|
9
|
+
export declare const rules: {
|
|
10
|
+
"no-runtime-schema": RuleModule;
|
|
11
|
+
"no-entity-in-contract": RuleModule;
|
|
12
|
+
"migration-down-reversible": RuleModule;
|
|
13
|
+
};
|
|
14
|
+
/** All three start at error: HFS keeps no baseline and the schema migration lanes clear the debt first. */
|
|
15
|
+
export declare const recommended: Recommended;
|
|
@@ -21,120 +21,104 @@
|
|
|
21
21
|
* Where a file lives is asked of the slot view (`be.persistence` and its `migrations/` folder, the transport slots),
|
|
22
22
|
* never of a path pattern.
|
|
23
23
|
*/
|
|
24
|
-
import ts from "typescript"
|
|
25
|
-
import { isTransportSlot } from "./lib/transport-slots.
|
|
26
|
-
import { keyName, walk } from "./lib/ast.
|
|
27
|
-
import { hfsOf, inTestWorld } from "./lib/hfs.
|
|
28
|
-
import { baseName, isMigrationFile, packageOfFile } from "./lib/ports.
|
|
29
|
-
import { inCli } from "./lib/persistence.
|
|
30
|
-
import { isPackageType, typed } from "./lib/types.
|
|
31
|
-
import { isDeclarationFile } from "./lib/path.
|
|
32
|
-
|
|
24
|
+
import ts from "typescript";
|
|
25
|
+
import { isTransportSlot } from "./lib/transport-slots.js";
|
|
26
|
+
import { keyName, walk } from "./lib/ast.js";
|
|
27
|
+
import { hfsOf, inTestWorld } from "./lib/hfs.js";
|
|
28
|
+
import { baseName, isMigrationFile, packageOfFile } from "./lib/ports.js";
|
|
29
|
+
import { inCli } from "./lib/persistence.js";
|
|
30
|
+
import { isPackageType, isTsNode, typed } from "./lib/types.js";
|
|
31
|
+
import { isDeclarationFile } from "./lib/path.js";
|
|
33
32
|
/** Schema-changing statements: `CREATE|ALTER|DROP` of a structure, `TRUNCATE TABLE`, `ADD|DROP COLUMN`. */
|
|
34
|
-
const DDL = /\b(?:(?:CREATE|ALTER|DROP)\s+(?:OR\s+REPLACE\s+)?(?:UNIQUE\s+)?(?:TEMP(?:ORARY)?\s+)?(?:TABLE|INDEX|TYPE|SCHEMA|VIEW|MATERIALIZED\s+VIEW|SEQUENCE|EXTENSION|DATABASE|TRIGGER|FUNCTION|PROCEDURE|DOMAIN|POLICY|PUBLICATION|COLLATION|ROLE)|TRUNCATE\s+TABLE|(?:ADD|DROP)\s+(?:COLUMN|CONSTRAINT))\b/i
|
|
35
|
-
|
|
33
|
+
const DDL = /\b(?:(?:CREATE|ALTER|DROP)\s+(?:OR\s+REPLACE\s+)?(?:UNIQUE\s+)?(?:TEMP(?:ORARY)?\s+)?(?:TABLE|INDEX|TYPE|SCHEMA|VIEW|MATERIALIZED\s+VIEW|SEQUENCE|EXTENSION|DATABASE|TRIGGER|FUNCTION|PROCEDURE|DOMAIN|POLICY|PUBLICATION|COLLATION|ROLE)|TRUNCATE\s+TABLE|(?:ADD|DROP)\s+(?:COLUMN|CONSTRAINT))\b/i;
|
|
36
34
|
/** The packages whose option types describe a DataSource. */
|
|
37
|
-
const OPTION_PACKAGES = new Set(["typeorm", "@nestjs/typeorm"])
|
|
38
|
-
|
|
35
|
+
const OPTION_PACKAGES = new Set(["typeorm", "@nestjs/typeorm"]);
|
|
39
36
|
/** The DataSource operations that change the schema at runtime. */
|
|
40
|
-
const SCHEMA_OPERATIONS = new Set(["synchronize", "dropDatabase"])
|
|
41
|
-
|
|
37
|
+
const SCHEMA_OPERATIONS = new Set(["synchronize", "dropDatabase"]);
|
|
42
38
|
/** The DataSource operations that run migrations: allowed only in the cli (apps/cli, src/features/cli) and the test world. */
|
|
43
|
-
const MIGRATION_RUNNERS = new Set(["runMigrations", "undoLastMigration"])
|
|
44
|
-
|
|
39
|
+
const MIGRATION_RUNNERS = new Set(["runMigrations", "undoLastMigration"]);
|
|
45
40
|
/** The typeorm types whose methods write rows. */
|
|
46
|
-
const WRITER_TYPES = ["EntityManager", "DataSource", "QueryRunner"]
|
|
47
|
-
|
|
41
|
+
const WRITER_TYPES = ["EntityManager", "DataSource", "QueryRunner"];
|
|
48
42
|
/** The typeorm schema builder types. */
|
|
49
|
-
const SCHEMA_BUILDER_TYPES = ["SchemaBuilder", "RdbmsSchemaBuilder"]
|
|
50
|
-
|
|
43
|
+
const SCHEMA_BUILDER_TYPES = ["SchemaBuilder", "RdbmsSchemaBuilder"];
|
|
51
44
|
/** The writes of an `EntityManager` that need no SQL text to be recognised. */
|
|
52
|
-
const WRITE_METHODS = new Set(["insert", "save", "upsert", "update", "delete", "remove", "softRemove", "softDelete", "recover", "increment", "decrement", "clear"])
|
|
53
|
-
|
|
45
|
+
const WRITE_METHODS = new Set(["insert", "save", "upsert", "update", "delete", "remove", "softRemove", "softDelete", "recover", "increment", "decrement", "clear"]);
|
|
54
46
|
/** A statement that writes rows. */
|
|
55
|
-
const WRITE_SQL = /\b(?:INSERT\s+INTO|UPDATE\s+\S+\s+SET|DELETE\s+FROM|MERGE\s+INTO)\b/i
|
|
56
|
-
|
|
47
|
+
const WRITE_SQL = /\b(?:INSERT\s+INTO|UPDATE\s+\S+\s+SET|DELETE\s+FROM|MERGE\s+INTO)\b/i;
|
|
57
48
|
/** The Nest lifecycle hooks that run at boot in every process that composes the provider. */
|
|
58
|
-
const BOOT_HOOKS = new Set(["onModuleInit", "onApplicationBootstrap"])
|
|
59
|
-
|
|
60
|
-
const isFalse = (node) => node?.type === "Literal" && node.value === false
|
|
61
|
-
|
|
49
|
+
const BOOT_HOOKS = new Set(["onModuleInit", "onApplicationBootstrap"]);
|
|
50
|
+
const isFalse = (node) => node?.type === "Literal" && node.value === false;
|
|
62
51
|
/** The text of every string literal and template chunk under `node`. */
|
|
63
52
|
const stringsUnder = (node) => {
|
|
64
|
-
const found = []
|
|
53
|
+
const found = [];
|
|
65
54
|
walk(node, (child) => {
|
|
66
|
-
if (child.type === "Literal" && typeof child.value === "string")
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
55
|
+
if (child.type === "Literal" && typeof child.value === "string")
|
|
56
|
+
found.push(child.value);
|
|
57
|
+
else if (child.type === "TemplateElement")
|
|
58
|
+
found.push(child.value.cooked ?? "");
|
|
59
|
+
});
|
|
60
|
+
return found;
|
|
61
|
+
};
|
|
72
62
|
/** The non-union, non-intersection constituents of a TypeScript type. */
|
|
73
|
-
const leavesOf = (type) => (type.isUnionOrIntersection() ? type.types.flatMap(leavesOf) : [type])
|
|
74
|
-
|
|
63
|
+
const leavesOf = (type) => (type.isUnionOrIntersection() ? type.types.flatMap(leavesOf) : [type]);
|
|
75
64
|
/** The `synchronize` members that typeorm declares on the contextual type of an object literal, as TypeScript declarations. */
|
|
76
65
|
const synchronizeMembers = (context, node) => {
|
|
77
|
-
const { checker, toTs } = typed(context)
|
|
78
|
-
const tsNode = toTs(node)
|
|
79
|
-
const expected = tsNode ? checker.getContextualType(tsNode) : undefined
|
|
80
|
-
if (!expected)
|
|
66
|
+
const { checker, toTs } = typed(context);
|
|
67
|
+
const tsNode = toTs(node);
|
|
68
|
+
const expected = tsNode ? checker.getContextualType(tsNode) : undefined;
|
|
69
|
+
if (!expected)
|
|
70
|
+
return [];
|
|
81
71
|
return leavesOf(expected)
|
|
82
72
|
.flatMap((part) => checker.getPropertyOfType(part, "synchronize")?.declarations ?? [])
|
|
83
|
-
.filter((declaration) => OPTION_PACKAGES.has(packageOfFile(declaration.getSourceFile().fileName)))
|
|
84
|
-
}
|
|
85
|
-
|
|
73
|
+
.filter((declaration) => OPTION_PACKAGES.has(packageOfFile(declaration.getSourceFile().fileName)));
|
|
74
|
+
};
|
|
86
75
|
/** A `synchronize` declared as a method is the DataSource operation, not the options flag. */
|
|
87
|
-
const isMethod = (declaration) => ts.isMethodSignature(declaration) || ts.isMethodDeclaration(declaration)
|
|
88
|
-
|
|
76
|
+
const isMethod = (declaration) => ts.isMethodSignature(declaration) || ts.isMethodDeclaration(declaration);
|
|
89
77
|
/** A `synchronize` declared on typeorm's `EntityOptions` is the per-entity switch, not the connection's. */
|
|
90
|
-
const isEntityOption = (declaration) => ts.isInterfaceDeclaration(declaration.parent) && declaration.parent.name.text === "EntityOptions"
|
|
91
|
-
|
|
78
|
+
const isEntityOption = (declaration) => ts.isInterfaceDeclaration(declaration.parent) && declaration.parent.name.text === "EntityOptions";
|
|
92
79
|
/** Whether an object literal is contextually a DataSource options object: its expected type has a `synchronize` option (a property, not the `synchronize()` method, not an entity's) declared by `typeorm`. */
|
|
93
|
-
const isOptionsObject = (context, node) => synchronizeMembers(context, node).some((declaration) => !isMethod(declaration) && !isEntityOption(declaration))
|
|
94
|
-
|
|
80
|
+
const isOptionsObject = (context, node) => synchronizeMembers(context, node).some((declaration) => !isMethod(declaration) && !isEntityOption(declaration));
|
|
95
81
|
/** Whether an object literal is the options of typeorm's `@Entity(...)`. */
|
|
96
|
-
const isEntityOptions = (context, node) => synchronizeMembers(context, node).some(isEntityOption)
|
|
97
|
-
|
|
82
|
+
const isEntityOptions = (context, node) => synchronizeMembers(context, node).some(isEntityOption);
|
|
98
83
|
/** Whether an object literal is contextually a DataSource (or a partial of one) whose `synchronize` is the method: its keys are overrides of operations, not configuration. */
|
|
99
84
|
const isOperationsObject = (context, node) => {
|
|
100
|
-
const members = synchronizeMembers(context, node)
|
|
101
|
-
return members.length > 0 && members.every(isMethod)
|
|
102
|
-
}
|
|
103
|
-
|
|
85
|
+
const members = synchronizeMembers(context, node);
|
|
86
|
+
return members.length > 0 && members.every(isMethod);
|
|
87
|
+
};
|
|
104
88
|
/** Whether a file is the cli (the cli app or the cli feature root, whose migrate and seed commands run them) or the test world: the only places that run migrations and seed. */
|
|
105
|
-
const isMigrationHost = (hfs, filename) => inCli(hfs, filename) || inTestWorld(hfs, filename)
|
|
106
|
-
|
|
89
|
+
const isMigrationHost = (hfs, filename) => inCli(hfs, filename) || inTestWorld(hfs, filename);
|
|
107
90
|
/** The SQL text of a call argument: a literal, a template, or the quasis of a tagged template. */
|
|
108
|
-
const sqlTextOf = (argument) => (argument ? stringsUnder(argument).join(" ") : "")
|
|
109
|
-
|
|
91
|
+
const sqlTextOf = (argument) => (argument ? stringsUnder(argument).join(" ") : "");
|
|
110
92
|
/**
|
|
111
93
|
* The first call under a lifecycle hook that writes rows: an `EntityManager`/`DataSource`/`QueryRunner` write method, a `.query(...)` whose
|
|
112
94
|
* text writes, or a call of another method of the same class (`this.seed()`) that does.
|
|
113
95
|
*/
|
|
114
96
|
const bootWriteOf = (context, method, klass, visited) => {
|
|
115
|
-
let found = null
|
|
97
|
+
let found = null;
|
|
116
98
|
walk(method.value.body, (node) => {
|
|
117
|
-
if (found || node.type !== "CallExpression")
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
99
|
+
if (found || node.type !== "CallExpression")
|
|
100
|
+
return;
|
|
101
|
+
const callee = node.callee;
|
|
102
|
+
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
|
|
103
|
+
return;
|
|
104
|
+
const name = callee.property.name;
|
|
121
105
|
if (callee.object.type === "ThisExpression") {
|
|
122
|
-
const target = klass.body.body.find((member) => member.type === "MethodDefinition" && member.kind === "method" && !member.computed && keyName(member.key) === name)
|
|
106
|
+
const target = klass.body.body.find((member) => member.type === "MethodDefinition" && member.kind === "method" && !member.computed && keyName(member.key) === name);
|
|
123
107
|
if (target && !visited.has(target)) {
|
|
124
|
-
visited.add(target)
|
|
125
|
-
found = bootWriteOf(context, target, klass, visited)
|
|
108
|
+
visited.add(target);
|
|
109
|
+
found = bootWriteOf(context, target, klass, visited);
|
|
126
110
|
}
|
|
127
|
-
return
|
|
111
|
+
return;
|
|
128
112
|
}
|
|
129
|
-
if (!WRITER_TYPES.some((type) => isPackageType(context, callee.object, type, "typeorm")))
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
|
|
113
|
+
if (!WRITER_TYPES.some((type) => isPackageType(context, callee.object, type, "typeorm")))
|
|
114
|
+
return;
|
|
115
|
+
if (WRITE_METHODS.has(name) || (name === "query" && WRITE_SQL.test(sqlTextOf(node.arguments[0]))))
|
|
116
|
+
found = node;
|
|
117
|
+
});
|
|
118
|
+
return found;
|
|
119
|
+
};
|
|
135
120
|
/** Whether an object literal has a property called `name`. */
|
|
136
|
-
const hasKey = (objectNode, name) => objectNode.properties.some((property) => property.type === "Property" && !property.computed && keyName(property.key) === name)
|
|
137
|
-
|
|
121
|
+
const hasKey = (objectNode, name) => objectNode.properties.some((property) => property.type === "Property" && !property.computed && keyName(property.key) === name);
|
|
138
122
|
/** The schema is decided by migrations run by the cli migrate command, never by the running process. */
|
|
139
123
|
export const noRuntimeSchema = {
|
|
140
124
|
meta: {
|
|
@@ -157,133 +141,171 @@ export const noRuntimeSchema = {
|
|
|
157
141
|
},
|
|
158
142
|
},
|
|
159
143
|
create(context) {
|
|
160
|
-
const filename = context.filename || context.getFilename()
|
|
161
|
-
if (isDeclarationFile(filename))
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
const
|
|
144
|
+
const filename = context.filename || context.getFilename();
|
|
145
|
+
if (isDeclarationFile(filename))
|
|
146
|
+
return {};
|
|
147
|
+
const hfs = hfsOf(context);
|
|
148
|
+
const migration = isMigrationFile(hfs, filename);
|
|
149
|
+
const migrationHost = isMigrationHost(hfs, filename);
|
|
165
150
|
return {
|
|
166
151
|
ObjectExpression(node) {
|
|
167
|
-
if (isOptionsObject(context, node) && !hasKey(node, "synchronize"))
|
|
152
|
+
if (isOptionsObject(context, node) && !hasKey(node, "synchronize"))
|
|
153
|
+
context.report({ node, messageId: "synchronizeMissing" });
|
|
168
154
|
},
|
|
169
155
|
MethodDefinition(node) {
|
|
170
|
-
if (node.kind !== "method" || node.computed || !BOOT_HOOKS.has(keyName(node.key) ?? "") || migrationHost)
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
156
|
+
if (node.kind !== "method" || node.computed || !BOOT_HOOKS.has(keyName(node.key) ?? "") || migrationHost)
|
|
157
|
+
return;
|
|
158
|
+
const klass = node.parent?.parent;
|
|
159
|
+
if (klass?.type !== "ClassDeclaration" && klass?.type !== "ClassExpression")
|
|
160
|
+
return;
|
|
161
|
+
const write = bootWriteOf(context, node, klass, new Set([node]));
|
|
162
|
+
if (write)
|
|
163
|
+
context.report({ node: write, messageId: "bootSeed", data: { hook: keyName(node.key), call: context.sourceCode.getText(write.callee) } });
|
|
175
164
|
},
|
|
176
165
|
Property(node) {
|
|
177
|
-
if (node.computed)
|
|
178
|
-
|
|
166
|
+
if (node.computed)
|
|
167
|
+
return;
|
|
168
|
+
const key = keyName(node.key);
|
|
179
169
|
if (key === "synchronize" && node.parent?.type === "ObjectExpression" && isEntityOptions(context, node.parent)) {
|
|
180
|
-
context.report({ node, messageId: "entitySynchronize" })
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
170
|
+
context.report({ node, messageId: "entitySynchronize" });
|
|
171
|
+
}
|
|
172
|
+
else if (key === "dropSchema" && !isFalse(node.value)) {
|
|
173
|
+
context.report({ node, messageId: "dropSchema" });
|
|
174
|
+
}
|
|
175
|
+
else if (key === "synchronize" && !isFalse(node.value)) {
|
|
176
|
+
if (node.parent?.type === "ObjectExpression" && isOperationsObject(context, node.parent))
|
|
177
|
+
return;
|
|
178
|
+
context.report({ node, messageId: "synchronize" });
|
|
179
|
+
}
|
|
180
|
+
else if (key === "migrationsRun") {
|
|
181
|
+
context.report({ node, messageId: "migrationsRun" });
|
|
182
|
+
}
|
|
183
|
+
else if ((key === "entities" || key === "migrations") && stringsUnder(node.value).some((text) => text.includes("*"))) {
|
|
184
|
+
context.report({ node, messageId: "glob", data: { key } });
|
|
190
185
|
}
|
|
191
186
|
},
|
|
192
187
|
NewExpression(node) {
|
|
193
|
-
if (!isPackageType(context, node, "DataSource", "typeorm"))
|
|
194
|
-
|
|
195
|
-
|
|
188
|
+
if (!isPackageType(context, node, "DataSource", "typeorm"))
|
|
189
|
+
return;
|
|
190
|
+
const options = node.arguments[0];
|
|
191
|
+
if (options && options.type !== "ObjectExpression")
|
|
192
|
+
context.report({ node: options, messageId: "optionsNotLiteral" });
|
|
196
193
|
},
|
|
197
194
|
CallExpression(node) {
|
|
198
|
-
const callee = node.callee
|
|
199
|
-
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
|
|
200
|
-
|
|
195
|
+
const callee = node.callee;
|
|
196
|
+
if (callee.type !== "MemberExpression" || callee.computed || callee.property.type !== "Identifier")
|
|
197
|
+
return;
|
|
198
|
+
const name = callee.property.name;
|
|
201
199
|
if (SCHEMA_OPERATIONS.has(name)) {
|
|
202
|
-
if (isPackageType(context, callee.object, "DataSource", "typeorm"))
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
if (isPackageType(context, callee.object, "DataSource", "typeorm"))
|
|
207
|
-
|
|
208
|
-
|
|
200
|
+
if (isPackageType(context, callee.object, "DataSource", "typeorm"))
|
|
201
|
+
context.report({ node, messageId: "synchronizeCall", data: { name } });
|
|
202
|
+
}
|
|
203
|
+
else if (MIGRATION_RUNNERS.has(name)) {
|
|
204
|
+
if (!migrationHost && isPackageType(context, callee.object, "DataSource", "typeorm"))
|
|
205
|
+
context.report({ node, messageId: "runMigrations", data: { name } });
|
|
206
|
+
}
|
|
207
|
+
else if (name === "createSchemaBuilder") {
|
|
208
|
+
if (isPackageType(context, callee.object, "DataSource", "typeorm"))
|
|
209
|
+
context.report({ node, messageId: "schemaBuilder", data: { name: "createSchemaBuilder()" } });
|
|
210
|
+
}
|
|
211
|
+
else if (name === "build" || name === "log") {
|
|
212
|
+
if (SCHEMA_BUILDER_TYPES.some((type) => isPackageType(context, callee.object, type, "typeorm")))
|
|
213
|
+
context.report({ node, messageId: "schemaBuilder", data: { name: `${name}()` } });
|
|
209
214
|
}
|
|
210
215
|
},
|
|
211
216
|
Literal(node) {
|
|
212
|
-
if (!migration && typeof node.value === "string" && DDL.test(node.value))
|
|
217
|
+
if (!migration && typeof node.value === "string" && DDL.test(node.value))
|
|
218
|
+
context.report({ node, messageId: "ddl" });
|
|
213
219
|
},
|
|
214
220
|
TemplateElement(node) {
|
|
215
|
-
if (!migration && DDL.test(node.value.cooked ?? ""))
|
|
221
|
+
if (!migration && DDL.test(node.value.cooked ?? ""))
|
|
222
|
+
context.report({ node, messageId: "ddl" });
|
|
216
223
|
},
|
|
217
|
-
}
|
|
224
|
+
};
|
|
218
225
|
},
|
|
219
|
-
}
|
|
220
|
-
|
|
226
|
+
};
|
|
221
227
|
// -- R37 -------------------------------------------------------------------------------------------
|
|
222
|
-
|
|
223
228
|
/** Whether a decorator is `typeorm`'s `Entity`, read through the checker so an aliased import counts. */
|
|
224
229
|
const isEntityDecorator = (checker, decorator) => {
|
|
225
|
-
const callee = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression
|
|
226
|
-
let symbol = checker.getSymbolAtLocation(callee)
|
|
227
|
-
if (symbol && (symbol.flags & ts.SymbolFlags.Alias) !== 0)
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
230
|
+
const callee = ts.isCallExpression(decorator.expression) ? decorator.expression.expression : decorator.expression;
|
|
231
|
+
let symbol = checker.getSymbolAtLocation(callee);
|
|
232
|
+
if (symbol && (symbol.flags & ts.SymbolFlags.Alias) !== 0)
|
|
233
|
+
symbol = checker.getAliasedSymbol(symbol);
|
|
234
|
+
return symbol?.name === "Entity" && (symbol.declarations ?? []).some((declaration) => packageOfFile(declaration.getSourceFile().fileName) === "typeorm");
|
|
235
|
+
};
|
|
231
236
|
/** Whether a TypeScript declaration is a class carrying `@Entity`. */
|
|
232
|
-
const carriesEntity = (checker, declaration) => ts.canHaveDecorators(declaration) && (ts.getDecorators(declaration) ?? []).some((decorator) => isEntityDecorator(checker, decorator))
|
|
233
|
-
|
|
237
|
+
const carriesEntity = (checker, declaration) => ts.canHaveDecorators(declaration) && (ts.getDecorators(declaration) ?? []).some((decorator) => isEntityDecorator(checker, decorator));
|
|
238
|
+
/** `declaration.name?.text` of a declaration whose kind is not known (undefined when it has no named `name`). */
|
|
239
|
+
const entityNameOf = (declaration) => {
|
|
240
|
+
const name = "name" in declaration ? declaration.name : undefined;
|
|
241
|
+
if (!isTsNode(name) || !("text" in name))
|
|
242
|
+
return undefined;
|
|
243
|
+
return typeof name.text === "string" ? name.text : undefined;
|
|
244
|
+
};
|
|
245
|
+
/** Whether a type is a type reference (`Array<T>`, `Promise<T>`, a generic class or interface instance). */
|
|
246
|
+
const isTypeReference = (type) => (type.flags & ts.TypeFlags.Object) !== 0 && "objectFlags" in type && typeof type.objectFlags === "number" && (type.objectFlags & ts.ObjectFlags.Reference) !== 0;
|
|
247
|
+
/** The type arguments of a type reference; any other type has none. */
|
|
248
|
+
const typeArgumentsOf = (checker, type) => (isTypeReference(type) ? checker.getTypeArguments(type) : []);
|
|
234
249
|
/**
|
|
235
250
|
* The name of an ORM entity a type reaches, or null: the type itself, a union or intersection member, a type argument
|
|
236
251
|
* (`Array<OrderEntity>`, `Promise<...>`), or a property of a type the repository declares. Types declared by a package
|
|
237
252
|
* or the language are not walked into, only through their type arguments.
|
|
238
253
|
*/
|
|
239
254
|
const entityReached = (checker, type, seen, depth) => {
|
|
240
|
-
if (!type || depth > 6 || seen.has(type))
|
|
241
|
-
|
|
255
|
+
if (!type || depth > 6 || seen.has(type))
|
|
256
|
+
return null;
|
|
257
|
+
seen.add(type);
|
|
242
258
|
if (type.isUnionOrIntersection()) {
|
|
243
259
|
for (const part of type.types) {
|
|
244
|
-
const found = entityReached(checker, part, seen, depth + 1)
|
|
245
|
-
if (found)
|
|
260
|
+
const found = entityReached(checker, part, seen, depth + 1);
|
|
261
|
+
if (found)
|
|
262
|
+
return found;
|
|
246
263
|
}
|
|
247
|
-
return null
|
|
264
|
+
return null;
|
|
248
265
|
}
|
|
249
|
-
const declarations = type.getSymbol()?.getDeclarations() ?? []
|
|
250
|
-
const entity = declarations.find((declaration) => carriesEntity(checker, declaration))
|
|
251
|
-
if (entity)
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
266
|
+
const declarations = type.getSymbol()?.getDeclarations() ?? [];
|
|
267
|
+
const entity = declarations.find((declaration) => carriesEntity(checker, declaration));
|
|
268
|
+
if (entity)
|
|
269
|
+
return entityNameOf(entity) ?? "an entity";
|
|
270
|
+
for (const argument of typeArgumentsOf(checker, type)) {
|
|
271
|
+
const found = entityReached(checker, argument, seen, depth + 1);
|
|
272
|
+
if (found)
|
|
273
|
+
return found;
|
|
255
274
|
}
|
|
256
|
-
const own = declarations.length > 0 && declarations.every((declaration) => !declaration.getSourceFile().isDeclarationFile)
|
|
257
|
-
if (!own)
|
|
275
|
+
const own = declarations.length > 0 && declarations.every((declaration) => !declaration.getSourceFile().isDeclarationFile);
|
|
276
|
+
if (!own)
|
|
277
|
+
return null;
|
|
258
278
|
for (const property of checker.getPropertiesOfType(type)) {
|
|
259
|
-
const declaration = property.valueDeclaration ?? property.declarations?.[0]
|
|
260
|
-
if (!declaration)
|
|
261
|
-
|
|
262
|
-
|
|
279
|
+
const declaration = property.valueDeclaration ?? property.declarations?.[0];
|
|
280
|
+
if (!declaration)
|
|
281
|
+
continue;
|
|
282
|
+
const found = entityReached(checker, checker.getTypeOfSymbolAtLocation(property, declaration), seen, depth + 1);
|
|
283
|
+
if (found)
|
|
284
|
+
return found;
|
|
263
285
|
}
|
|
264
|
-
return null
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
const
|
|
268
|
-
const PARAMETER_HOLDERS = new Set(["Identifier", "ObjectPattern", "ArrayPattern", "AssignmentPattern", "RestElement"])
|
|
269
|
-
|
|
286
|
+
return null;
|
|
287
|
+
};
|
|
288
|
+
const FUNCTION_TYPES = new Set(["FunctionDeclaration", "FunctionExpression", "ArrowFunctionExpression", "TSDeclareFunction", "TSEmptyBodyFunctionExpression", "TSMethodSignature"]);
|
|
289
|
+
const PARAMETER_HOLDERS = new Set(["Identifier", "ObjectPattern", "ArrayPattern", "AssignmentPattern", "RestElement"]);
|
|
270
290
|
/** Which files carry boundary types, and how much of each: the whole file, or only the `execute` of a handler. */
|
|
271
291
|
const boundaryOf = (hfs, filename) => {
|
|
272
|
-
const slot = hfs.slotOf(filename) ?? ""
|
|
273
|
-
const name = baseName(filename)
|
|
274
|
-
if (isTransportSlot(slot))
|
|
275
|
-
|
|
276
|
-
if (
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
292
|
+
const slot = hfs.slotOf(filename) ?? "";
|
|
293
|
+
const name = baseName(filename);
|
|
294
|
+
if (isTransportSlot(slot))
|
|
295
|
+
return "file";
|
|
296
|
+
if (/\.(?:contracts|command|query)\.ts$/.test(name))
|
|
297
|
+
return "file";
|
|
298
|
+
if (name.endsWith(".handler.ts"))
|
|
299
|
+
return "execute";
|
|
300
|
+
return null;
|
|
301
|
+
};
|
|
280
302
|
/** The MethodDefinition a node sits in the signature of, or null. */
|
|
281
303
|
const methodOf = (node) => {
|
|
282
|
-
let current = node
|
|
283
|
-
while (current && !FUNCTION_TYPES.has(current.type))
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
304
|
+
let current = node;
|
|
305
|
+
while (current && !FUNCTION_TYPES.has(current.type))
|
|
306
|
+
current = current.parent;
|
|
307
|
+
return current?.parent?.type === "MethodDefinition" ? current.parent : null;
|
|
308
|
+
};
|
|
287
309
|
/** An ORM entity type never appears in a contract, DTO, command or query, transport signature or handler `execute`. */
|
|
288
310
|
export const noEntityInContract = {
|
|
289
311
|
meta: {
|
|
@@ -296,62 +318,71 @@ export const noEntityInContract = {
|
|
|
296
318
|
},
|
|
297
319
|
},
|
|
298
320
|
create(context) {
|
|
299
|
-
const filename = context.filename || context.getFilename()
|
|
300
|
-
if (isDeclarationFile(filename))
|
|
301
|
-
|
|
302
|
-
const
|
|
321
|
+
const filename = context.filename || context.getFilename();
|
|
322
|
+
if (isDeclarationFile(filename))
|
|
323
|
+
return {};
|
|
324
|
+
const hfs = hfsOf(context);
|
|
325
|
+
const listeners = {};
|
|
303
326
|
if (baseName(filename).endsWith(".entity.ts")) {
|
|
304
327
|
listeners.ImportDeclaration = (node) => {
|
|
305
|
-
const source = String(node.source.value)
|
|
328
|
+
const source = String(node.source.value);
|
|
306
329
|
if (["@nestjs/graphql", "class-validator"].some((banned) => source === banned || source.startsWith(`${banned}/`))) {
|
|
307
|
-
context.report({ node, messageId: "entityImport", data: { source } })
|
|
330
|
+
context.report({ node, messageId: "entityImport", data: { source } });
|
|
308
331
|
}
|
|
309
|
-
}
|
|
332
|
+
};
|
|
310
333
|
}
|
|
311
|
-
const boundary = boundaryOf(hfs, filename)
|
|
312
|
-
if (!boundary)
|
|
313
|
-
|
|
314
|
-
const
|
|
334
|
+
const boundary = boundaryOf(hfs, filename);
|
|
335
|
+
if (!boundary)
|
|
336
|
+
return listeners;
|
|
337
|
+
const { checker, toTs } = typed(context);
|
|
338
|
+
const reported = new Set();
|
|
315
339
|
const judge = (typeNode) => {
|
|
316
|
-
if (reported.has(typeNode))
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
340
|
+
if (reported.has(typeNode))
|
|
341
|
+
return;
|
|
342
|
+
const tsNode = toTs(typeNode);
|
|
343
|
+
// every type annotation maps to a TypeScript type node; the kind check only tells the compiler so
|
|
344
|
+
if (!tsNode || !ts.isTypeNode(tsNode))
|
|
345
|
+
return;
|
|
346
|
+
const name = entityReached(checker, checker.getTypeFromTypeNode(tsNode), new Set(), 0);
|
|
320
347
|
if (name) {
|
|
321
|
-
reported.add(typeNode)
|
|
322
|
-
context.report({ node: typeNode, messageId: "entity", data: { name } })
|
|
348
|
+
reported.add(typeNode);
|
|
349
|
+
context.report({ node: typeNode, messageId: "entity", data: { name } });
|
|
323
350
|
}
|
|
324
|
-
}
|
|
351
|
+
};
|
|
325
352
|
/** Whether a signature is one this file is judged on. */
|
|
326
|
-
const inScope = (node) =>
|
|
353
|
+
const inScope = (node) => {
|
|
354
|
+
if (boundary === "file")
|
|
355
|
+
return true;
|
|
356
|
+
const key = methodOf(node)?.key;
|
|
357
|
+
return key !== undefined && "name" in key && key.name === "execute";
|
|
358
|
+
};
|
|
327
359
|
listeners.TSTypeAnnotation = (node) => {
|
|
328
|
-
const holder = node.parent
|
|
329
|
-
const isParameter = PARAMETER_HOLDERS.has(holder.type) && (FUNCTION_TYPES.has(holder.parent?.type) || holder.parent?.type === "TSParameterProperty")
|
|
330
|
-
const isReturn = FUNCTION_TYPES.has(holder.type) && holder.returnType === node
|
|
331
|
-
const isMember = holder.type === "PropertyDefinition" || holder.type === "TSPropertySignature"
|
|
332
|
-
if ((isParameter || isReturn || (isMember && boundary === "file")) && inScope(holder))
|
|
333
|
-
|
|
360
|
+
const holder = node.parent;
|
|
361
|
+
const isParameter = PARAMETER_HOLDERS.has(holder.type) && (FUNCTION_TYPES.has(holder.parent?.type) || holder.parent?.type === "TSParameterProperty");
|
|
362
|
+
const isReturn = FUNCTION_TYPES.has(holder.type) && "returnType" in holder && holder.returnType === node;
|
|
363
|
+
const isMember = holder.type === "PropertyDefinition" || holder.type === "TSPropertySignature";
|
|
364
|
+
if ((isParameter || isReturn || (isMember && boundary === "file")) && inScope(holder))
|
|
365
|
+
judge(node.typeAnnotation);
|
|
366
|
+
};
|
|
334
367
|
listeners.TSTypeAliasDeclaration = (node) => {
|
|
335
|
-
if (boundary === "file")
|
|
336
|
-
|
|
368
|
+
if (boundary === "file")
|
|
369
|
+
judge(node.typeAnnotation);
|
|
370
|
+
};
|
|
337
371
|
// `extends Command<OrderEntity>` and `implements ICQRSHandler<...>`: the heritage names what the class carries across
|
|
338
372
|
listeners.TSTypeParameterInstantiation = (node) => {
|
|
339
|
-
const parent = node.parent
|
|
340
|
-
const heritage = parent.type === "TSClassImplements" || parent.type === "TSInterfaceHeritage" || parent.type === "ClassDeclaration" || parent.type === "ClassExpression"
|
|
341
|
-
if (heritage)
|
|
342
|
-
|
|
343
|
-
|
|
373
|
+
const parent = node.parent;
|
|
374
|
+
const heritage = parent.type === "TSClassImplements" || parent.type === "TSInterfaceHeritage" || parent.type === "ClassDeclaration" || parent.type === "ClassExpression";
|
|
375
|
+
if (heritage)
|
|
376
|
+
for (const param of node.params)
|
|
377
|
+
judge(param);
|
|
378
|
+
};
|
|
379
|
+
return listeners;
|
|
344
380
|
},
|
|
345
|
-
}
|
|
346
|
-
|
|
381
|
+
};
|
|
347
382
|
// -- R74 -------------------------------------------------------------------------------------------
|
|
348
|
-
|
|
349
|
-
const methodNamed = (klass, name) =>
|
|
350
|
-
klass.body.body.find((member) => member.type === "MethodDefinition" && !member.computed && keyName(member.key) === name)
|
|
351
|
-
|
|
383
|
+
const methodNamed = (klass, name) => klass.body.body.find((member) => member.type === "MethodDefinition" && !member.computed && keyName(member.key) === name);
|
|
352
384
|
/** Whether a `down` body does nothing but refuse. */
|
|
353
|
-
const onlyThrows = (body) => body.body.length > 0 && body.body.every((statement) => statement.type === "ThrowStatement")
|
|
354
|
-
|
|
385
|
+
const onlyThrows = (body) => body.body.length > 0 && body.body.every((statement) => statement.type === "ThrowStatement");
|
|
355
386
|
/** A migration can be undone. */
|
|
356
387
|
export const migrationDownReversible = {
|
|
357
388
|
meta: {
|
|
@@ -365,31 +396,36 @@ export const migrationDownReversible = {
|
|
|
365
396
|
},
|
|
366
397
|
},
|
|
367
398
|
create(context) {
|
|
368
|
-
const filename = context.filename || context.getFilename()
|
|
369
|
-
if (isDeclarationFile(filename) || !isMigrationFile(hfsOf(context), filename))
|
|
399
|
+
const filename = context.filename || context.getFilename();
|
|
400
|
+
if (isDeclarationFile(filename) || !isMigrationFile(hfsOf(context), filename))
|
|
401
|
+
return {};
|
|
370
402
|
const check = (node) => {
|
|
371
|
-
if (!node.body)
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
403
|
+
if (!node.body)
|
|
404
|
+
return;
|
|
405
|
+
const up = methodNamed(node, "up");
|
|
406
|
+
if (!up)
|
|
407
|
+
return;
|
|
408
|
+
const down = methodNamed(node, "down");
|
|
409
|
+
const downBody = down?.value.body;
|
|
410
|
+
if (!down)
|
|
411
|
+
context.report({ node: node.id ?? node, messageId: "missing" });
|
|
412
|
+
else if (downBody?.body.length === 0)
|
|
413
|
+
context.report({ node: down.key, messageId: "empty" });
|
|
414
|
+
else if (downBody && onlyThrows(downBody))
|
|
415
|
+
context.report({ node: down.key, messageId: "throws" });
|
|
416
|
+
};
|
|
417
|
+
return { ClassDeclaration: check };
|
|
380
418
|
},
|
|
381
|
-
}
|
|
382
|
-
|
|
419
|
+
};
|
|
383
420
|
/** The rules this law contributes to the plugin. */
|
|
384
421
|
export const rules = {
|
|
385
422
|
"no-runtime-schema": noRuntimeSchema,
|
|
386
423
|
"no-entity-in-contract": noEntityInContract,
|
|
387
424
|
"migration-down-reversible": migrationDownReversible,
|
|
388
|
-
}
|
|
389
|
-
|
|
425
|
+
};
|
|
390
426
|
/** All three start at error: HFS keeps no baseline and the schema migration lanes clear the debt first. */
|
|
391
427
|
export const recommended = {
|
|
392
428
|
"starci-be/no-runtime-schema": "error",
|
|
393
429
|
"starci-be/no-entity-in-contract": "error",
|
|
394
430
|
"starci-be/migration-down-reversible": "error",
|
|
395
|
-
}
|
|
431
|
+
};
|