@autotelic/plumb 0.3.1 → 0.3.2
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/dist/effect/index.d.ts +3 -0
- package/dist/effect/index.js +56 -0
- package/dist/effect/rules/guarded-op-must-return-effect.d.ts +6 -0
- package/dist/effect/rules/guarded-op-must-return-effect.js +235 -0
- package/dist/effect/rules/guarded-op-must-return-option.d.ts +2 -0
- package/dist/effect/rules/guarded-op-must-return-option.js +88 -0
- package/dist/effect/rules/no-cascading-layer-provide.d.ts +6 -0
- package/dist/effect/rules/no-cascading-layer-provide.js +73 -0
- package/dist/effect/rules/no-decode-unknown-option.d.ts +7 -0
- package/dist/effect/rules/no-decode-unknown-option.js +34 -0
- package/dist/effect/rules/no-direct-browser-storage.d.ts +2 -0
- package/dist/effect/rules/no-direct-browser-storage.js +88 -0
- package/dist/effect/rules/no-direct-fetch.d.ts +2 -0
- package/dist/effect/rules/no-direct-fetch.js +37 -0
- package/dist/effect/rules/no-manual-field-guards.d.ts +6 -0
- package/dist/effect/rules/no-manual-field-guards.js +129 -0
- package/dist/effect/rules/no-nested-layer-provide.d.ts +2 -0
- package/dist/effect/rules/no-nested-layer-provide.js +50 -0
- package/dist/effect/rules/no-schema-class-modeling.d.ts +2 -0
- package/dist/effect/rules/no-schema-class-modeling.js +52 -0
- package/dist/effect/rules/no-service-constructor-imports.d.ts +2 -0
- package/dist/effect/rules/no-service-constructor-imports.js +42 -0
- package/dist/effect/rules/no-silent-error-swallow.d.ts +2 -0
- package/dist/effect/rules/no-silent-error-swallow.js +95 -0
- package/dist/effect/rules/no-static-effect-service-forwarders.d.ts +6 -0
- package/dist/effect/rules/no-static-effect-service-forwarders.js +222 -0
- package/dist/effect/rules/no-try-catch.d.ts +2 -0
- package/dist/effect/rules/no-try-catch.js +30 -0
- package/dist/effect/rules/no-unguarded-json-parse.d.ts +5 -0
- package/dist/effect/rules/no-unguarded-json-parse.js +200 -0
- package/dist/effect/rules/option-core-needs-effect-public.d.ts +5 -0
- package/dist/effect/rules/option-core-needs-effect-public.js +76 -0
- package/dist/effect/rules/prefer-die-for-precondition-defects.d.ts +5 -0
- package/dist/effect/rules/prefer-die-for-precondition-defects.js +112 -0
- package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.d.ts +5 -0
- package/dist/effect/rules/prefer-effect-gen-for-guard-ladders.js +72 -0
- package/dist/effect/rules/prefer-effect-match.d.ts +2 -0
- package/dist/effect/rules/prefer-effect-match.js +74 -0
- package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.d.ts +2 -0
- package/dist/effect/rules/prefer-effect-predicate-over-boolean-function.js +75 -0
- package/dist/effect/rules/prefer-named-guard-predicate.d.ts +2 -0
- package/dist/effect/rules/prefer-named-guard-predicate.js +93 -0
- package/dist/effect/rules/prefer-option-pipeline.d.ts +2 -0
- package/dist/effect/rules/prefer-option-pipeline.js +87 -0
- package/dist/effect/rules/prefer-ordering-match.d.ts +2 -0
- package/dist/effect/rules/prefer-ordering-match.js +135 -0
- package/dist/effect/rules/prefer-tagged-enum.d.ts +2 -0
- package/dist/effect/rules/prefer-tagged-enum.js +66 -0
- package/dist/effect/rules/require-schema-type-derivation.d.ts +7 -0
- package/dist/effect/rules/require-schema-type-derivation.js +80 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +102 -0
- package/dist/meta/index.d.ts +7 -0
- package/{src/meta/index.ts → dist/meta/index.js} +13 -16
- package/dist/meta/rules/no-disable-directives.d.ts +6 -0
- package/dist/meta/rules/no-disable-directives.js +35 -0
- package/dist/meta/rules/no-manual-ancestor-walks.d.ts +2 -0
- package/dist/meta/rules/no-manual-ancestor-walks.js +26 -0
- package/dist/meta/rules/prefer-before-file-scope.d.ts +2 -0
- package/dist/meta/rules/prefer-before-file-scope.js +57 -0
- package/dist/meta/rules/require-create-once.d.ts +2 -0
- package/dist/meta/rules/require-create-once.js +51 -0
- package/dist/meta/rules/require-rule-tester.d.ts +2 -0
- package/dist/meta/rules/require-rule-tester.js +50 -0
- package/dist/rules/no-anonymous-wide-tuples.d.ts +7 -0
- package/dist/rules/no-anonymous-wide-tuples.js +34 -0
- package/dist/rules/no-barrel-export-star.d.ts +2 -0
- package/dist/rules/no-barrel-export-star.js +26 -0
- package/dist/rules/no-boolean-field-signals.d.ts +2 -0
- package/dist/rules/no-boolean-field-signals.js +279 -0
- package/dist/rules/no-builtin-throws.d.ts +6 -0
- package/dist/rules/no-builtin-throws.js +74 -0
- package/dist/rules/no-chained-type-assertions.d.ts +2 -0
- package/dist/rules/no-chained-type-assertions.js +54 -0
- package/dist/rules/no-conditional-empty-object-spread.d.ts +2 -0
- package/dist/rules/no-conditional-empty-object-spread.js +36 -0
- package/dist/rules/no-duplicated-literal-union.d.ts +6 -0
- package/dist/rules/no-duplicated-literal-union.js +62 -0
- package/dist/rules/no-exported-mutable-state.d.ts +7 -0
- package/dist/rules/no-exported-mutable-state.js +104 -0
- package/dist/rules/no-generic-export-names.d.ts +2 -0
- package/dist/rules/no-generic-export-names.js +141 -0
- package/dist/rules/no-impossible-branch-throw.d.ts +2 -0
- package/dist/rules/no-impossible-branch-throw.js +51 -0
- package/dist/rules/no-known-value-widening.d.ts +2 -0
- package/dist/rules/no-known-value-widening.js +176 -0
- package/dist/rules/no-module-mocking.d.ts +2 -0
- package/dist/rules/no-module-mocking.js +90 -0
- package/dist/rules/no-multiple-function-params.d.ts +2 -0
- package/dist/rules/no-multiple-function-params.js +155 -0
- package/dist/rules/no-nondeterministic-core.d.ts +6 -0
- package/dist/rules/no-nondeterministic-core.js +63 -0
- package/dist/rules/no-object-parameters.d.ts +2 -0
- package/dist/rules/no-object-parameters.js +95 -0
- package/dist/rules/no-optional-function-parameters.d.ts +7 -0
- package/dist/rules/no-optional-function-parameters.js +44 -0
- package/dist/rules/no-product-of-state-booleans.d.ts +2 -0
- package/dist/rules/no-product-of-state-booleans.js +79 -0
- package/dist/rules/no-redundant-derived-field.d.ts +6 -0
- package/dist/rules/no-redundant-derived-field.js +194 -0
- package/dist/rules/no-reflect-apply.d.ts +2 -0
- package/dist/rules/no-reflect-apply.js +29 -0
- package/dist/rules/no-reflect-get.d.ts +2 -0
- package/dist/rules/no-reflect-get.js +29 -0
- package/dist/rules/no-reinterpret-cast.d.ts +2 -0
- package/dist/rules/no-reinterpret-cast.js +68 -0
- package/dist/rules/no-runtime-typeof.d.ts +2 -0
- package/dist/rules/no-runtime-typeof.js +54 -0
- package/dist/rules/no-sentinel-comparison-union.d.ts +2 -0
- package/dist/rules/no-sentinel-comparison-union.js +139 -0
- package/dist/rules/no-shape-in-symbol-names.d.ts +2 -0
- package/dist/rules/no-shape-in-symbol-names.js +39 -0
- package/dist/rules/no-single-use-private-functions.d.ts +6 -0
- package/dist/rules/no-single-use-private-functions.js +295 -0
- package/dist/rules/no-stacked-jsdoc-blocks.d.ts +2 -0
- package/dist/rules/no-stacked-jsdoc-blocks.js +50 -0
- package/dist/rules/no-stray-inline-comments.d.ts +2 -0
- package/dist/rules/no-stray-inline-comments.js +74 -0
- package/dist/rules/no-swappable-primitive-params.d.ts +2 -0
- package/dist/rules/no-swappable-primitive-params.js +96 -0
- package/dist/rules/no-tag-ladder-assertions.d.ts +6 -0
- package/dist/rules/no-tag-ladder-assertions.js +63 -0
- package/dist/rules/no-transposed-field-reads.d.ts +8 -0
- package/dist/rules/no-transposed-field-reads.js +101 -0
- package/dist/rules/no-unit-return-validators.d.ts +2 -0
- package/dist/rules/no-unit-return-validators.js +64 -0
- package/dist/rules/no-unknown-parameters.d.ts +2 -0
- package/dist/rules/no-unknown-parameters.js +82 -0
- package/dist/rules/no-unknown-returns.d.ts +2 -0
- package/dist/rules/no-unknown-returns.js +86 -0
- package/dist/rules/no-unknown-type-aliases.d.ts +2 -0
- package/dist/rules/no-unknown-type-aliases.js +64 -0
- package/dist/rules/no-unsafe-dictionary-type.d.ts +2 -0
- package/dist/rules/no-unsafe-dictionary-type.js +116 -0
- package/dist/rules/no-vague-test-filenames.d.ts +2 -0
- package/dist/rules/no-vague-test-filenames.js +61 -0
- package/dist/rules/no-widen-then-assert.d.ts +2 -0
- package/dist/rules/no-widen-then-assert.js +268 -0
- package/dist/rules/prefer-payload-brand.d.ts +2 -0
- package/dist/rules/prefer-payload-brand.js +57 -0
- package/dist/rules/prefer-property-tests.d.ts +5 -0
- package/dist/rules/prefer-property-tests.js +39 -0
- package/dist/rules/require-canonical-stringify-for-identity.d.ts +8 -0
- package/dist/rules/require-canonical-stringify-for-identity.js +72 -0
- package/dist/rules/require-deprecated-tag-for-legacy-comments.d.ts +2 -0
- package/dist/rules/require-deprecated-tag-for-legacy-comments.js +34 -0
- package/dist/rules/require-exhaustive-tag-switch.d.ts +7 -0
- package/dist/rules/require-exhaustive-tag-switch.js +34 -0
- package/dist/rules/require-fc-block-predicate.d.ts +2 -0
- package/dist/rules/require-fc-block-predicate.js +37 -0
- package/dist/rules/require-jsdoc-on-exported.d.ts +2 -0
- package/dist/rules/require-jsdoc-on-exported.js +66 -0
- package/dist/rules/require-published-order.d.ts +2 -0
- package/dist/rules/require-published-order.js +102 -0
- package/dist/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
- package/dist/rules/require-safety-comment-for-type-assertion.js +53 -0
- package/dist/rules/require-sort-comparator.d.ts +7 -0
- package/dist/rules/require-sort-comparator.js +34 -0
- package/dist/rules/test-utils.d.ts +35 -0
- package/dist/rules/test-utils.js +53 -0
- package/{src/shared/ancestors.ts → dist/shared/ancestors.d.ts} +1 -4
- package/dist/shared/ancestors.js +19 -0
- package/dist/shared/child-nodes.d.ts +12 -0
- package/dist/shared/child-nodes.js +26 -0
- package/dist/shared/dictionary-types.d.ts +55 -0
- package/dist/shared/dictionary-types.js +413 -0
- package/{src/shared/is-node.ts → dist/shared/is-node.d.ts} +2 -6
- package/dist/shared/is-node.js +10 -0
- package/dist/shared/lexical-type-parameters.d.ts +12 -0
- package/dist/shared/lexical-type-parameters.js +50 -0
- package/dist/shared/reflect-method.d.ts +15 -0
- package/dist/shared/reflect-method.js +32 -0
- package/{src/shared/rule-options.ts → dist/shared/rule-options.d.ts} +2 -7
- package/dist/shared/rule-options.js +12 -0
- package/{src/shared/structural.ts → dist/shared/structural.d.ts} +17 -44
- package/dist/shared/structural.js +40 -0
- package/{src/testing/index.ts → dist/testing/index.d.ts} +0 -1
- package/dist/testing/index.js +1 -0
- package/dist/testing/testable-rule.d.ts +38 -0
- package/dist/testing/testable-rule.js +70 -0
- package/package.json +7 -6
- package/src/effect/index.ts +0 -59
- package/src/effect/rules/guarded-op-must-return-effect.ts +0 -236
- package/src/effect/rules/guarded-op-must-return-option.ts +0 -97
- package/src/effect/rules/no-cascading-layer-provide.ts +0 -80
- package/src/effect/rules/no-decode-unknown-option.ts +0 -41
- package/src/effect/rules/no-direct-browser-storage.ts +0 -91
- package/src/effect/rules/no-direct-fetch.ts +0 -44
- package/src/effect/rules/no-manual-field-guards.ts +0 -144
- package/src/effect/rules/no-nested-layer-provide.ts +0 -51
- package/src/effect/rules/no-schema-class-modeling.ts +0 -59
- package/src/effect/rules/no-service-constructor-imports.ts +0 -50
- package/src/effect/rules/no-silent-error-swallow.ts +0 -99
- package/src/effect/rules/no-static-effect-service-forwarders.ts +0 -227
- package/src/effect/rules/no-try-catch.ts +0 -32
- package/src/effect/rules/no-unguarded-json-parse.ts +0 -211
- package/src/effect/rules/option-core-needs-effect-public.ts +0 -81
- package/src/effect/rules/prefer-die-for-precondition-defects.ts +0 -118
- package/src/effect/rules/prefer-effect-gen-for-guard-ladders.ts +0 -76
- package/src/effect/rules/prefer-effect-match.ts +0 -78
- package/src/effect/rules/prefer-effect-predicate-over-boolean-function.ts +0 -79
- package/src/effect/rules/prefer-named-guard-predicate.ts +0 -105
- package/src/effect/rules/prefer-option-pipeline.ts +0 -95
- package/src/effect/rules/prefer-ordering-match.ts +0 -152
- package/src/effect/rules/prefer-tagged-enum.ts +0 -68
- package/src/effect/rules/require-schema-type-derivation.ts +0 -83
- package/src/index.ts +0 -106
- package/src/meta/rules/no-disable-directives.ts +0 -38
- package/src/meta/rules/no-manual-ancestor-walks.ts +0 -27
- package/src/meta/rules/prefer-before-file-scope.ts +0 -57
- package/src/meta/rules/require-create-once.ts +0 -51
- package/src/meta/rules/require-rule-tester.ts +0 -57
- package/src/rules/no-anonymous-wide-tuples.ts +0 -38
- package/src/rules/no-barrel-export-star.ts +0 -30
- package/src/rules/no-boolean-field-signals.ts +0 -305
- package/src/rules/no-builtin-throws.ts +0 -83
- package/src/rules/no-chained-type-assertions.ts +0 -65
- package/src/rules/no-conditional-empty-object-spread.ts +0 -42
- package/src/rules/no-duplicated-literal-union.ts +0 -66
- package/src/rules/no-exported-mutable-state.ts +0 -111
- package/src/rules/no-generic-export-names.ts +0 -149
- package/src/rules/no-impossible-branch-throw.ts +0 -55
- package/src/rules/no-known-value-widening.ts +0 -225
- package/src/rules/no-module-mocking.ts +0 -95
- package/src/rules/no-multiple-function-params.ts +0 -192
- package/src/rules/no-nondeterministic-core.ts +0 -73
- package/src/rules/no-object-parameters.ts +0 -127
- package/src/rules/no-optional-function-parameters.ts +0 -49
- package/src/rules/no-product-of-state-booleans.ts +0 -80
- package/src/rules/no-redundant-derived-field.ts +0 -192
- package/src/rules/no-reflect-apply.ts +0 -32
- package/src/rules/no-reflect-get.ts +0 -32
- package/src/rules/no-reinterpret-cast.ts +0 -78
- package/src/rules/no-runtime-typeof.ts +0 -59
- package/src/rules/no-sentinel-comparison-union.ts +0 -148
- package/src/rules/no-shape-in-symbol-names.ts +0 -45
- package/src/rules/no-single-use-private-functions.ts +0 -329
- package/src/rules/no-stacked-jsdoc-blocks.ts +0 -65
- package/src/rules/no-stray-inline-comments.ts +0 -79
- package/src/rules/no-swappable-primitive-params.ts +0 -109
- package/src/rules/no-tag-ladder-assertions.ts +0 -71
- package/src/rules/no-transposed-field-reads.ts +0 -135
- package/src/rules/no-unit-return-validators.ts +0 -65
- package/src/rules/no-unknown-parameters.ts +0 -97
- package/src/rules/no-unknown-returns.ts +0 -120
- package/src/rules/no-unknown-type-aliases.ts +0 -70
- package/src/rules/no-unsafe-dictionary-type.ts +0 -132
- package/src/rules/no-vague-test-filenames.ts +0 -67
- package/src/rules/no-widen-then-assert.ts +0 -345
- package/src/rules/prefer-payload-brand.ts +0 -67
- package/src/rules/prefer-property-tests.ts +0 -43
- package/src/rules/require-canonical-stringify-for-identity.ts +0 -80
- package/src/rules/require-deprecated-tag-for-legacy-comments.ts +0 -45
- package/src/rules/require-exhaustive-tag-switch.ts +0 -42
- package/src/rules/require-fc-block-predicate.ts +0 -42
- package/src/rules/require-jsdoc-on-exported.ts +0 -74
- package/src/rules/require-published-order.ts +0 -109
- package/src/rules/require-safety-comment-for-type-assertion.ts +0 -61
- package/src/rules/require-sort-comparator.ts +0 -41
- package/src/rules/test-utils.ts +0 -68
- package/src/shared/child-nodes.ts +0 -27
- package/src/shared/dictionary-types.ts +0 -524
- package/src/shared/lexical-type-parameters.ts +0 -62
- package/src/shared/reflect-method.ts +0 -41
- package/src/testing/testable-rule.test.ts +0 -68
- package/src/testing/testable-rule.ts +0 -86
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
const BUILT_INS = new Set([
|
|
2
|
+
"Record",
|
|
3
|
+
"Readonly",
|
|
4
|
+
"Partial",
|
|
5
|
+
"Required",
|
|
6
|
+
"Pick",
|
|
7
|
+
"Omit",
|
|
8
|
+
"PropertyKey",
|
|
9
|
+
"NonNullable",
|
|
10
|
+
]);
|
|
11
|
+
const TRANSPARENT_WRAPPERS = new Set(["Readonly", "Partial", "Required", "NonNullable"]);
|
|
12
|
+
/**
|
|
13
|
+
* Build the alias/interface maps for a program so type references can be
|
|
14
|
+
* resolved to their declarations during dictionary classification.
|
|
15
|
+
* @param {ESTree.Program} program - Root AST node of the file under lint.
|
|
16
|
+
* @returns {TypeEnvironment} Environment mapping declared names to their declaration nodes.
|
|
17
|
+
*/
|
|
18
|
+
export function createTypeEnvironment(program) {
|
|
19
|
+
const aliases = new Map();
|
|
20
|
+
const interfaces = new Map();
|
|
21
|
+
const shadowedBuiltIns = new Set();
|
|
22
|
+
for (const statement of program.body) {
|
|
23
|
+
const declaration = statement.type === "ExportNamedDeclaration" || statement.type === "ExportDefaultDeclaration"
|
|
24
|
+
? statement.declaration ?? null
|
|
25
|
+
: statement;
|
|
26
|
+
if (declaration?.type === "ImportDeclaration") {
|
|
27
|
+
for (const specifier of declaration.specifiers) {
|
|
28
|
+
if (BUILT_INS.has(specifier.local.name))
|
|
29
|
+
shadowedBuiltIns.add(specifier.local.name);
|
|
30
|
+
}
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
if (declaration?.type === "TSTypeAliasDeclaration") {
|
|
34
|
+
const existing = aliases.get(declaration.id.name);
|
|
35
|
+
if (existing === undefined)
|
|
36
|
+
aliases.set(declaration.id.name, declaration);
|
|
37
|
+
else
|
|
38
|
+
shadowedBuiltIns.add(declaration.id.name);
|
|
39
|
+
if (BUILT_INS.has(declaration.id.name))
|
|
40
|
+
shadowedBuiltIns.add(declaration.id.name);
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
if (declaration?.type === "TSInterfaceDeclaration") {
|
|
44
|
+
const declarations = interfaces.get(declaration.id.name) ?? [];
|
|
45
|
+
declarations.push(declaration);
|
|
46
|
+
interfaces.set(declaration.id.name, declarations);
|
|
47
|
+
if (BUILT_INS.has(declaration.id.name))
|
|
48
|
+
shadowedBuiltIns.add(declaration.id.name);
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
if (declaration?.type === "TSEnumDeclaration") {
|
|
52
|
+
if (BUILT_INS.has(declaration.id.name))
|
|
53
|
+
shadowedBuiltIns.add(declaration.id.name);
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if ((declaration?.type === "ClassDeclaration" ||
|
|
57
|
+
declaration?.type === "FunctionDeclaration") &&
|
|
58
|
+
declaration.id !== null) {
|
|
59
|
+
if (BUILT_INS.has(declaration.id.name))
|
|
60
|
+
shadowedBuiltIns.add(declaration.id.name);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return { aliases, interfaces, shadowedBuiltIns };
|
|
64
|
+
}
|
|
65
|
+
function typeReferenceName(type) {
|
|
66
|
+
return type.typeName.type === "Identifier" ? type.typeName.name : null;
|
|
67
|
+
}
|
|
68
|
+
function isBuiltIn(payload) {
|
|
69
|
+
return BUILT_INS.has(payload.name) && !payload.environment.shadowedBuiltIns.has(payload.name);
|
|
70
|
+
}
|
|
71
|
+
function isUnappliedReferenceTo(payload) {
|
|
72
|
+
const unwrapped = unwrapTransparentType(payload.type);
|
|
73
|
+
return (unwrapped.type === "TSTypeReference" &&
|
|
74
|
+
typeReferenceName(unwrapped) === payload.name &&
|
|
75
|
+
(unwrapped.typeArguments === null ||
|
|
76
|
+
unwrapped.typeArguments === undefined ||
|
|
77
|
+
unwrapped.typeArguments.params.length === 0));
|
|
78
|
+
}
|
|
79
|
+
function unwrapTransparentType(type) {
|
|
80
|
+
let current = type;
|
|
81
|
+
while (current.type === "TSParenthesizedType" ||
|
|
82
|
+
(current.type === "TSTypeOperator" && current.operator === "readonly")) {
|
|
83
|
+
current = current.typeAnnotation;
|
|
84
|
+
}
|
|
85
|
+
return current;
|
|
86
|
+
}
|
|
87
|
+
function isEffectivelyEmptyMember(member) {
|
|
88
|
+
return (member.type === "TSPropertySignature" &&
|
|
89
|
+
member.optional === true &&
|
|
90
|
+
member.typeAnnotation !== null &&
|
|
91
|
+
member.typeAnnotation !== undefined &&
|
|
92
|
+
unwrapTransparentType(member.typeAnnotation.typeAnnotation).type === "TSNeverKeyword");
|
|
93
|
+
}
|
|
94
|
+
function resolvedSubstitutionArgument(payload) {
|
|
95
|
+
const { type, base } = payload;
|
|
96
|
+
const resolving = payload.resolving ?? new Set();
|
|
97
|
+
const unwrapped = unwrapTransparentType(type);
|
|
98
|
+
if (unwrapped.type !== "TSTypeReference")
|
|
99
|
+
return type;
|
|
100
|
+
const name = typeReferenceName(unwrapped);
|
|
101
|
+
if (name === null || resolving.has(name))
|
|
102
|
+
return type;
|
|
103
|
+
const substitution = base.get(name);
|
|
104
|
+
if (substitution === undefined)
|
|
105
|
+
return type;
|
|
106
|
+
const nextResolving = new Set(resolving);
|
|
107
|
+
nextResolving.add(name);
|
|
108
|
+
return resolvedSubstitutionArgument({ type: substitution, base, resolving: nextResolving });
|
|
109
|
+
}
|
|
110
|
+
function aliasSubstitution(alias, type, base) {
|
|
111
|
+
const parameters = alias.typeParameters?.params ?? [];
|
|
112
|
+
const arguments_ = type.typeArguments?.params ?? [];
|
|
113
|
+
const next = new Map(base);
|
|
114
|
+
for (const [index, parameter] of parameters.entries()) {
|
|
115
|
+
const argument = arguments_[index] ?? parameter.default;
|
|
116
|
+
if (argument === null || argument === undefined)
|
|
117
|
+
return null;
|
|
118
|
+
next.set(parameter.name.name, resolvedSubstitutionArgument({ type: argument, base }));
|
|
119
|
+
}
|
|
120
|
+
return next;
|
|
121
|
+
}
|
|
122
|
+
function unsafeDirectValue(type, environment, substitutions, resolvingAliases) {
|
|
123
|
+
const unwrapped = unwrapTransparentType(type);
|
|
124
|
+
if (unwrapped.type === "TSUnknownKeyword")
|
|
125
|
+
return "unknown";
|
|
126
|
+
if (unwrapped.type === "TSAnyKeyword")
|
|
127
|
+
return "any";
|
|
128
|
+
if (unwrapped.type === "TSObjectKeyword")
|
|
129
|
+
return "object";
|
|
130
|
+
if (unwrapped.type === "TSTypeLiteral" &&
|
|
131
|
+
(unwrapped.members.length === 0 || unwrapped.members.every(isEffectivelyEmptyMember)))
|
|
132
|
+
return "empty-object";
|
|
133
|
+
if (unwrapped.type === "TSUnionType") {
|
|
134
|
+
return unwrapped.types.some((member) => unsafeDirectValue(member, environment, substitutions, resolvingAliases) !== null)
|
|
135
|
+
? "union"
|
|
136
|
+
: null;
|
|
137
|
+
}
|
|
138
|
+
if (unwrapped.type === "TSIntersectionType") {
|
|
139
|
+
const unsafeMembers = unwrapped.types.map((member) => unsafeDirectValue(member, environment, substitutions, resolvingAliases));
|
|
140
|
+
if (unsafeMembers.includes("any"))
|
|
141
|
+
return "any";
|
|
142
|
+
const [firstUnsafeMember] = unsafeMembers;
|
|
143
|
+
return unsafeMembers.length > 0 &&
|
|
144
|
+
firstUnsafeMember !== undefined &&
|
|
145
|
+
unsafeMembers.every((member) => member !== null)
|
|
146
|
+
? firstUnsafeMember
|
|
147
|
+
: null;
|
|
148
|
+
}
|
|
149
|
+
if (unwrapped.type !== "TSTypeReference")
|
|
150
|
+
return null;
|
|
151
|
+
const name = typeReferenceName(unwrapped);
|
|
152
|
+
if (name === null)
|
|
153
|
+
return null;
|
|
154
|
+
if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn({ name, environment })) {
|
|
155
|
+
const wrapped = unwrapped.typeArguments?.params[0];
|
|
156
|
+
return wrapped === undefined
|
|
157
|
+
? null
|
|
158
|
+
: unsafeDirectValue(wrapped, environment, substitutions, resolvingAliases);
|
|
159
|
+
}
|
|
160
|
+
const substitution = substitutions.get(name);
|
|
161
|
+
if (substitution !== undefined) {
|
|
162
|
+
return isUnappliedReferenceTo({ type: substitution, name })
|
|
163
|
+
? null
|
|
164
|
+
: unsafeDirectValue(substitution, environment, substitutions, resolvingAliases);
|
|
165
|
+
}
|
|
166
|
+
const interfaceDeclarations = environment.interfaces.get(name);
|
|
167
|
+
if (interfaceDeclarations !== undefined) {
|
|
168
|
+
const [declaration] = interfaceDeclarations;
|
|
169
|
+
const effectivelyEmpty = interfaceDeclarations.length === 1 &&
|
|
170
|
+
declaration !== undefined &&
|
|
171
|
+
declaration.extends.length === 0 &&
|
|
172
|
+
(declaration.body.body.length === 0 ||
|
|
173
|
+
declaration.body.body.every(isEffectivelyEmptyMember));
|
|
174
|
+
return effectivelyEmpty ? "empty-object" : null;
|
|
175
|
+
}
|
|
176
|
+
const alias = environment.aliases.get(name);
|
|
177
|
+
if (alias === undefined || resolvingAliases.has(name))
|
|
178
|
+
return null;
|
|
179
|
+
const nextSubstitutions = aliasSubstitution(alias, unwrapped, substitutions);
|
|
180
|
+
if (nextSubstitutions === null)
|
|
181
|
+
return null;
|
|
182
|
+
const nextResolving = new Set(resolvingAliases);
|
|
183
|
+
nextResolving.add(name);
|
|
184
|
+
return unsafeDirectValue(alias.typeAnnotation, environment, nextSubstitutions, nextResolving);
|
|
185
|
+
}
|
|
186
|
+
function dictionaryValueTypes(type, environment, substitutions, resolvingAliases) {
|
|
187
|
+
const unwrapped = unwrapTransparentType(type);
|
|
188
|
+
if (unwrapped.type === "TSTypeLiteral") {
|
|
189
|
+
return unwrapped.members.flatMap((member) => member.type === "TSIndexSignature" && member.typeAnnotation !== null
|
|
190
|
+
? [{ type: member.typeAnnotation.typeAnnotation, substitutions }]
|
|
191
|
+
: []);
|
|
192
|
+
}
|
|
193
|
+
if (unwrapped.type === "TSMappedType") {
|
|
194
|
+
return unwrapped.typeAnnotation === null
|
|
195
|
+
? []
|
|
196
|
+
: [{ type: unwrapped.typeAnnotation, substitutions }];
|
|
197
|
+
}
|
|
198
|
+
if (unwrapped.type !== "TSTypeReference")
|
|
199
|
+
return [];
|
|
200
|
+
const name = typeReferenceName(unwrapped);
|
|
201
|
+
if (name === null)
|
|
202
|
+
return [];
|
|
203
|
+
const substitution = substitutions.get(name);
|
|
204
|
+
if (substitution !== undefined) {
|
|
205
|
+
return isUnappliedReferenceTo({ type: substitution, name })
|
|
206
|
+
? []
|
|
207
|
+
: dictionaryValueTypes(substitution, environment, substitutions, resolvingAliases);
|
|
208
|
+
}
|
|
209
|
+
if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn({ name, environment })) {
|
|
210
|
+
const wrapped = unwrapped.typeArguments?.params[0];
|
|
211
|
+
return wrapped === undefined
|
|
212
|
+
? []
|
|
213
|
+
: dictionaryValueTypes(wrapped, environment, substitutions, resolvingAliases);
|
|
214
|
+
}
|
|
215
|
+
if (name === "Record" && isBuiltIn({ name, environment })) {
|
|
216
|
+
const value = unwrapped.typeArguments?.params[1] ?? null;
|
|
217
|
+
return value === null ? [] : [{ type: value, substitutions }];
|
|
218
|
+
}
|
|
219
|
+
if ((name === "Pick" || name === "Omit") && isBuiltIn({ name, environment })) {
|
|
220
|
+
const source = unwrapped.typeArguments?.params[0];
|
|
221
|
+
return source === undefined
|
|
222
|
+
? []
|
|
223
|
+
: dictionaryValueTypes(source, environment, substitutions, resolvingAliases);
|
|
224
|
+
}
|
|
225
|
+
const alias = environment.aliases.get(name);
|
|
226
|
+
if (alias === undefined || resolvingAliases.has(name))
|
|
227
|
+
return [];
|
|
228
|
+
const nextSubstitutions = aliasSubstitution(alias, unwrapped, substitutions);
|
|
229
|
+
if (nextSubstitutions === null)
|
|
230
|
+
return [];
|
|
231
|
+
const nextResolving = new Set(resolvingAliases);
|
|
232
|
+
nextResolving.add(name);
|
|
233
|
+
return dictionaryValueTypes(alias.typeAnnotation, environment, nextSubstitutions, nextResolving);
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Classify a single type as an unsafe dictionary value, if it is one.
|
|
237
|
+
* @param {ESTree.TSType} valueType - Type annotation of the dictionary value slot.
|
|
238
|
+
* @param {TypeEnvironment} environment - Declared-alias environment from createTypeEnvironment.
|
|
239
|
+
* @returns {UnsafeDictionary | null} The unsafe kind ("any", "unknown", "object", "empty-object") or null.
|
|
240
|
+
*/
|
|
241
|
+
export function classifyUnsafeDictionaryValue(valueType, environment) {
|
|
242
|
+
const unsafeValue = unsafeDirectValue(valueType, environment, new Map(), new Set());
|
|
243
|
+
return unsafeValue === null ? null : { kind: "unsafe-dictionary", unsafeValue };
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Classify the value side of an index-signature or Record dictionary.
|
|
247
|
+
* @param {ESTree.TSType} type - The dictionary type node being inspected.
|
|
248
|
+
* @param {TypeEnvironment} environment - Declared-alias environment from createTypeEnvironment.
|
|
249
|
+
* @returns {UnsafeDictionary | null} Classification with kind and location, or null when safe.
|
|
250
|
+
*/
|
|
251
|
+
export function classifyUnsafeDictionary(type, environment) {
|
|
252
|
+
for (const valueType of dictionaryValueTypes(type, environment, new Map(), new Set())) {
|
|
253
|
+
const unsafeValue = unsafeDirectValue(valueType.type, environment, valueType.substitutions, new Set());
|
|
254
|
+
if (unsafeValue !== null)
|
|
255
|
+
return { kind: "unsafe-dictionary", unsafeValue };
|
|
256
|
+
}
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Describe what a widening assignment erases, for report messaging.
|
|
261
|
+
* @param {ESTree.TSType} type - The assigned (widened) type.
|
|
262
|
+
* @param {TypeEnvironment} environment - Declared-alias environment from createTypeEnvironment.
|
|
263
|
+
* @returns {WideningTarget | null} Human-readable target description, or null when not a widening.
|
|
264
|
+
*/
|
|
265
|
+
export function classifyWideningTarget(type, environment) {
|
|
266
|
+
const unwrapped = unwrapTransparentType(type);
|
|
267
|
+
if (unwrapped.type === "TSUnknownKeyword")
|
|
268
|
+
return { kind: "unknown" };
|
|
269
|
+
if (unwrapped.type === "TSObjectKeyword")
|
|
270
|
+
return { kind: "object" };
|
|
271
|
+
if (unwrapped.type === "TSTypeLiteral") {
|
|
272
|
+
return unwrapped.members.some((member) => member.type === "TSIndexSignature")
|
|
273
|
+
? { kind: "open dictionary" }
|
|
274
|
+
: unwrapped.members.length > 0
|
|
275
|
+
? { kind: "anonymous object" }
|
|
276
|
+
: null;
|
|
277
|
+
}
|
|
278
|
+
if (unwrapped.type === "TSMappedType")
|
|
279
|
+
return { kind: "open dictionary" };
|
|
280
|
+
if (unwrapped.type !== "TSTypeReference")
|
|
281
|
+
return null;
|
|
282
|
+
const name = typeReferenceName(unwrapped);
|
|
283
|
+
if (name === null)
|
|
284
|
+
return null;
|
|
285
|
+
if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn({ name, environment })) {
|
|
286
|
+
const wrapped = unwrapped.typeArguments?.params[0];
|
|
287
|
+
return wrapped === undefined ? null : classifyWideningTarget(wrapped, environment);
|
|
288
|
+
}
|
|
289
|
+
if (name === "Record" && isBuiltIn({ name, environment }))
|
|
290
|
+
return { kind: "open dictionary" };
|
|
291
|
+
const alias = environment.aliases.get(name);
|
|
292
|
+
if (alias === undefined)
|
|
293
|
+
return null;
|
|
294
|
+
if ((alias.typeParameters?.params.length ?? 0) > 0) {
|
|
295
|
+
const substitutions = aliasSubstitution(alias, unwrapped, new Map());
|
|
296
|
+
const resolves = substitutions !== null &&
|
|
297
|
+
dictionaryValueTypes(alias.typeAnnotation, environment, substitutions, new Set([name])).length > 0;
|
|
298
|
+
return resolves ? { kind: "generic container" } : null;
|
|
299
|
+
}
|
|
300
|
+
const substitutions = aliasSubstitution(alias, unwrapped, new Map());
|
|
301
|
+
if (substitutions === null)
|
|
302
|
+
return null;
|
|
303
|
+
const resolved = classifyAliasBroadTarget(alias.typeAnnotation, environment, substitutions, new Set([name]));
|
|
304
|
+
return resolved;
|
|
305
|
+
}
|
|
306
|
+
function isBroadMappedKey(type, environment, substitutions) {
|
|
307
|
+
const unwrapped = unwrapTransparentType(type);
|
|
308
|
+
if (unwrapped.type === "TSStringKeyword" ||
|
|
309
|
+
unwrapped.type === "TSNumberKeyword" ||
|
|
310
|
+
unwrapped.type === "TSSymbolKeyword") {
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
if (unwrapped.type === "TSUnionType") {
|
|
314
|
+
return unwrapped.types.every((member) => isBroadMappedKey(member, environment, substitutions));
|
|
315
|
+
}
|
|
316
|
+
if (unwrapped.type !== "TSTypeReference")
|
|
317
|
+
return false;
|
|
318
|
+
const name = typeReferenceName(unwrapped);
|
|
319
|
+
if (name === null)
|
|
320
|
+
return false;
|
|
321
|
+
const substitution = substitutions.get(name);
|
|
322
|
+
if (substitution !== undefined && !isUnappliedReferenceTo({ type: substitution, name })) {
|
|
323
|
+
return isBroadMappedKey(substitution, environment, substitutions);
|
|
324
|
+
}
|
|
325
|
+
return name === "PropertyKey" && isBuiltIn({ name, environment });
|
|
326
|
+
}
|
|
327
|
+
function classifyAliasBroadTarget(type, environment, substitutions, resolvingAliases) {
|
|
328
|
+
const unwrapped = unwrapTransparentType(type);
|
|
329
|
+
if (unwrapped.type === "TSUnknownKeyword")
|
|
330
|
+
return { kind: "unknown" };
|
|
331
|
+
if (unwrapped.type === "TSObjectKeyword")
|
|
332
|
+
return { kind: "object" };
|
|
333
|
+
if (unwrapped.type === "TSTypeLiteral") {
|
|
334
|
+
return unwrapped.members.some((member) => member.type === "TSIndexSignature")
|
|
335
|
+
? { kind: "open dictionary" }
|
|
336
|
+
: null;
|
|
337
|
+
}
|
|
338
|
+
if (unwrapped.type === "TSMappedType") {
|
|
339
|
+
return isBroadMappedKey(unwrapped.constraint, environment, substitutions)
|
|
340
|
+
? { kind: "open dictionary" }
|
|
341
|
+
: null;
|
|
342
|
+
}
|
|
343
|
+
if (unwrapped.type !== "TSTypeReference")
|
|
344
|
+
return null;
|
|
345
|
+
const name = typeReferenceName(unwrapped);
|
|
346
|
+
if (name === null)
|
|
347
|
+
return null;
|
|
348
|
+
const substitution = substitutions.get(name);
|
|
349
|
+
if (substitution !== undefined) {
|
|
350
|
+
return isUnappliedReferenceTo({ type: substitution, name })
|
|
351
|
+
? null
|
|
352
|
+
: classifyAliasBroadTarget(substitution, environment, substitutions, resolvingAliases);
|
|
353
|
+
}
|
|
354
|
+
if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn({ name, environment })) {
|
|
355
|
+
const wrapped = unwrapped.typeArguments?.params[0];
|
|
356
|
+
return wrapped === undefined
|
|
357
|
+
? null
|
|
358
|
+
: classifyAliasBroadTarget(wrapped, environment, substitutions, resolvingAliases);
|
|
359
|
+
}
|
|
360
|
+
if (name === "Record" && isBuiltIn({ name, environment })) {
|
|
361
|
+
return { kind: "open dictionary" };
|
|
362
|
+
}
|
|
363
|
+
const alias = environment.aliases.get(name);
|
|
364
|
+
if (alias === undefined || resolvingAliases.has(name))
|
|
365
|
+
return null;
|
|
366
|
+
const nextSubstitutions = aliasSubstitution(alias, unwrapped, substitutions);
|
|
367
|
+
if (nextSubstitutions === null)
|
|
368
|
+
return null;
|
|
369
|
+
const nextResolving = new Set(resolvingAliases);
|
|
370
|
+
nextResolving.add(name);
|
|
371
|
+
return classifyAliasBroadTarget(alias.typeAnnotation, environment, nextSubstitutions, nextResolving);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Whether an expression is an object literal carrying at least one property.
|
|
375
|
+
* @param {ESTree.Expression} expression - Candidate expression node.
|
|
376
|
+
* @returns {boolean} True only for ObjectExpression nodes with members.
|
|
377
|
+
*/
|
|
378
|
+
export function isPopulatedObjectExpression(expression) {
|
|
379
|
+
let current = expression;
|
|
380
|
+
while (current.type === "ParenthesizedExpression" ||
|
|
381
|
+
current.type === "TSAsExpression" ||
|
|
382
|
+
current.type === "TSTypeAssertion" ||
|
|
383
|
+
current.type === "TSNonNullExpression") {
|
|
384
|
+
current = current.expression;
|
|
385
|
+
}
|
|
386
|
+
return current.type === "ObjectExpression" && current.properties.length > 0;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Whether an expression carries first-hand type evidence (schema parse,
|
|
390
|
+
* literal, typed constructor) and therefore needs no further guarding.
|
|
391
|
+
* @param {ESTree.Expression} expression - Candidate expression node.
|
|
392
|
+
* @returns {boolean} True when the expression is self-evidencing.
|
|
393
|
+
*/
|
|
394
|
+
export function isKnownEvidenceExpression(expression) {
|
|
395
|
+
let current = expression;
|
|
396
|
+
while (current.type === "ParenthesizedExpression" ||
|
|
397
|
+
current.type === "TSAsExpression" ||
|
|
398
|
+
current.type === "TSTypeAssertion" ||
|
|
399
|
+
current.type === "TSNonNullExpression" ||
|
|
400
|
+
current.type === "TSSatisfiesExpression") {
|
|
401
|
+
current = current.expression;
|
|
402
|
+
}
|
|
403
|
+
if (current.type === "ObjectExpression")
|
|
404
|
+
return true;
|
|
405
|
+
return (current.type === "ArrayExpression" ||
|
|
406
|
+
current.type === "ArrowFunctionExpression" ||
|
|
407
|
+
current.type === "ClassExpression" ||
|
|
408
|
+
current.type === "FunctionExpression" ||
|
|
409
|
+
current.type === "NewExpression" ||
|
|
410
|
+
current.type === "Literal" ||
|
|
411
|
+
current.type === "TemplateLiteral" ||
|
|
412
|
+
current.type === "UnaryExpression");
|
|
413
|
+
}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import type { ESTree } from "@oxlint/plugins";
|
|
2
|
-
|
|
3
|
-
import { isRecordObject, type NodeFieldValue, readField, isString } from "./structural.ts";
|
|
4
|
-
|
|
2
|
+
import { type NodeFieldValue } from "./structural.ts";
|
|
5
3
|
/**
|
|
6
4
|
* Whether a reflected node-field value is an AST node (as opposed to a child
|
|
7
5
|
* array, literal, or absent).
|
|
8
6
|
* @param {NodeFieldValue} value - Value obtained from reading an ESTree node field.
|
|
9
7
|
* @returns {boolean} True when the value is a single AST node.
|
|
10
8
|
*/
|
|
11
|
-
export function isNode(value: NodeFieldValue): value is ESTree.Node
|
|
12
|
-
return isRecordObject(value) && isString(readField(value, "type"));
|
|
13
|
-
}
|
|
9
|
+
export declare function isNode(value: NodeFieldValue): value is ESTree.Node;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isRecordObject, readField, isString } from "./structural.js";
|
|
2
|
+
/**
|
|
3
|
+
* Whether a reflected node-field value is an AST node (as opposed to a child
|
|
4
|
+
* array, literal, or absent).
|
|
5
|
+
* @param {NodeFieldValue} value - Value obtained from reading an ESTree node field.
|
|
6
|
+
* @returns {boolean} True when the value is a single AST node.
|
|
7
|
+
*/
|
|
8
|
+
export function isNode(value) {
|
|
9
|
+
return isRecordObject(value) && isString(readField(value, "type"));
|
|
10
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ESTree } from "@oxlint/plugins";
|
|
2
|
+
type VisitorKeys = Readonly<Record<string, readonly string[]>>;
|
|
3
|
+
/**
|
|
4
|
+
* Collect type binders that are in scope at a node and can shadow module aliases.
|
|
5
|
+
*
|
|
6
|
+
* @param {ESTree.Node} node - The node whose lexical scope is being resolved.
|
|
7
|
+
* @param {ReadonlyArray<ESTree.Node>} ancestors - Nearest-first ancestor chain of `node`.
|
|
8
|
+
* @param {VisitorKeys} visitorKeys - Grammar keys used to descend conditional types.
|
|
9
|
+
* @returns {ReadonlySet<string>} Names of in-scope type binders.
|
|
10
|
+
*/
|
|
11
|
+
export declare function lexicalTypeParameterNames(node: ESTree.Node, ancestors: ReadonlyArray<ESTree.Node>, visitorKeys: VisitorKeys): ReadonlySet<string>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { isNode } from "./is-node.js";
|
|
2
|
+
import { readField } from "../shared/structural.js";
|
|
3
|
+
function collectInferTypeParameterNames(node, visitorKeys, names) {
|
|
4
|
+
if (node.type === "TSInferType")
|
|
5
|
+
names.add(node.typeParameter.name.name);
|
|
6
|
+
for (const key of visitorKeys[node.type] ?? []) {
|
|
7
|
+
const value = readField(node, key);
|
|
8
|
+
if (isNode(value)) {
|
|
9
|
+
collectInferTypeParameterNames(value, visitorKeys, names);
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
if (!Array.isArray(value))
|
|
13
|
+
continue;
|
|
14
|
+
for (const child of value) {
|
|
15
|
+
if (isNode(child))
|
|
16
|
+
collectInferTypeParameterNames(child, visitorKeys, names);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Collect type binders that are in scope at a node and can shadow module aliases.
|
|
22
|
+
*
|
|
23
|
+
* @param {ESTree.Node} node - The node whose lexical scope is being resolved.
|
|
24
|
+
* @param {ReadonlyArray<ESTree.Node>} ancestors - Nearest-first ancestor chain of `node`.
|
|
25
|
+
* @param {VisitorKeys} visitorKeys - Grammar keys used to descend conditional types.
|
|
26
|
+
* @returns {ReadonlySet<string>} Names of in-scope type binders.
|
|
27
|
+
*/
|
|
28
|
+
export function lexicalTypeParameterNames(node, ancestors, visitorKeys) {
|
|
29
|
+
const names = new Set();
|
|
30
|
+
const chain = [node, ...[...ancestors].reverse()];
|
|
31
|
+
for (let index = 1; index < chain.length; index += 1) {
|
|
32
|
+
const current = chain[index];
|
|
33
|
+
if (current.type === "Program")
|
|
34
|
+
break;
|
|
35
|
+
const descendant = chain[index - 1];
|
|
36
|
+
if ("typeParameters" in current) {
|
|
37
|
+
for (const parameter of current.typeParameters?.params ?? []) {
|
|
38
|
+
names.add(parameter.name.name);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (current.type === "TSMappedType" &&
|
|
42
|
+
(descendant === current.nameType || descendant === current.typeAnnotation)) {
|
|
43
|
+
names.add(current.key.name);
|
|
44
|
+
}
|
|
45
|
+
if (current.type === "TSConditionalType" && descendant === current.trueType) {
|
|
46
|
+
collectInferTypeParameterNames(current.extendsType, visitorKeys, names);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return names;
|
|
50
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ESTree, SourceCode } from "@oxlint/plugins";
|
|
2
|
+
interface ReflectMethodCallInput {
|
|
3
|
+
sourceCode: SourceCode;
|
|
4
|
+
callee: ESTree.Expression;
|
|
5
|
+
methodName: string;
|
|
6
|
+
}
|
|
7
|
+
/** Reports whether a call target names one method on the global Reflect object.
|
|
8
|
+
*
|
|
9
|
+
* @param {SourceCode} sourceCode - The rule's source-code accessor.
|
|
10
|
+
* @param {ESTree.Expression} callee - The callee expression of the call.
|
|
11
|
+
* @param {string} methodName - The Reflect method name to match.
|
|
12
|
+
* @returns {boolean} True when the call targets the global `Reflect`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function isGlobalReflectMethodCall({ sourceCode, callee, methodName, }: ReflectMethodCallInput): boolean;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** Reports whether a call target names one method on the global Reflect object.
|
|
2
|
+
*
|
|
3
|
+
* @param {SourceCode} sourceCode - The rule's source-code accessor.
|
|
4
|
+
* @param {ESTree.Expression} callee - The callee expression of the call.
|
|
5
|
+
* @param {string} methodName - The Reflect method name to match.
|
|
6
|
+
* @returns {boolean} True when the call targets the global `Reflect`.
|
|
7
|
+
*/
|
|
8
|
+
export function isGlobalReflectMethodCall({ sourceCode, callee, methodName, }) {
|
|
9
|
+
if (!("property" in callee) || !("object" in callee) || !("computed" in callee))
|
|
10
|
+
return false;
|
|
11
|
+
const object = callee.object;
|
|
12
|
+
if (object.type !== "Identifier" || object.name !== "Reflect")
|
|
13
|
+
return false;
|
|
14
|
+
if (!sourceCode.isGlobalReference(object)) {
|
|
15
|
+
let resolved = null;
|
|
16
|
+
let scope = sourceCode.getScope(object);
|
|
17
|
+
while (scope !== null) {
|
|
18
|
+
const variable = scope.set.get(object.name);
|
|
19
|
+
if (variable !== undefined) {
|
|
20
|
+
resolved = variable;
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
scope = scope.upper;
|
|
24
|
+
}
|
|
25
|
+
if (resolved !== null && resolved.defs.length > 0)
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
const property = callee.property;
|
|
29
|
+
return callee.computed
|
|
30
|
+
? property.type === "Literal" && property.value === methodName
|
|
31
|
+
: property.type === "Identifier" && property.name === methodName;
|
|
32
|
+
}
|
|
@@ -7,17 +7,12 @@
|
|
|
7
7
|
* representations directly.
|
|
8
8
|
*/
|
|
9
9
|
export interface OptionRecord {
|
|
10
|
-
|
|
10
|
+
readonly [key: string]: unknown;
|
|
11
11
|
}
|
|
12
|
-
|
|
13
12
|
/**
|
|
14
13
|
* Read the first options entry as an object record.
|
|
15
14
|
*
|
|
16
15
|
* @param {readonly unknown[] | undefined} options - The raw `context.options` array.
|
|
17
16
|
* @returns {OptionRecord} The first entry as a record, or an empty record when absent.
|
|
18
17
|
*/
|
|
19
|
-
export function firstOptionRecord(options: readonly unknown[] | undefined): OptionRecord
|
|
20
|
-
const first = options?.[0];
|
|
21
|
-
if (first === null || typeof first !== "object" || Array.isArray(first)) return {};
|
|
22
|
-
return first as Record<string, unknown>;
|
|
23
|
-
}
|
|
18
|
+
export declare function firstOptionRecord(options: readonly unknown[] | undefined): OptionRecord;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read the first options entry as an object record.
|
|
3
|
+
*
|
|
4
|
+
* @param {readonly unknown[] | undefined} options - The raw `context.options` array.
|
|
5
|
+
* @returns {OptionRecord} The first entry as a record, or an empty record when absent.
|
|
6
|
+
*/
|
|
7
|
+
export function firstOptionRecord(options) {
|
|
8
|
+
const first = options?.[0];
|
|
9
|
+
if (first === null || typeof first !== "object" || Array.isArray(first))
|
|
10
|
+
return {};
|
|
11
|
+
return first;
|
|
12
|
+
}
|