@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,36 @@
|
|
|
1
|
+
import type { TSESLint } from "@typescript-eslint/utils";
|
|
2
|
+
import type { HfsView } from "./hfs.js";
|
|
3
|
+
import type { Recommended, Rules } from "./rule.js";
|
|
4
|
+
/** The plugin object the factory registers as `starci-be`. */
|
|
5
|
+
export interface CanonPlugin {
|
|
6
|
+
readonly meta?: {
|
|
7
|
+
readonly name?: string;
|
|
8
|
+
readonly version?: string;
|
|
9
|
+
};
|
|
10
|
+
readonly rules: Rules;
|
|
11
|
+
}
|
|
12
|
+
/** A disable directive is a weakening of lint, and one that suppresses nothing is dead weight. */
|
|
13
|
+
export declare const linterOptions: Readonly<{
|
|
14
|
+
noInlineConfig: true;
|
|
15
|
+
reportUnusedDisableDirectives: "error";
|
|
16
|
+
}>;
|
|
17
|
+
/** Every tracked source a back end holds; the factory lints them all. */
|
|
18
|
+
export declare const SOURCE_FILES: readonly string[];
|
|
19
|
+
/** The only paths a back end never lints: build output, coverage output and installed packages. */
|
|
20
|
+
export declare const IGNORED: readonly string[];
|
|
21
|
+
/** The typescript-eslint rules the canon borrows (BE-CONVENTION 1.17, R72/R73; Sonar S1874, S6551 and S7503 through R235), all `error`. */
|
|
22
|
+
export declare const BORROWED: Recommended;
|
|
23
|
+
/**
|
|
24
|
+
* The flat config of one back-end repository.
|
|
25
|
+
*
|
|
26
|
+
* @param {object} input - Attachment options.
|
|
27
|
+
* @param {object} input.hfs - The HFS view of the repository (`loadHfs(import.meta.url)`).
|
|
28
|
+
* @param {object} input.plugin - The canon plugin.
|
|
29
|
+
* @param {Record<string, unknown>} input.recommended - The canon levels.
|
|
30
|
+
* @returns {Promise<Array<object>>} The flat config (ESLint awaits an exported promise): one ignore block, one rule block and the Sonar way block.
|
|
31
|
+
*/
|
|
32
|
+
export declare const buildBeConfig: ({ hfs, plugin, recommended }: {
|
|
33
|
+
hfs: HfsView | null | undefined;
|
|
34
|
+
plugin: CanonPlugin | null | undefined;
|
|
35
|
+
recommended?: Recommended | undefined;
|
|
36
|
+
}) => Promise<TSESLint.FlatConfig.ConfigArray>;
|
|
@@ -16,25 +16,20 @@
|
|
|
16
16
|
* else, so a rule cannot be published weakened and still look adopted. The factory takes no rule overrides, globs
|
|
17
17
|
* or ignores: there is no parameter through which a repository could weaken the canon.
|
|
18
18
|
*/
|
|
19
|
-
import tsParser from "@typescript-eslint/parser"
|
|
20
|
-
import { OUTSIDE_THE_SCAN_FILES } from "
|
|
21
|
-
import { sonarWayRules } from "
|
|
22
|
-
|
|
19
|
+
import tsParser from "@typescript-eslint/parser";
|
|
20
|
+
import { OUTSIDE_THE_SCAN_FILES } from "../../runtime/scripts/lib/sonar-syntax-rules.mjs";
|
|
21
|
+
import { sonarWayRules } from "../../runtime/scripts/lib/sonar-way.mjs";
|
|
23
22
|
/** A disable directive is a weakening of lint, and one that suppresses nothing is dead weight. */
|
|
24
|
-
export const linterOptions = Object.freeze({ noInlineConfig: true, reportUnusedDisableDirectives: "error" })
|
|
25
|
-
|
|
23
|
+
export const linterOptions = Object.freeze({ noInlineConfig: true, reportUnusedDisableDirectives: "error" });
|
|
26
24
|
/** Every tracked source a back end holds; the factory lints them all. */
|
|
27
|
-
export const SOURCE_FILES = Object.freeze(["**/*.ts", "**/*.mts", "**/*.cts", "**/*.js", "**/*.mjs", "**/*.cjs"])
|
|
28
|
-
|
|
25
|
+
export const SOURCE_FILES = Object.freeze(["**/*.ts", "**/*.mts", "**/*.cts", "**/*.js", "**/*.mjs", "**/*.cjs"]);
|
|
29
26
|
/** The only paths a back end never lints: build output, coverage output and installed packages. */
|
|
30
|
-
export const IGNORED = Object.freeze(["dist/**", "coverage/**", "**/node_modules/**"])
|
|
31
|
-
|
|
27
|
+
export const IGNORED = Object.freeze(["dist/**", "coverage/**", "**/node_modules/**"]);
|
|
32
28
|
/**
|
|
33
29
|
* Root-level JavaScript (the managed `eslint.config.mjs`, `jest.config.js`) is outside `tsconfig.json`
|
|
34
30
|
* (`allowJs: false`); the project service types it with a default project instead of skipping it.
|
|
35
31
|
*/
|
|
36
|
-
const ROOT_SCRIPTS = Object.freeze(["*.js", "*.mjs", "*.cjs"])
|
|
37
|
-
|
|
32
|
+
const ROOT_SCRIPTS = Object.freeze(["*.js", "*.mjs", "*.cjs"]);
|
|
38
33
|
/** The typescript-eslint rules the canon borrows (BE-CONVENTION 1.17, R72/R73; Sonar S1874, S6551 and S7503 through R235), all `error`. */
|
|
39
34
|
export const BORROWED = Object.freeze({
|
|
40
35
|
"@typescript-eslint/consistent-type-assertions": ["error", { assertionStyle: "never" }],
|
|
@@ -53,10 +48,8 @@ export const BORROWED = Object.freeze({
|
|
|
53
48
|
"@typescript-eslint/no-unsafe-return": "error",
|
|
54
49
|
"@typescript-eslint/no-unsafe-argument": "error",
|
|
55
50
|
"no-console": "error",
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
const levelOf = (setting) => (Array.isArray(setting) ? setting[0] : setting)
|
|
59
|
-
|
|
51
|
+
});
|
|
52
|
+
const levelOf = (setting) => (Array.isArray(setting) ? setting[0] : setting);
|
|
60
53
|
/**
|
|
61
54
|
* The flat config of one back-end repository.
|
|
62
55
|
*
|
|
@@ -68,17 +61,21 @@ const levelOf = (setting) => (Array.isArray(setting) ? setting[0] : setting)
|
|
|
68
61
|
*/
|
|
69
62
|
export const buildBeConfig = async ({ hfs, plugin, recommended }) => {
|
|
70
63
|
if (!hfs || typeof hfs.slotOf !== "function" || typeof hfs.repoRoot !== "string") {
|
|
71
|
-
throw new Error("starciBeConfig needs { hfs: loadHfs(import.meta.url) } - the rules read the repository's slots through it")
|
|
64
|
+
throw new Error("starciBeConfig needs { hfs: loadHfs(import.meta.url) } - the rules read the repository's slots through it");
|
|
72
65
|
}
|
|
73
|
-
if (hfs.profile !== "be")
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (
|
|
77
|
-
|
|
78
|
-
if (
|
|
66
|
+
if (hfs.profile !== "be")
|
|
67
|
+
throw new Error(`starciBeConfig lints the be side of an app (its eslint.config.mjs lives in be/); this view is ${hfs.side ? `the ${hfs.side} side` : "the app root"}`);
|
|
68
|
+
const rules = recommended ?? {};
|
|
69
|
+
if (!plugin?.rules)
|
|
70
|
+
throw new Error("starciBeConfig needs the canon plugin");
|
|
71
|
+
if (Object.keys(rules).length === 0)
|
|
72
|
+
throw new Error("starciBeConfig received an empty recommendation - a config with no rules is not adoption");
|
|
73
|
+
const weak = Object.entries(rules).filter(([, setting]) => levelOf(setting) !== "error").map(([name]) => name);
|
|
74
|
+
if (weak.length > 0)
|
|
75
|
+
throw new Error(`starciBeConfig refuses a recommendation with rules not at error: ${weak.join(", ")}`);
|
|
79
76
|
// Loaded here, not at import: the rule catalog check imports this package to list its rules and needs no linter plugin.
|
|
80
|
-
const { default: tsPlugin } = await import("@typescript-eslint/eslint-plugin")
|
|
81
|
-
const [{ default: sonarjs }, { default: unicorn }] = await Promise.all([import("eslint-plugin-sonarjs"), import("eslint-plugin-unicorn")])
|
|
77
|
+
const { default: tsPlugin } = await import("@typescript-eslint/eslint-plugin");
|
|
78
|
+
const [{ default: sonarjs }, { default: unicorn }] = await Promise.all([import("eslint-plugin-sonarjs"), import("eslint-plugin-unicorn")]);
|
|
82
79
|
return [
|
|
83
80
|
{ ignores: [...IGNORED] },
|
|
84
81
|
{
|
|
@@ -96,5 +93,5 @@ export const buildBeConfig = async ({ hfs, plugin, recommended }) => {
|
|
|
96
93
|
},
|
|
97
94
|
// Sonar way: what the scan raises is refused while the code is written; a spec is outside the scan, so outside this block.
|
|
98
95
|
{ files: [...SOURCE_FILES], ignores: [...OUTSIDE_THE_SCAN_FILES], plugins: { sonarjs, unicorn }, rules: sonarWayRules(sonarjs, "be").rules },
|
|
99
|
-
]
|
|
100
|
-
}
|
|
96
|
+
];
|
|
97
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { TSESLint, TSESTree } from "@typescript-eslint/utils";
|
|
2
|
+
import type { Context, Node } from "./rule.js";
|
|
3
|
+
/** Statement text that changes rows. */
|
|
4
|
+
export declare const WRITING_SQL: RegExp;
|
|
5
|
+
/** Statement text that creates rows. */
|
|
6
|
+
export declare const INSERTING_SQL: RegExp;
|
|
7
|
+
/**
|
|
8
|
+
* True when the node's type is a typeorm database receiver.
|
|
9
|
+
*
|
|
10
|
+
* @param {object} context - The ESLint rule context.
|
|
11
|
+
* @param {object} node - The receiver expression.
|
|
12
|
+
* @returns {boolean} Whether its type is `EntityManager`, `DataSource` or `QueryRunner` of `typeorm`.
|
|
13
|
+
*/
|
|
14
|
+
export declare const isDatabaseReceiver: (context: Context, node: Node) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The statement text of a `query` argument: a literal, a template (substitutions read as a space), a tagged template, or the `const` it names (one hop).
|
|
17
|
+
*
|
|
18
|
+
* @param {object | undefined} node - The argument.
|
|
19
|
+
* @param {object | null} scope - The scope the argument is read in (null after the one hop).
|
|
20
|
+
* @returns {string | null} The text, or null when it cannot be read statically.
|
|
21
|
+
*/
|
|
22
|
+
export declare const queryText: (node: Node | null | undefined, scope: TSESLint.Scope.Scope | null) => string | null;
|
|
23
|
+
/**
|
|
24
|
+
* The member name of a call `receiver.method(...)`, or null for any other callee.
|
|
25
|
+
*
|
|
26
|
+
* @param {object} node - A CallExpression.
|
|
27
|
+
* @returns {string | null} The method name.
|
|
28
|
+
*/
|
|
29
|
+
export declare const methodOf: (node: TSESTree.CallExpression) => string | null;
|
|
@@ -2,18 +2,14 @@
|
|
|
2
2
|
* What the test-data laws share: which value is a database receiver, what text a `query` argument carries, and which calls create rows.
|
|
3
3
|
* A receiver is recognised by its TYPE (`EntityManager`, `DataSource`, `QueryRunner` of `typeorm`), never by its name.
|
|
4
4
|
*/
|
|
5
|
-
import { staticText } from "./ast.
|
|
6
|
-
import { isPackageType } from "./types.
|
|
7
|
-
|
|
5
|
+
import { staticText } from "./ast.js";
|
|
6
|
+
import { isPackageType } from "./types.js";
|
|
8
7
|
/** The `typeorm` types a call can write through. */
|
|
9
|
-
const RECEIVER_TYPES = Object.freeze(["EntityManager", "DataSource", "QueryRunner"])
|
|
10
|
-
|
|
8
|
+
const RECEIVER_TYPES = Object.freeze(["EntityManager", "DataSource", "QueryRunner"]);
|
|
11
9
|
/** Statement text that changes rows. */
|
|
12
|
-
export const WRITING_SQL = /(?:^|[\s;(])(?:insert\s+into|update\s+["`\w.]+\s+set|delete\s+from|truncate\b)/i
|
|
13
|
-
|
|
10
|
+
export const WRITING_SQL = /(?:^|[\s;(])(?:insert\s+into|update\s+["`\w.]+\s+set|delete\s+from|truncate\b)/i;
|
|
14
11
|
/** Statement text that creates rows. */
|
|
15
|
-
export const INSERTING_SQL = /(?:^|[\s;(])insert\s+into\b/i
|
|
16
|
-
|
|
12
|
+
export const INSERTING_SQL = /(?:^|[\s;(])insert\s+into\b/i;
|
|
17
13
|
/**
|
|
18
14
|
* True when the node's type is a typeorm database receiver.
|
|
19
15
|
*
|
|
@@ -21,8 +17,7 @@ export const INSERTING_SQL = /(?:^|[\s;(])insert\s+into\b/i
|
|
|
21
17
|
* @param {object} node - The receiver expression.
|
|
22
18
|
* @returns {boolean} Whether its type is `EntityManager`, `DataSource` or `QueryRunner` of `typeorm`.
|
|
23
19
|
*/
|
|
24
|
-
export const isDatabaseReceiver = (context, node) => RECEIVER_TYPES.some((name) => isPackageType(context, node, name, "typeorm"))
|
|
25
|
-
|
|
20
|
+
export const isDatabaseReceiver = (context, node) => RECEIVER_TYPES.some((name) => isPackageType(context, node, name, "typeorm"));
|
|
26
21
|
/**
|
|
27
22
|
* The statement text of a `query` argument: a literal, a template (substitutions read as a space), a tagged template, or the `const` it names (one hop).
|
|
28
23
|
*
|
|
@@ -31,21 +26,26 @@ export const isDatabaseReceiver = (context, node) => RECEIVER_TYPES.some((name)
|
|
|
31
26
|
* @returns {string | null} The text, or null when it cannot be read statically.
|
|
32
27
|
*/
|
|
33
28
|
export const queryText = (node, scope) => {
|
|
34
|
-
if (!node)
|
|
35
|
-
|
|
36
|
-
if (node.type === "
|
|
37
|
-
|
|
38
|
-
if (
|
|
39
|
-
|
|
29
|
+
if (!node)
|
|
30
|
+
return null;
|
|
31
|
+
if (node.type === "TemplateLiteral")
|
|
32
|
+
return node.quasis.map((quasi) => quasi.value.cooked ?? "").join(" ");
|
|
33
|
+
if (node.type === "TaggedTemplateExpression")
|
|
34
|
+
return queryText(node.quasi, null);
|
|
35
|
+
const direct = staticText(node);
|
|
36
|
+
if (direct !== null)
|
|
37
|
+
return direct;
|
|
38
|
+
if (node.type !== "Identifier")
|
|
39
|
+
return null;
|
|
40
40
|
for (let reference = scope; reference; reference = reference.upper) {
|
|
41
|
-
const variable = reference.set.get(node.name)
|
|
42
|
-
if (!variable)
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
const variable = reference.set.get(node.name);
|
|
42
|
+
if (!variable)
|
|
43
|
+
continue;
|
|
44
|
+
const definition = variable.defs[0]?.node;
|
|
45
|
+
return definition?.type === "VariableDeclarator" && definition.init ? queryText(definition.init, null) : null;
|
|
45
46
|
}
|
|
46
|
-
return null
|
|
47
|
-
}
|
|
48
|
-
|
|
47
|
+
return null;
|
|
48
|
+
};
|
|
49
49
|
/**
|
|
50
50
|
* The member name of a call `receiver.method(...)`, or null for any other callee.
|
|
51
51
|
*
|
|
@@ -53,6 +53,6 @@ export const queryText = (node, scope) => {
|
|
|
53
53
|
* @returns {string | null} The method name.
|
|
54
54
|
*/
|
|
55
55
|
export const methodOf = (node) => {
|
|
56
|
-
const callee = node.callee
|
|
57
|
-
return callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" ? callee.property.name : null
|
|
58
|
-
}
|
|
56
|
+
const callee = node.callee;
|
|
57
|
+
return callee.type === "MemberExpression" && !callee.computed && callee.property.type === "Identifier" ? callee.property.name : null;
|
|
58
|
+
};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Declaration-site questions for the type-aware rules of R38-R45: WHERE a type or a class is declared (which owner,
|
|
3
|
+
* which tier) and what it derives from. A rule never asks what a receiver is called; it asks what its type is and which
|
|
4
|
+
* owner of the repository declares that type. The owner and the tier come from the HFS slot view, never from a path.
|
|
5
|
+
*/
|
|
6
|
+
import ts from "typescript";
|
|
7
|
+
import type { TSESTree } from "@typescript-eslint/utils";
|
|
8
|
+
import type { Context, Node } from "./rule.js";
|
|
9
|
+
import type { HfsView } from "./hfs.js";
|
|
10
|
+
import type { TypeOrigin } from "./types.js";
|
|
11
|
+
/** The last segment of an owner root (`src/modules/platform/errors` gives `errors`), or null when there is no owner. */
|
|
12
|
+
export declare const ownerName: (root: string | null | undefined) => string | null | undefined;
|
|
13
|
+
/** True when `file` belongs to the owner `<name>` of the given tier (`platform`, `errors`). */
|
|
14
|
+
export declare const isOwnedBy: (hfs: HfsView, file: string, tier: string, name: string | null | undefined) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* True when the node's type is `name`, declared by the owner `<tier>/<capability>` of this repository.
|
|
17
|
+
*
|
|
18
|
+
* @param {object} context - The ESLint rule context.
|
|
19
|
+
* @param {object} node - The node to type.
|
|
20
|
+
* @param {string} name - The declared symbol name (`Logger`).
|
|
21
|
+
* @param {string} tier - The tier of the declaring owner (`platform`, `domain`).
|
|
22
|
+
* @param {string} capability - The owner's directory name (`logging`).
|
|
23
|
+
* @returns {boolean} Whether one of the type's origins matches.
|
|
24
|
+
*/
|
|
25
|
+
export declare const isOwnedType: (context: Context, node: Node, name: string, tier: string, capability: string) => boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Where the type of a node is declared, keeping a union ALIAS whole (`ErrorKind` is a union of literals; its origin is the
|
|
28
|
+
* alias declaration, not the literals). Falls back to `typeOrigins` for every other type.
|
|
29
|
+
*
|
|
30
|
+
* @param {object} context - The ESLint rule context.
|
|
31
|
+
* @param {object} node - An expression or type node.
|
|
32
|
+
* @returns {Array<{ name: string, file: string, module: string | null }>} The declarations of the type.
|
|
33
|
+
*/
|
|
34
|
+
export declare const originsOf: (context: Context, node: Node) => TypeOrigin[];
|
|
35
|
+
/** The TypeScript type of an ESTree node. */
|
|
36
|
+
export declare const typeOf: (context: Context, node: Node) => ts.Type | null;
|
|
37
|
+
/**
|
|
38
|
+
* True when the node's type is a member of the enum `enumName` declared by the owner `<tier>/<capability>`.
|
|
39
|
+
*
|
|
40
|
+
* @param {object} context - The ESLint rule context.
|
|
41
|
+
* @param {object} node - The expression (`PublicReason.Health`).
|
|
42
|
+
* @param {string} enumName - The enum's declared name.
|
|
43
|
+
* @param {string} tier - The tier of the declaring owner.
|
|
44
|
+
* @param {string} capability - The declaring owner's directory name.
|
|
45
|
+
* @returns {boolean} Whether the value is a member of that enum.
|
|
46
|
+
*/
|
|
47
|
+
export declare const isOwnedEnumMember: (context: Context, node: Node, enumName: string, tier: string, capability: string) => boolean;
|
|
48
|
+
/** The members of a union type, or the type itself. */
|
|
49
|
+
export declare const partsOf: (type: ts.Type | null | undefined) => ts.Type[];
|
|
50
|
+
/** The members of a type with `undefined` and `null` removed (an optional property's real type). */
|
|
51
|
+
export declare const presentParts: (type: ts.Type | null | undefined) => ts.Type[];
|
|
52
|
+
/**
|
|
53
|
+
* True when the type, or any class it extends, satisfies `test(symbolName, declaringFileName)`.
|
|
54
|
+
*
|
|
55
|
+
* @param {object} checker - The type checker.
|
|
56
|
+
* @param {object} type - The type to walk.
|
|
57
|
+
* @param {(name: string, file: string) => boolean} test - The predicate over one class or interface in the chain.
|
|
58
|
+
* @param {number} [depth] - The recursion guard.
|
|
59
|
+
* @returns {boolean} Whether the chain holds a match.
|
|
60
|
+
*/
|
|
61
|
+
export declare const derives: (checker: ts.TypeChecker, type: ts.Type | null | undefined, test: (name: string, file: string) => boolean, depth?: number) => boolean;
|
|
62
|
+
export declare const derivesFromBuiltinError: (context: Context, type: ts.Type | null | undefined) => boolean;
|
|
63
|
+
/** True when the type is (or extends) `DomainError` as declared by the repository's `platform/errors` owner. */
|
|
64
|
+
export declare const derivesFromDomainError: (context: Context, type: ts.Type | null | undefined) => boolean;
|
|
65
|
+
/**
|
|
66
|
+
* The owner-relative `errors/<capability>.error.ts` home of an error family, or null for a file that is not one.
|
|
67
|
+
*
|
|
68
|
+
* @param {object} hfs - The HFS view.
|
|
69
|
+
* @param {string} filename - The linted filename.
|
|
70
|
+
* @returns {{ capability: string, owner: string } | null} The file's capability name and its owner's directory name.
|
|
71
|
+
*/
|
|
72
|
+
export declare const errorHomeOf: (hfs: HfsView, filename: string) => {
|
|
73
|
+
capability: string | undefined;
|
|
74
|
+
owner: string | null | undefined;
|
|
75
|
+
} | null;
|
|
76
|
+
/** The names an import brings in from one package: local name to imported name (`*` for a namespace, `default`). */
|
|
77
|
+
export declare const importsFrom: (program: TSESTree.Program, matches: (source: string) => boolean) => Map<string, string>;
|
|
@@ -3,16 +3,13 @@
|
|
|
3
3
|
* which tier) and what it derives from. A rule never asks what a receiver is called; it asks what its type is and which
|
|
4
4
|
* owner of the repository declares that type. The owner and the tier come from the HFS slot view, never from a path.
|
|
5
5
|
*/
|
|
6
|
-
import ts from "typescript"
|
|
7
|
-
import { hfsOf } from "./hfs.
|
|
8
|
-
import { typeOrigins, typed } from "./types.
|
|
9
|
-
|
|
6
|
+
import ts from "typescript";
|
|
7
|
+
import { hfsOf } from "./hfs.js";
|
|
8
|
+
import { typeOrigins, typed } from "./types.js";
|
|
10
9
|
/** The last segment of an owner root (`src/modules/platform/errors` gives `errors`), or null when there is no owner. */
|
|
11
|
-
export const ownerName = (root) => (root ? root.split("/").at(-1) : null)
|
|
12
|
-
|
|
10
|
+
export const ownerName = (root) => (root ? root.split("/").at(-1) : null);
|
|
13
11
|
/** True when `file` belongs to the owner `<name>` of the given tier (`platform`, `errors`). */
|
|
14
|
-
export const isOwnedBy = (hfs, file, tier, name) => hfs.tierOf(file) === tier && ownerName(hfs.ownerOf(file)) === name
|
|
15
|
-
|
|
12
|
+
export const isOwnedBy = (hfs, file, tier, name) => hfs.tierOf(file) === tier && ownerName(hfs.ownerOf(file)) === name;
|
|
16
13
|
/**
|
|
17
14
|
* True when the node's type is `name`, declared by the owner `<tier>/<capability>` of this repository.
|
|
18
15
|
*
|
|
@@ -24,10 +21,9 @@ export const isOwnedBy = (hfs, file, tier, name) => hfs.tierOf(file) === tier &&
|
|
|
24
21
|
* @returns {boolean} Whether one of the type's origins matches.
|
|
25
22
|
*/
|
|
26
23
|
export const isOwnedType = (context, node, name, tier, capability) => {
|
|
27
|
-
const hfs = hfsOf(context)
|
|
28
|
-
return originsOf(context, node).some((origin) => origin.name === name && isOwnedBy(hfs, origin.file, tier, capability))
|
|
29
|
-
}
|
|
30
|
-
|
|
24
|
+
const hfs = hfsOf(context);
|
|
25
|
+
return originsOf(context, node).some((origin) => origin.name === name && isOwnedBy(hfs, origin.file, tier, capability));
|
|
26
|
+
};
|
|
31
27
|
/**
|
|
32
28
|
* Where the type of a node is declared, keeping a union ALIAS whole (`ErrorKind` is a union of literals; its origin is the
|
|
33
29
|
* alias declaration, not the literals). Falls back to `typeOrigins` for every other type.
|
|
@@ -37,20 +33,21 @@ export const isOwnedType = (context, node, name, tier, capability) => {
|
|
|
37
33
|
* @returns {Array<{ name: string, file: string, module: string | null }>} The declarations of the type.
|
|
38
34
|
*/
|
|
39
35
|
export const originsOf = (context, node) => {
|
|
40
|
-
const type = typeOf(context, node)
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
36
|
+
const type = typeOf(context, node);
|
|
37
|
+
const aliasSymbol = type?.aliasSymbol;
|
|
38
|
+
const alias = aliasSymbol?.declarations?.[0];
|
|
39
|
+
if (aliasSymbol && alias)
|
|
40
|
+
return [{ name: aliasSymbol.name, file: String(alias.getSourceFile().fileName).replace(/\\/g, "/"), module: null }];
|
|
41
|
+
return typeOrigins(context, node);
|
|
42
|
+
};
|
|
46
43
|
/** The TypeScript type of an ESTree node. */
|
|
47
44
|
export const typeOf = (context, node) => {
|
|
48
|
-
const { checker, toTs } = typed(context)
|
|
49
|
-
const tsNode = toTs(node)
|
|
50
|
-
if (!tsNode)
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
const { checker, toTs } = typed(context);
|
|
46
|
+
const tsNode = toTs(node);
|
|
47
|
+
if (!tsNode)
|
|
48
|
+
return null;
|
|
49
|
+
return ts.isTypeNode(tsNode) ? checker.getTypeFromTypeNode(tsNode) : checker.getTypeAtLocation(tsNode);
|
|
50
|
+
};
|
|
54
51
|
/**
|
|
55
52
|
* True when the node's type is a member of the enum `enumName` declared by the owner `<tier>/<capability>`.
|
|
56
53
|
*
|
|
@@ -62,33 +59,29 @@ export const typeOf = (context, node) => {
|
|
|
62
59
|
* @returns {boolean} Whether the value is a member of that enum.
|
|
63
60
|
*/
|
|
64
61
|
export const isOwnedEnumMember = (context, node, enumName, tier, capability) => {
|
|
65
|
-
const hfs = hfsOf(context)
|
|
66
|
-
const type = typeOf(context, node)
|
|
67
|
-
const parts = partsOf(type)
|
|
68
|
-
if (parts.length === 0)
|
|
62
|
+
const hfs = hfsOf(context);
|
|
63
|
+
const type = typeOf(context, node);
|
|
64
|
+
const parts = partsOf(type);
|
|
65
|
+
if (parts.length === 0)
|
|
66
|
+
return false;
|
|
69
67
|
return parts.every((part) => {
|
|
70
|
-
if (!(part.flags & ts.TypeFlags.EnumLiteral))
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
68
|
+
if (!(part.flags & ts.TypeFlags.EnumLiteral))
|
|
69
|
+
return false;
|
|
70
|
+
const declaration = part.getSymbol()?.declarations?.[0];
|
|
71
|
+
const owner = declaration?.parent;
|
|
72
|
+
return (declaration !== undefined &&
|
|
75
73
|
ts.isEnumMember(declaration) &&
|
|
76
74
|
owner !== undefined &&
|
|
77
75
|
ts.isEnumDeclaration(owner) &&
|
|
78
76
|
owner.name.text === enumName &&
|
|
79
|
-
isOwnedBy(hfs, String(declaration.getSourceFile().fileName).replace(/\\/g, "/"), tier, capability)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
77
|
+
isOwnedBy(hfs, String(declaration.getSourceFile().fileName).replace(/\\/g, "/"), tier, capability));
|
|
78
|
+
});
|
|
79
|
+
};
|
|
84
80
|
/** The members of a union type, or the type itself. */
|
|
85
|
-
export const partsOf = (type) => (type?.isUnion?.() ? type.types : type ? [type] : [])
|
|
86
|
-
|
|
87
|
-
const NULLISH = ts.TypeFlags.Undefined | ts.TypeFlags.Null | ts.TypeFlags.Void
|
|
88
|
-
|
|
81
|
+
export const partsOf = (type) => (type?.isUnion?.() ? type.types : type ? [type] : []);
|
|
82
|
+
const NULLISH = ts.TypeFlags.Undefined | ts.TypeFlags.Null | ts.TypeFlags.Void;
|
|
89
83
|
/** The members of a type with `undefined` and `null` removed (an optional property's real type). */
|
|
90
|
-
export const presentParts = (type) => partsOf(type).filter((part) => !(part.flags & NULLISH))
|
|
91
|
-
|
|
84
|
+
export const presentParts = (type) => partsOf(type).filter((part) => !(part.flags & NULLISH));
|
|
92
85
|
/**
|
|
93
86
|
* True when the type, or any class it extends, satisfies `test(symbolName, declaringFileName)`.
|
|
94
87
|
*
|
|
@@ -99,31 +92,39 @@ export const presentParts = (type) => partsOf(type).filter((part) => !(part.flag
|
|
|
99
92
|
* @returns {boolean} Whether the chain holds a match.
|
|
100
93
|
*/
|
|
101
94
|
export const derives = (checker, type, test, depth = 0) => {
|
|
102
|
-
if (!type || depth > 24)
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
95
|
+
if (!type || depth > 24)
|
|
96
|
+
return false;
|
|
97
|
+
const symbol = type.getSymbol?.();
|
|
98
|
+
if (symbol?.declarations?.some((declaration) => test(symbol.name, String(declaration.getSourceFile().fileName).replace(/\\/g, "/"))))
|
|
99
|
+
return true;
|
|
100
|
+
const target = targetOf(type);
|
|
101
|
+
if (!target.isClassOrInterface?.())
|
|
102
|
+
return false;
|
|
103
|
+
return checker.getBaseTypes(target).some((base) => derives(checker, base, test, depth + 1));
|
|
104
|
+
};
|
|
110
105
|
/** True when the type is (or extends) a declaration of the global `Error` from the TypeScript library. */
|
|
106
|
+
/** Whether a value is a TypeScript type (it carries numeric `flags`). */
|
|
107
|
+
const isTsType = (value) => typeof value === "object" && value !== null && "flags" in value && typeof value.flags === "number" && "checker" in value;
|
|
108
|
+
/** A generic instantiation's target (`Array<T>` of `Array<string>`), else the type itself. */
|
|
109
|
+
const targetOf = (type) => {
|
|
110
|
+
const target = "target" in type ? type.target : undefined;
|
|
111
|
+
return isTsType(target) ? target : type;
|
|
112
|
+
};
|
|
111
113
|
export const derivesFromBuiltinError = (context, type) => {
|
|
112
|
-
const { program, checker } = typed(context)
|
|
114
|
+
const { program, checker } = typed(context);
|
|
113
115
|
return derives(checker, type, (name, file) => {
|
|
114
|
-
if (name !== "Error")
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
116
|
+
if (name !== "Error")
|
|
117
|
+
return false;
|
|
118
|
+
const source = program.getSourceFile(file);
|
|
119
|
+
return source ? program.isSourceFileDefaultLibrary(source) : false;
|
|
120
|
+
});
|
|
121
|
+
};
|
|
120
122
|
/** True when the type is (or extends) `DomainError` as declared by the repository's `platform/errors` owner. */
|
|
121
123
|
export const derivesFromDomainError = (context, type) => {
|
|
122
|
-
const hfs = hfsOf(context)
|
|
123
|
-
const { checker } = typed(context)
|
|
124
|
-
return derives(checker, type, (name, file) => name === "DomainError" && isOwnedBy(hfs, file, "platform", "errors"))
|
|
125
|
-
}
|
|
126
|
-
|
|
124
|
+
const hfs = hfsOf(context);
|
|
125
|
+
const { checker } = typed(context);
|
|
126
|
+
return derives(checker, type, (name, file) => name === "DomainError" && isOwnedBy(hfs, file, "platform", "errors"));
|
|
127
|
+
};
|
|
127
128
|
/**
|
|
128
129
|
* The owner-relative `errors/<capability>.error.ts` home of an error family, or null for a file that is not one.
|
|
129
130
|
*
|
|
@@ -132,23 +133,27 @@ export const derivesFromDomainError = (context, type) => {
|
|
|
132
133
|
* @returns {{ capability: string, owner: string } | null} The file's capability name and its owner's directory name.
|
|
133
134
|
*/
|
|
134
135
|
export const errorHomeOf = (hfs, filename) => {
|
|
135
|
-
const root = hfs.ownerOf(filename)
|
|
136
|
-
if (!root)
|
|
137
|
-
|
|
138
|
-
const
|
|
139
|
-
|
|
140
|
-
}
|
|
141
|
-
|
|
136
|
+
const root = hfs.ownerOf(filename);
|
|
137
|
+
if (!root)
|
|
138
|
+
return null;
|
|
139
|
+
const inside = hfs.relative(filename).slice(root.length + 1);
|
|
140
|
+
const match = /^errors\/([a-z][a-z0-9-]*)\.error\.ts$/.exec(inside);
|
|
141
|
+
return match ? { capability: match[1], owner: ownerName(root) } : null;
|
|
142
|
+
};
|
|
142
143
|
/** The names an import brings in from one package: local name to imported name (`*` for a namespace, `default`). */
|
|
143
144
|
export const importsFrom = (program, matches) => {
|
|
144
|
-
const names = new Map()
|
|
145
|
+
const names = new Map();
|
|
145
146
|
for (const statement of program.body) {
|
|
146
|
-
if (statement.type !== "ImportDeclaration" || typeof statement.source.value !== "string" || !matches(statement.source.value))
|
|
147
|
+
if (statement.type !== "ImportDeclaration" || typeof statement.source.value !== "string" || !matches(statement.source.value))
|
|
148
|
+
continue;
|
|
147
149
|
for (const specifier of statement.specifiers) {
|
|
148
|
-
if (specifier.type === "ImportSpecifier")
|
|
149
|
-
|
|
150
|
-
else
|
|
150
|
+
if (specifier.type === "ImportSpecifier")
|
|
151
|
+
names.set(specifier.local.name, specifier.imported.type === "Identifier" ? specifier.imported.name : specifier.imported.value);
|
|
152
|
+
else if (specifier.type === "ImportNamespaceSpecifier")
|
|
153
|
+
names.set(specifier.local.name, "*");
|
|
154
|
+
else
|
|
155
|
+
names.set(specifier.local.name, "default");
|
|
151
156
|
}
|
|
152
157
|
}
|
|
153
|
-
return names
|
|
154
|
-
}
|
|
158
|
+
return names;
|
|
159
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the door rules of the feature kinds (webhooks, realtime) read from a class: what is injected into it, which methods
|
|
3
|
+
* the framework enters, and which expression a call is made on. Every answer comes from a decorator's import, a value's
|
|
4
|
+
* declared type or a declaration's origin, never from a spelling.
|
|
5
|
+
*/
|
|
6
|
+
import ts from "typescript";
|
|
7
|
+
import type { TSESTree } from "@typescript-eslint/utils";
|
|
8
|
+
import type { Context, Node } from "./rule.js";
|
|
9
|
+
/** A node that may carry decorators (a class, a member, a parameter). */
|
|
10
|
+
export interface Decorated {
|
|
11
|
+
readonly decorators?: readonly TSESTree.Decorator[];
|
|
12
|
+
}
|
|
13
|
+
/** A class of either form. */
|
|
14
|
+
export type ClassNode = TSESTree.ClassDeclaration | TSESTree.ClassExpression;
|
|
15
|
+
/** One injected member of a class: a constructor parameter or an injector-decorated property, with its type annotation. */
|
|
16
|
+
export interface InjectedMember {
|
|
17
|
+
readonly node: Node;
|
|
18
|
+
readonly annotation: TSESTree.TypeNode | undefined;
|
|
19
|
+
}
|
|
20
|
+
/** One call in a method body: the call, its member receiver and the called method name. */
|
|
21
|
+
export interface MethodCall {
|
|
22
|
+
readonly call: TSESTree.CallExpression;
|
|
23
|
+
readonly receiver: TSESTree.Expression | null;
|
|
24
|
+
readonly method: string | null;
|
|
25
|
+
}
|
|
26
|
+
/** True when the class carries a decorator that is `name` exported by `source`. */
|
|
27
|
+
export declare const hasClassDecorator: (context: Context, node: Decorated, source: string | readonly string[], name: string | readonly string[]) => boolean;
|
|
28
|
+
/** The decorators of a method or class that are one of `names` exported by `source`. */
|
|
29
|
+
export declare const decoratorsFrom: (context: Context, node: Decorated, source: string | readonly string[], names: string | readonly string[]) => TSESTree.Decorator[];
|
|
30
|
+
/**
|
|
31
|
+
* Every value injected into a class: a constructor parameter (plain or a parameter property) and a property that
|
|
32
|
+
* carries a decorator which injects (`Inject` of Nest, a `@nestjs/typeorm` injector or a function declared in a
|
|
33
|
+
* `*.decorators.ts` file).
|
|
34
|
+
*
|
|
35
|
+
* @param {object} context - The ESLint rule context.
|
|
36
|
+
* @param {object} classNode - A `ClassDeclaration`.
|
|
37
|
+
* @returns {Array<{ node: object, annotation: object | undefined }>} The injected members, each with its declared type annotation.
|
|
38
|
+
*/
|
|
39
|
+
export declare const injectedMembers: (context: Context, classNode: ClassNode) => InjectedMember[];
|
|
40
|
+
/** The symbol an identifier names, with an import alias resolved to its target. */
|
|
41
|
+
export declare const aliasTarget: (context: Context, identifier: Node) => ts.Symbol | undefined;
|
|
42
|
+
/** The methods of a class (instance, non-constructor) that carry one of the decorators `names` of `source`. */
|
|
43
|
+
export declare const methodsDecoratedBy: (context: Context, classNode: ClassNode, source: string | readonly string[], names: string | readonly string[]) => TSESTree.MethodDefinition[];
|
|
44
|
+
/**
|
|
45
|
+
* Every call made in a method body, closures included: `<receiver>.<method>(...)` as `{ call, receiver, method }`, and any
|
|
46
|
+
* other call as `{ call, receiver: null, method: null }`.
|
|
47
|
+
*/
|
|
48
|
+
export declare const callsOf: (method: TSESTree.MethodDefinition) => MethodCall[];
|
|
49
|
+
/** The parameters of a handler method, with the pattern a default value or a destructuring wraps unwrapped. */
|
|
50
|
+
export declare const parametersOf: (method: TSESTree.MethodDefinition) => (TSESTree.AssignmentPattern | TSESTree.BindingName | TSESTree.RestElement)[];
|