@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,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-aware helpers: a rule asks what a node IS (its TypeScript type and where that type is declared), never what it
|
|
3
|
+
* is called. `starciBeConfig` turns typed linting on for every file (`parserOptions.projectService`), so these
|
|
4
|
+
* helpers refuse to run without the program instead of falling back to a name match: a rule that silently degrades to
|
|
5
|
+
* a heuristic is the loophole the owner closed.
|
|
6
|
+
*/
|
|
7
|
+
import ts from "typescript";
|
|
8
|
+
import type { ParserServicesWithTypeInformation } from "@typescript-eslint/utils";
|
|
9
|
+
import type { Context, Node } from "./rule.js";
|
|
10
|
+
/** The TypeScript services of the linted file: the program, its checker and the ESTree to TS node map. */
|
|
11
|
+
export interface Typed {
|
|
12
|
+
readonly program: ts.Program;
|
|
13
|
+
readonly checker: ts.TypeChecker;
|
|
14
|
+
readonly toTs: ParserServicesWithTypeInformation["esTreeNodeToTSNodeMap"]["get"];
|
|
15
|
+
}
|
|
16
|
+
/** Where a type is declared: the symbol name, the forward-slash file and the package (null for the repository's own source). */
|
|
17
|
+
export interface TypeOrigin {
|
|
18
|
+
readonly name: string;
|
|
19
|
+
readonly file: string;
|
|
20
|
+
readonly module: string | null;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The TypeScript services of the file being linted.
|
|
24
|
+
*
|
|
25
|
+
* @param context - The ESLint rule context.
|
|
26
|
+
* @returns The program, its checker and the ESTree to TS node map.
|
|
27
|
+
*/
|
|
28
|
+
export declare const typed: (context: Context) => Typed;
|
|
29
|
+
/**
|
|
30
|
+
* Where the type of an ESTree node (or of a type annotation node) is declared.
|
|
31
|
+
*
|
|
32
|
+
* @param context - The ESLint rule context.
|
|
33
|
+
* @param node - An expression, identifier, parameter or type node.
|
|
34
|
+
* @returns Each declaration's symbol name, forward-slash file path and package; `[]` for a primitive or an anonymous type.
|
|
35
|
+
*/
|
|
36
|
+
export declare const typeOrigins: (context: Context, node: Node) => TypeOrigin[];
|
|
37
|
+
/**
|
|
38
|
+
* Where a TypeScript type is declared, for a rule that already holds a type from the checker (an alias argument, a call signature return).
|
|
39
|
+
*
|
|
40
|
+
* @param checker - The program's type checker.
|
|
41
|
+
* @param type - A TypeScript type.
|
|
42
|
+
* @returns The declaration origins, as `typeOrigins` returns them.
|
|
43
|
+
*/
|
|
44
|
+
export declare const originsOfType: (checker: ts.TypeChecker, type: ts.Type | undefined) => TypeOrigin[];
|
|
45
|
+
/** Whether a value is a TypeScript node (it carries a numeric `kind`). */
|
|
46
|
+
export declare const isTsNode: (value: unknown) => value is ts.Node;
|
|
47
|
+
/**
|
|
48
|
+
* The TypeScript node a node holds under `key` (`body`, `initializer`, `expression`), or undefined when it holds none: the typed
|
|
49
|
+
* form of reading `declaration?.body` off a declaration whose kind is not known.
|
|
50
|
+
*/
|
|
51
|
+
export declare const childNode: (node: ts.Node | null | undefined, key: string) => ts.Node | undefined;
|
|
52
|
+
/** A symbol after alias resolution (`import { X as Y }` gives X), or the symbol itself. */
|
|
53
|
+
export declare const resolvedSymbol: (checker: ts.TypeChecker, symbol: ts.Symbol | undefined) => ts.Symbol | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* The package a declaration belongs to: the name of an enclosing `declare module "<pkg>"`, else the package directory
|
|
56
|
+
* of a `node_modules/<pkg>/` (or `node_modules/@scope/<pkg>/`) file, else null for the repository's own source.
|
|
57
|
+
*/
|
|
58
|
+
export declare const moduleOf: (declaration: ts.Node, file: string) => string | null;
|
|
59
|
+
/**
|
|
60
|
+
* True when the node's type is the named type declared in a file whose path satisfies `fromFile`.
|
|
61
|
+
*
|
|
62
|
+
* @param context - The ESLint rule context.
|
|
63
|
+
* @param node - The node to type.
|
|
64
|
+
* @param name - The declared symbol name (`EntityManager`).
|
|
65
|
+
* @param fromFile - Filter on the declaring file (a package path, a slot).
|
|
66
|
+
* @returns Whether one of the node's type origins matches.
|
|
67
|
+
*/
|
|
68
|
+
export declare const isTypeNamed: (context: Context, node: Node, name: string, fromFile?: (file: string) => boolean) => boolean;
|
|
69
|
+
/**
|
|
70
|
+
* True when the node's type is `name` declared by the package `pkg` (`typeorm`, `@nestjs/cqrs`).
|
|
71
|
+
*
|
|
72
|
+
* @param context - The ESLint rule context.
|
|
73
|
+
* @param node - The node to type.
|
|
74
|
+
* @param name - The declared symbol name.
|
|
75
|
+
* @param pkg - The package that declares it.
|
|
76
|
+
* @returns Whether the node's type is that package's `name`.
|
|
77
|
+
*/
|
|
78
|
+
export declare const isPackageType: (context: Context, node: Node, name: string, pkg: string) => boolean;
|
|
79
|
+
/**
|
|
80
|
+
* The package that declares the value an expression names (`APP_GUARD` and `Injectable` of `@nestjs/*`), after alias resolution, or
|
|
81
|
+
* null for the repository's own declaration, an unresolved name or an expression that names no symbol.
|
|
82
|
+
*
|
|
83
|
+
* @param context - The ESLint rule context.
|
|
84
|
+
* @param node - An identifier, member expression or call (its callee is read).
|
|
85
|
+
* @returns The package name.
|
|
86
|
+
*/
|
|
87
|
+
export declare const packageOfExport: (context: Context, node: Node) => string | null;
|
|
88
|
+
/**
|
|
89
|
+
* True when the node is a reference to a value the package `pkg` exports (`APP_GUARD` of `@nestjs/core`). A local constant of the same name is not.
|
|
90
|
+
*
|
|
91
|
+
* @param context - The ESLint rule context.
|
|
92
|
+
* @param node - An identifier or member expression.
|
|
93
|
+
* @param pkg - The package that must declare the referenced value.
|
|
94
|
+
* @returns Whether the node references an export of that package.
|
|
95
|
+
*/
|
|
96
|
+
export declare const isPackageExport: (context: Context, node: Node, pkg: string) => boolean;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type-aware helpers: a rule asks what a node IS (its TypeScript type and where that type is declared), never what it
|
|
3
|
+
* is called. `starciBeConfig` turns typed linting on for every file (`parserOptions.projectService`), so these
|
|
4
|
+
* helpers refuse to run without the program instead of falling back to a name match: a rule that silently degrades to
|
|
5
|
+
* a heuristic is the loophole the owner closed.
|
|
6
|
+
*/
|
|
7
|
+
import ts from "typescript";
|
|
8
|
+
/**
|
|
9
|
+
* The TypeScript services of the file being linted.
|
|
10
|
+
*
|
|
11
|
+
* @param context - The ESLint rule context.
|
|
12
|
+
* @returns The program, its checker and the ESTree to TS node map.
|
|
13
|
+
*/
|
|
14
|
+
export const typed = (context) => {
|
|
15
|
+
const services = context.sourceCode?.parserServices ?? context.parserServices;
|
|
16
|
+
const program = services?.program;
|
|
17
|
+
const map = services?.esTreeNodeToTSNodeMap;
|
|
18
|
+
if (!program || !map) {
|
|
19
|
+
throw new Error(`${context.id ?? "a starci-be rule"} needs typed linting (parserOptions.projectService); lint through starciBeConfig, which turns it on`);
|
|
20
|
+
}
|
|
21
|
+
return { program, checker: program.getTypeChecker(), toTs: (node) => map.get(node) };
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* The declarations of a type: those of its alias (a written `type Repo = Repository<T>`) and those of its own symbol, each
|
|
25
|
+
* after alias resolution (an imported type alias resolves to its target). Both are origins, so a rename by alias hides nothing.
|
|
26
|
+
*/
|
|
27
|
+
const declarationsOf = (checker, type) => {
|
|
28
|
+
if (!type)
|
|
29
|
+
return [];
|
|
30
|
+
return [type.aliasSymbol, type.getSymbol?.()].flatMap((symbol) => {
|
|
31
|
+
if (!symbol)
|
|
32
|
+
return [];
|
|
33
|
+
const target = symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
34
|
+
return target.getDeclarations?.() ?? [];
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Where the type of an ESTree node (or of a type annotation node) is declared.
|
|
39
|
+
*
|
|
40
|
+
* @param context - The ESLint rule context.
|
|
41
|
+
* @param node - An expression, identifier, parameter or type node.
|
|
42
|
+
* @returns Each declaration's symbol name, forward-slash file path and package; `[]` for a primitive or an anonymous type.
|
|
43
|
+
*/
|
|
44
|
+
export const typeOrigins = (context, node) => {
|
|
45
|
+
const { checker, toTs } = typed(context);
|
|
46
|
+
const tsNode = toTs(node);
|
|
47
|
+
if (!tsNode)
|
|
48
|
+
return [];
|
|
49
|
+
return originsOfType(checker, ts.isTypeNode(tsNode) ? checker.getTypeFromTypeNode(tsNode) : checker.getTypeAtLocation(tsNode));
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Where a TypeScript type is declared, for a rule that already holds a type from the checker (an alias argument, a call signature return).
|
|
53
|
+
*
|
|
54
|
+
* @param checker - The program's type checker.
|
|
55
|
+
* @param type - A TypeScript type.
|
|
56
|
+
* @returns The declaration origins, as `typeOrigins` returns them.
|
|
57
|
+
*/
|
|
58
|
+
export const originsOfType = (checker, type) => {
|
|
59
|
+
const parts = type?.isUnion?.() ? type.types : [type];
|
|
60
|
+
return parts.flatMap((part) => declarationsOf(checker, part).map((declaration) => {
|
|
61
|
+
const file = String(declaration.getSourceFile().fileName).replace(/\\/g, "/");
|
|
62
|
+
return { name: identifierNameOf(declaration), file, module: moduleOf(declaration, file) };
|
|
63
|
+
}));
|
|
64
|
+
};
|
|
65
|
+
/** Whether a value is a TypeScript node (it carries a numeric `kind`). */
|
|
66
|
+
export const isTsNode = (value) => typeof value === "object" && value !== null && "kind" in value && typeof value.kind === "number";
|
|
67
|
+
/**
|
|
68
|
+
* The TypeScript node a node holds under `key` (`body`, `initializer`, `expression`), or undefined when it holds none: the typed
|
|
69
|
+
* form of reading `declaration?.body` off a declaration whose kind is not known.
|
|
70
|
+
*/
|
|
71
|
+
export const childNode = (node, key) => {
|
|
72
|
+
if (!node)
|
|
73
|
+
return undefined;
|
|
74
|
+
const value = Reflect.get(node, key);
|
|
75
|
+
return isTsNode(value) ? value : undefined;
|
|
76
|
+
};
|
|
77
|
+
/** A symbol after alias resolution (`import { X as Y }` gives X), or the symbol itself. */
|
|
78
|
+
export const resolvedSymbol = (checker, symbol) => (symbol && symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol);
|
|
79
|
+
/** The text of a declaration's own `name` when that name is an identifier, else "". */
|
|
80
|
+
const identifierNameOf = (declaration) => {
|
|
81
|
+
const name = "name" in declaration ? declaration.name : undefined;
|
|
82
|
+
return isTsNode(name) && ts.isIdentifier(name) ? name.text : "";
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* The package a declaration belongs to: the name of an enclosing `declare module "<pkg>"`, else the package directory
|
|
86
|
+
* of a `node_modules/<pkg>/` (or `node_modules/@scope/<pkg>/`) file, else null for the repository's own source.
|
|
87
|
+
*/
|
|
88
|
+
export const moduleOf = (declaration, file) => {
|
|
89
|
+
for (let node = declaration.parent; node; node = node.parent) {
|
|
90
|
+
if (ts.isModuleDeclaration(node) && ts.isStringLiteral(node.name))
|
|
91
|
+
return node.name.text;
|
|
92
|
+
}
|
|
93
|
+
const match = /\/node_modules\/((?:@[^/]+\/)?[^/]+)\//.exec(file);
|
|
94
|
+
return match?.[1] ?? null;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* True when the node's type is the named type declared in a file whose path satisfies `fromFile`.
|
|
98
|
+
*
|
|
99
|
+
* @param context - The ESLint rule context.
|
|
100
|
+
* @param node - The node to type.
|
|
101
|
+
* @param name - The declared symbol name (`EntityManager`).
|
|
102
|
+
* @param fromFile - Filter on the declaring file (a package path, a slot).
|
|
103
|
+
* @returns Whether one of the node's type origins matches.
|
|
104
|
+
*/
|
|
105
|
+
export const isTypeNamed = (context, node, name, fromFile = () => true) => typeOrigins(context, node).some((origin) => origin.name === name && fromFile(origin.file));
|
|
106
|
+
/**
|
|
107
|
+
* True when the node's type is `name` declared by the package `pkg` (`typeorm`, `@nestjs/cqrs`).
|
|
108
|
+
*
|
|
109
|
+
* @param context - The ESLint rule context.
|
|
110
|
+
* @param node - The node to type.
|
|
111
|
+
* @param name - The declared symbol name.
|
|
112
|
+
* @param pkg - The package that declares it.
|
|
113
|
+
* @returns Whether the node's type is that package's `name`.
|
|
114
|
+
*/
|
|
115
|
+
export const isPackageType = (context, node, name, pkg) => typeOrigins(context, node).some((origin) => origin.name === name && origin.module === pkg);
|
|
116
|
+
/**
|
|
117
|
+
* The package that declares the value an expression names (`APP_GUARD` and `Injectable` of `@nestjs/*`), after alias resolution, or
|
|
118
|
+
* null for the repository's own declaration, an unresolved name or an expression that names no symbol.
|
|
119
|
+
*
|
|
120
|
+
* @param context - The ESLint rule context.
|
|
121
|
+
* @param node - An identifier, member expression or call (its callee is read).
|
|
122
|
+
* @returns The package name.
|
|
123
|
+
*/
|
|
124
|
+
export const packageOfExport = (context, node) => {
|
|
125
|
+
const { checker, toTs } = typed(context);
|
|
126
|
+
let tsNode = toTs(node);
|
|
127
|
+
if (!tsNode)
|
|
128
|
+
return null;
|
|
129
|
+
if (ts.isCallExpression(tsNode))
|
|
130
|
+
tsNode = tsNode.expression;
|
|
131
|
+
const symbol = checker.getSymbolAtLocation(ts.isPropertyAccessExpression(tsNode) ? tsNode.name : tsNode);
|
|
132
|
+
if (!symbol)
|
|
133
|
+
return null;
|
|
134
|
+
const target = symbol.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(symbol) : symbol;
|
|
135
|
+
for (const declaration of target.getDeclarations?.() ?? []) {
|
|
136
|
+
const module = moduleOf(declaration, String(declaration.getSourceFile().fileName).replace(/\\/g, "/"));
|
|
137
|
+
if (module !== null)
|
|
138
|
+
return module;
|
|
139
|
+
}
|
|
140
|
+
return null;
|
|
141
|
+
};
|
|
142
|
+
/**
|
|
143
|
+
* True when the node is a reference to a value the package `pkg` exports (`APP_GUARD` of `@nestjs/core`). A local constant of the same name is not.
|
|
144
|
+
*
|
|
145
|
+
* @param context - The ESLint rule context.
|
|
146
|
+
* @param node - An identifier or member expression.
|
|
147
|
+
* @param pkg - The package that must declare the referenced value.
|
|
148
|
+
* @returns Whether the node references an export of that package.
|
|
149
|
+
*/
|
|
150
|
+
export const isPackageExport = (context, node, pkg) => packageOfExport(context, node) === pkg;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { HfsUnitRole, HfsView } from "./hfs.js";
|
|
2
|
+
/** A unit-tested role, or an optional logic role whose spec the coverage slot asks for. */
|
|
3
|
+
export interface SpecRole {
|
|
4
|
+
readonly role: string;
|
|
5
|
+
readonly spec: string;
|
|
6
|
+
readonly slot?: string;
|
|
7
|
+
readonly exempt?: readonly string[];
|
|
8
|
+
readonly optional?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/** The file name of a linted path. */
|
|
11
|
+
export declare const baseOf: (filename: string) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Whether a file is a unit spec.
|
|
14
|
+
*
|
|
15
|
+
* @param {object} hfs - The HFS view.
|
|
16
|
+
* @param {string} filename - The linted file.
|
|
17
|
+
* @returns {boolean} True for a `*.spec.ts` that is not a spec of another test kind.
|
|
18
|
+
*/
|
|
19
|
+
export declare const isUnitSpecFile: (hfs: HfsView, filename: string) => boolean;
|
|
20
|
+
/** Whether a file is a `<name>.service.spec.ts` unit spec. */
|
|
21
|
+
export declare const isServiceSpecFile: (hfs: HfsView, filename: string) => boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The unit-tested roles of the back end: `ruleParams.be.unitRoles` of the slot manifest, the ONE list (`[{ role, spec, slot? }]`).
|
|
24
|
+
*
|
|
25
|
+
* @param {object} hfs - The HFS view.
|
|
26
|
+
* @returns {ReadonlyArray<{ role: string, spec: string, slot?: string }>} The roles.
|
|
27
|
+
*/
|
|
28
|
+
export declare const unitRoles: (hfs: HfsView) => readonly HfsUnitRole[];
|
|
29
|
+
/**
|
|
30
|
+
* The unit-tested role whose spec a file is (`<name>.<role>.spec.ts`, in the role's slot), or null.
|
|
31
|
+
*
|
|
32
|
+
* @param {object} hfs - The HFS view.
|
|
33
|
+
* @param {string} filename - The linted file.
|
|
34
|
+
* @returns {object | null} The role entry.
|
|
35
|
+
*/
|
|
36
|
+
export declare const unitRoleOfSpec: (hfs: HfsView, filename: string) => SpecRole | null;
|
|
37
|
+
/** Whether a file is the spec of a value role (`ruleParams.be.valueRoles`: a zod schema): its subject is a declared value, so the spec parses it and builds no testing module. */
|
|
38
|
+
export declare const isValueRoleSpec: (hfs: HfsView, filename: string) => boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The unit-tested role whose subject a file is (`<name>.<role>.ts`, in the role's slot, outside the test tree), or null.
|
|
41
|
+
*
|
|
42
|
+
* @param {object} hfs - The HFS view.
|
|
43
|
+
* @param {string} filename - The linted file.
|
|
44
|
+
* @returns {object | null} The role entry.
|
|
45
|
+
*/
|
|
46
|
+
export declare const unitRoleOfSubject: (hfs: HfsView, filename: string) => HfsUnitRole | null;
|
|
47
|
+
/** The door a `<name>.<role>.spec.ts` of a feature kind tests, or null: `payment.webhook.spec.ts` gives `payment.webhook.ts`. */
|
|
48
|
+
export declare const doorOfSpec: (hfs: HfsView, filename: string) => string | null;
|
|
@@ -9,14 +9,11 @@
|
|
|
9
9
|
* (`<provider>.webhook.spec.ts`, `<channel>.gateway.spec.ts`, `<channel>.subscription.spec.ts` beside its door, in the kind's slot);
|
|
10
10
|
* the quality rules of R48 judge the service specs.
|
|
11
11
|
*/
|
|
12
|
-
import { basename } from "node:path"
|
|
13
|
-
|
|
12
|
+
import { basename } from "node:path";
|
|
14
13
|
/** The slots whose `*.spec.ts` files are not unit specs: the other test kinds and world infrastructure. */
|
|
15
|
-
const OTHER_KIND_SLOTS = new Set(["be.tests.e2e", "be.tests.integration", "be.tests.contract", "be.tests.world", "be.tests.world.kit"])
|
|
16
|
-
|
|
14
|
+
const OTHER_KIND_SLOTS = new Set(["be.tests.e2e", "be.tests.integration", "be.tests.contract", "be.tests.world", "be.tests.world.kit"]);
|
|
17
15
|
/** The file name of a linted path. */
|
|
18
|
-
export const baseOf = (filename) => basename(String(filename || "").replace(/\\/g, "/"))
|
|
19
|
-
|
|
16
|
+
export const baseOf = (filename) => basename(String(filename || "").replace(/\\/g, "/"));
|
|
20
17
|
/**
|
|
21
18
|
* Whether a file is a unit spec.
|
|
22
19
|
*
|
|
@@ -25,34 +22,29 @@ export const baseOf = (filename) => basename(String(filename || "").replace(/\\/
|
|
|
25
22
|
* @returns {boolean} True for a `*.spec.ts` that is not a spec of another test kind.
|
|
26
23
|
*/
|
|
27
24
|
export const isUnitSpecFile = (hfs, filename) => {
|
|
28
|
-
if (!/\.spec\.[cm]?ts$/.test(baseOf(filename)))
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
if (!/\.spec\.[cm]?ts$/.test(baseOf(filename)))
|
|
26
|
+
return false;
|
|
27
|
+
const found = hfs.classify(filename);
|
|
28
|
+
return !OTHER_KIND_SLOTS.has(found.slot ?? "") && !OTHER_KIND_SLOTS.has(found.nearest?.slot ?? "");
|
|
29
|
+
};
|
|
33
30
|
/** Whether a file is a `<name>.service.spec.ts` unit spec. */
|
|
34
|
-
export const isServiceSpecFile = (hfs, filename) => /\.service\.spec\.ts$/.test(baseOf(filename)) && isUnitSpecFile(hfs, filename)
|
|
35
|
-
|
|
31
|
+
export const isServiceSpecFile = (hfs, filename) => /\.service\.spec\.ts$/.test(baseOf(filename)) && isUnitSpecFile(hfs, filename);
|
|
36
32
|
/**
|
|
37
33
|
* The unit-tested roles of the back end: `ruleParams.be.unitRoles` of the slot manifest, the ONE list (`[{ role, spec, slot? }]`).
|
|
38
34
|
*
|
|
39
35
|
* @param {object} hfs - The HFS view.
|
|
40
36
|
* @returns {ReadonlyArray<{ role: string, spec: string, slot?: string }>} The roles.
|
|
41
37
|
*/
|
|
42
|
-
export const unitRoles = (hfs) => hfs.ruleParams.unitRoles ?? []
|
|
43
|
-
|
|
38
|
+
export const unitRoles = (hfs) => hfs.ruleParams.unitRoles ?? [];
|
|
44
39
|
/** Whether the slot that owns a file is measured at 100 per file (`coverage: required`): the home of the optional specs of the logic roles. */
|
|
45
40
|
const inCoverageSlot = (hfs, filename) => {
|
|
46
|
-
const slot = hfs.slotOf(filename)
|
|
47
|
-
return slot !== null && hfs.slot(slot)?.coverage === "required"
|
|
48
|
-
}
|
|
49
|
-
|
|
41
|
+
const slot = hfs.slotOf(filename);
|
|
42
|
+
return slot !== null && hfs.slot(slot)?.coverage === "required";
|
|
43
|
+
};
|
|
50
44
|
/** The roles whose spec is legal but not required: every logic role that is not a spec-required unit role. */
|
|
51
|
-
const optionalRoles = (hfs) => (hfs.ruleParams.logicRoles ?? []).filter((role) => !unitRoles(hfs).some((unit) => unit.role === role)).map((role) => ({ role, spec: `${role}.spec`, optional: true }))
|
|
52
|
-
|
|
45
|
+
const optionalRoles = (hfs) => (hfs.ruleParams.logicRoles ?? []).filter((role) => !unitRoles(hfs).some((unit) => unit.role === role)).map((role) => ({ role, spec: `${role}.spec`, optional: true }));
|
|
53
46
|
/** Whether a role admits a file by its slot (a role with no slot admits any slot; an optional logic role only a coverage-required slot). */
|
|
54
|
-
const inRoleSlot = (hfs, role, filename) => (role.optional === true ? inCoverageSlot(hfs, filename) : role.slot === undefined || hfs.slotOf(filename) === role.slot)
|
|
55
|
-
|
|
47
|
+
const inRoleSlot = (hfs, role, filename) => (role.optional === true ? inCoverageSlot(hfs, filename) : role.slot === undefined || hfs.slotOf(filename) === role.slot);
|
|
56
48
|
/**
|
|
57
49
|
* The unit-tested role whose spec a file is (`<name>.<role>.spec.ts`, in the role's slot), or null.
|
|
58
50
|
*
|
|
@@ -61,17 +53,16 @@ const inRoleSlot = (hfs, role, filename) => (role.optional === true ? inCoverage
|
|
|
61
53
|
* @returns {object | null} The role entry.
|
|
62
54
|
*/
|
|
63
55
|
export const unitRoleOfSpec = (hfs, filename) => {
|
|
64
|
-
if (!isUnitSpecFile(hfs, filename))
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
56
|
+
if (!isUnitSpecFile(hfs, filename))
|
|
57
|
+
return null;
|
|
58
|
+
const name = baseOf(filename);
|
|
59
|
+
return [...unitRoles(hfs), ...optionalRoles(hfs)].find((role) => name.endsWith(`.${role.spec}.ts`) && inRoleSlot(hfs, role, filename)) ?? null;
|
|
60
|
+
};
|
|
69
61
|
/** Whether a file is the spec of a value role (`ruleParams.be.valueRoles`: a zod schema): its subject is a declared value, so the spec parses it and builds no testing module. */
|
|
70
62
|
export const isValueRoleSpec = (hfs, filename) => {
|
|
71
|
-
const role = unitRoleOfSpec(hfs, filename)?.role
|
|
72
|
-
return role !== undefined && (hfs.ruleParams.valueRoles ?? []).includes(role)
|
|
73
|
-
}
|
|
74
|
-
|
|
63
|
+
const role = unitRoleOfSpec(hfs, filename)?.role;
|
|
64
|
+
return role !== undefined && (hfs.ruleParams.valueRoles ?? []).includes(role);
|
|
65
|
+
};
|
|
75
66
|
/**
|
|
76
67
|
* The unit-tested role whose subject a file is (`<name>.<role>.ts`, in the role's slot, outside the test tree), or null.
|
|
77
68
|
*
|
|
@@ -80,18 +71,18 @@ export const isValueRoleSpec = (hfs, filename) => {
|
|
|
80
71
|
* @returns {object | null} The role entry.
|
|
81
72
|
*/
|
|
82
73
|
export const unitRoleOfSubject = (hfs, filename) => {
|
|
83
|
-
const name = baseOf(filename)
|
|
84
|
-
const slot = hfs.slotOf(filename)
|
|
85
|
-
if (!slot || slot.startsWith("be.tests."))
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
|
|
74
|
+
const name = baseOf(filename);
|
|
75
|
+
const slot = hfs.slotOf(filename);
|
|
76
|
+
if (!slot || slot.startsWith("be.tests."))
|
|
77
|
+
return null;
|
|
78
|
+
return unitRoles(hfs).find((role) => name.endsWith(`.${role.role}.ts`) && !name.endsWith(`.${role.spec}.ts`) && inRoleSlot(hfs, role, filename)) ?? null;
|
|
79
|
+
};
|
|
89
80
|
/** The slots of the feature kinds whose door carries its own unit spec beside it. */
|
|
90
|
-
const DOOR_SPEC_SLOTS = new Set(["be.feature.webhooks.http", "be.feature.realtime.graphql", "be.feature.realtime.websocket", "be.feature.realtime.sse"])
|
|
91
|
-
|
|
81
|
+
const DOOR_SPEC_SLOTS = new Set(["be.feature.webhooks.http", "be.feature.realtime.graphql", "be.feature.realtime.websocket", "be.feature.realtime.sse"]);
|
|
92
82
|
/** The door a `<name>.<role>.spec.ts` of a feature kind tests, or null: `payment.webhook.spec.ts` gives `payment.webhook.ts`. */
|
|
93
83
|
export const doorOfSpec = (hfs, filename) => {
|
|
94
|
-
if (!isUnitSpecFile(hfs, filename) || !DOOR_SPEC_SLOTS.has(hfs.slotOf(filename) ?? ""))
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
84
|
+
if (!isUnitSpecFile(hfs, filename) || !DOOR_SPEC_SLOTS.has(hfs.slotOf(filename) ?? ""))
|
|
85
|
+
return null;
|
|
86
|
+
const match = /^(.+.(?:webhook|gateway|subscription|controller)).spec.ts$/.exec(baseOf(filename));
|
|
87
|
+
return match ? `${match[1]}.ts` : null;
|
|
88
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Context, Node } from "./rule.js";
|
|
2
|
+
import type { HfsView } from "./hfs.js";
|
|
3
|
+
/** A return names the declared PROVIDER_ACK itself, with identity and ownership resolved by TypeScript/HFS. */
|
|
4
|
+
export declare const isProviderAcknowledgement: (context: Context, hfs: HfsView, expression: Node | null | undefined) => boolean;
|
|
@@ -1,87 +1,103 @@
|
|
|
1
1
|
/** A provider's only POST body is its own exported, immutable literal acknowledgement. */
|
|
2
|
-
import ts from "typescript"
|
|
3
|
-
import { aliasTarget } from "./doors.
|
|
4
|
-
import { typed } from "./types.
|
|
5
|
-
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { aliasTarget } from "./doors.js";
|
|
4
|
+
import { typed } from "./types.js";
|
|
6
5
|
/** Static wrappers carry a type, never permission to compute the acknowledgement. */
|
|
7
6
|
const unwrap = (node) => {
|
|
8
|
-
while (node && (ts.isAsExpression(node) || ts.isSatisfiesExpression(node) || ts.isParenthesizedExpression(node)))
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
while (node && (ts.isAsExpression(node) || ts.isSatisfiesExpression(node) || ts.isParenthesizedExpression(node)))
|
|
8
|
+
node = node.expression;
|
|
9
|
+
return node;
|
|
10
|
+
};
|
|
12
11
|
/** A scalar literal includes JSON null and a signed numeric literal, but no identifier or template. */
|
|
12
|
+
const SCALAR_KEYWORDS = [ts.SyntaxKind.TrueKeyword, ts.SyntaxKind.FalseKeyword, ts.SyntaxKind.NullKeyword];
|
|
13
|
+
const SIGNS = [ts.SyntaxKind.PlusToken, ts.SyntaxKind.MinusToken];
|
|
13
14
|
const scalarLiteral = (node) => {
|
|
14
|
-
if (!node)
|
|
15
|
-
|
|
16
|
-
if (
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
if (!node)
|
|
16
|
+
return false;
|
|
17
|
+
if (ts.isStringLiteral(node) || ts.isNumericLiteral(node))
|
|
18
|
+
return true;
|
|
19
|
+
if (SCALAR_KEYWORDS.includes(node.kind))
|
|
20
|
+
return true;
|
|
21
|
+
return ts.isPrefixUnaryExpression(node) && SIGNS.includes(node.operator) && ts.isNumericLiteral(node.operand);
|
|
22
|
+
};
|
|
20
23
|
/** Literal data recursively excludes spreads, computed keys, methods, accessors and input references. */
|
|
21
24
|
const literalData = (expression) => {
|
|
22
|
-
const node = unwrap(expression)
|
|
23
|
-
if (scalarLiteral(node))
|
|
24
|
-
|
|
25
|
-
if (
|
|
25
|
+
const node = unwrap(expression);
|
|
26
|
+
if (scalarLiteral(node))
|
|
27
|
+
return true;
|
|
28
|
+
if (node && ts.isArrayLiteralExpression(node))
|
|
29
|
+
return node.elements.every((element) => literalData(element));
|
|
30
|
+
if (!node || !ts.isObjectLiteralExpression(node))
|
|
31
|
+
return false;
|
|
26
32
|
return node.properties.every((property) => ts.isPropertyAssignment(property)
|
|
27
33
|
&& (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name) || ts.isNumericLiteral(property.name))
|
|
28
|
-
&& literalData(property.initializer))
|
|
29
|
-
}
|
|
30
|
-
|
|
34
|
+
&& literalData(property.initializer));
|
|
35
|
+
};
|
|
31
36
|
/** The declaration has a const assertion anywhere in its static initializer wrappers. */
|
|
32
37
|
const constAsserted = (expression) => {
|
|
33
|
-
let node = expression
|
|
38
|
+
let node = expression;
|
|
34
39
|
while (node && (ts.isAsExpression(node) || ts.isSatisfiesExpression(node) || ts.isParenthesizedExpression(node))) {
|
|
35
|
-
if (ts.isAsExpression(node) && ts.isTypeReferenceNode(node.type) && ts.isIdentifier(node.type.typeName) && node.type.typeName.text === "const")
|
|
36
|
-
|
|
40
|
+
if (ts.isAsExpression(node) && ts.isTypeReferenceNode(node.type) && ts.isIdentifier(node.type.typeName) && node.type.typeName.text === "const")
|
|
41
|
+
return true;
|
|
42
|
+
node = node.expression;
|
|
37
43
|
}
|
|
38
|
-
return false
|
|
39
|
-
}
|
|
40
|
-
|
|
44
|
+
return false;
|
|
45
|
+
};
|
|
41
46
|
/** A readonly literal annotation cannot widen the provider's fixed body to arbitrary data. */
|
|
42
47
|
const builtinReadonly = (node, services) => {
|
|
43
|
-
if (!ts.isTypeReferenceNode(node) || !ts.isIdentifier(node.typeName) || node.typeName.text !== "Readonly" || node.typeArguments?.length !== 1)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
+
if (!ts.isTypeReferenceNode(node) || !ts.isIdentifier(node.typeName) || node.typeName.text !== "Readonly" || node.typeArguments?.length !== 1)
|
|
49
|
+
return false;
|
|
50
|
+
const symbol = services.checker.getSymbolAtLocation(node.typeName);
|
|
51
|
+
return (symbol?.getDeclarations() ?? []).some((declaration) => services.program.isSourceFileDefaultLibrary(declaration.getSourceFile()));
|
|
52
|
+
};
|
|
48
53
|
/** Readonly's built-in mapped type is trusted; a locally shadowed alias is not. */
|
|
49
54
|
const readonlyLiteralType = (node, services, readonly = false) => {
|
|
50
|
-
if (!node)
|
|
51
|
-
|
|
52
|
-
if (ts.
|
|
53
|
-
|
|
54
|
-
if (ts.
|
|
55
|
-
|
|
55
|
+
if (!node)
|
|
56
|
+
return false;
|
|
57
|
+
if (ts.isLiteralTypeNode(node))
|
|
58
|
+
return scalarLiteral(node.literal);
|
|
59
|
+
if (ts.isTypeOperatorNode(node) && node.operator === ts.SyntaxKind.ReadonlyKeyword)
|
|
60
|
+
return readonlyLiteralType(node.type, services, true);
|
|
61
|
+
if (builtinReadonly(node, services))
|
|
62
|
+
return readonlyLiteralType(node.typeArguments?.[0], services, true);
|
|
63
|
+
if (ts.isTupleTypeNode(node))
|
|
64
|
+
return readonly && node.elements.every((entry) => readonlyLiteralType(entry, services));
|
|
65
|
+
if (!ts.isTypeLiteralNode(node) || node.members.length === 0)
|
|
66
|
+
return false;
|
|
56
67
|
return node.members.every((member) => ts.isPropertySignature(member) && !member.questionToken
|
|
57
68
|
&& (readonly || member.modifiers?.some((modifier) => modifier.kind === ts.SyntaxKind.ReadonlyKeyword))
|
|
58
|
-
&& readonlyLiteralType(member.type, services))
|
|
59
|
-
}
|
|
60
|
-
|
|
69
|
+
&& readonlyLiteralType(member.type, services));
|
|
70
|
+
};
|
|
61
71
|
/** The actual symbol is exported by the source module, including a separate export declaration. */
|
|
62
72
|
const exportedByModule = (checker, declaration, symbol) => {
|
|
63
|
-
const sourceSymbol = checker.getSymbolAtLocation(declaration.getSourceFile())
|
|
64
|
-
if (!sourceSymbol)
|
|
73
|
+
const sourceSymbol = checker.getSymbolAtLocation(declaration.getSourceFile());
|
|
74
|
+
if (!sourceSymbol)
|
|
75
|
+
return false;
|
|
65
76
|
return checker.getExportsOfModule(sourceSymbol).some((entry) => {
|
|
66
|
-
const target = entry.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(entry) : entry
|
|
67
|
-
return entry.name === "PROVIDER_ACK" && target === symbol
|
|
68
|
-
})
|
|
69
|
-
}
|
|
70
|
-
|
|
77
|
+
const target = entry.flags & ts.SymbolFlags.Alias ? checker.getAliasedSymbol(entry) : entry;
|
|
78
|
+
return entry.name === "PROVIDER_ACK" && target === symbol;
|
|
79
|
+
});
|
|
80
|
+
};
|
|
71
81
|
/** A return names the declared PROVIDER_ACK itself, with identity and ownership resolved by TypeScript/HFS. */
|
|
72
82
|
export const isProviderAcknowledgement = (context, hfs, expression) => {
|
|
73
|
-
if (expression?.type !== "Identifier")
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const
|
|
83
|
+
if (expression?.type !== "Identifier")
|
|
84
|
+
return false;
|
|
85
|
+
const symbol = aliasTarget(context, expression);
|
|
86
|
+
if (!symbol || symbol.name !== "PROVIDER_ACK")
|
|
87
|
+
return false;
|
|
88
|
+
const services = typed(context);
|
|
89
|
+
const { checker } = services;
|
|
90
|
+
const owner = hfs.ownerOf(context.filename);
|
|
79
91
|
return (symbol.getDeclarations() ?? []).some((declaration) => {
|
|
80
|
-
if (!ts.isVariableDeclaration(declaration) || !(declaration.parent.flags & ts.NodeFlags.Const))
|
|
81
|
-
|
|
82
|
-
if (
|
|
83
|
-
|
|
84
|
-
if (!
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
92
|
+
if (!ts.isVariableDeclaration(declaration) || !(declaration.parent.flags & ts.NodeFlags.Const))
|
|
93
|
+
return false;
|
|
94
|
+
if (owner === null || hfs.ownerOf(declaration.getSourceFile().fileName) !== owner)
|
|
95
|
+
return false;
|
|
96
|
+
if (!exportedByModule(checker, declaration, symbol))
|
|
97
|
+
return false;
|
|
98
|
+
const value = unwrap(declaration.initializer);
|
|
99
|
+
if (!value || !(ts.isObjectLiteralExpression(value) || ts.isStringLiteral(value)) || !literalData(value))
|
|
100
|
+
return false;
|
|
101
|
+
return constAsserted(declaration.initializer) || readonlyLiteralType(declaration.type, services);
|
|
102
|
+
});
|
|
103
|
+
};
|