@rc312/oxlint-rules 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +43 -2
- package/dist/anti-slop/effect/index.d.ts +3 -0
- package/dist/anti-slop/effect/index.js +18 -0
- package/dist/anti-slop/effect/rules/no-manual-effect-error-tag.d.ts +1 -0
- package/dist/anti-slop/effect/rules/no-manual-effect-error-tag.js +39 -0
- package/dist/anti-slop/effect/rules/no-manual-tag-comparison.d.ts +1 -0
- package/dist/anti-slop/effect/rules/no-manual-tag-comparison.js +32 -0
- package/dist/anti-slop/effect/rules/no-manual-tagged-construction.d.ts +1 -0
- package/dist/anti-slop/effect/rules/no-manual-tagged-construction.js +27 -0
- package/dist/anti-slop/effect/rules/no-service-constructor-imports.d.ts +2 -0
- package/dist/anti-slop/effect/rules/no-service-constructor-imports.js +44 -0
- package/dist/anti-slop/effect/rules/prefer-effect-match.d.ts +1 -0
- package/dist/anti-slop/effect/rules/prefer-effect-match.js +48 -0
- package/dist/anti-slop/effect/shared/tagged-values.d.ts +8 -0
- package/dist/anti-slop/effect/shared/tagged-values.js +68 -0
- package/dist/anti-slop/index.d.ts +3 -0
- package/dist/anti-slop/index.js +44 -0
- package/dist/anti-slop/rules/no-array-filter-map.d.ts +2 -0
- package/dist/anti-slop/rules/no-array-filter-map.js +30 -0
- package/dist/anti-slop/rules/no-chained-type-assertions.d.ts +2 -0
- package/dist/anti-slop/rules/no-chained-type-assertions.js +60 -0
- package/dist/anti-slop/rules/no-conditional-empty-object-spread.d.ts +2 -0
- package/dist/anti-slop/rules/no-conditional-empty-object-spread.js +40 -0
- package/dist/anti-slop/rules/no-known-value-widening.d.ts +2 -0
- package/dist/anti-slop/rules/no-known-value-widening.js +300 -0
- package/dist/anti-slop/rules/no-module-mocking.d.ts +2 -0
- package/dist/anti-slop/rules/no-module-mocking.js +69 -0
- package/dist/anti-slop/rules/no-object-parameters.d.ts +2 -0
- package/dist/anti-slop/rules/no-object-parameters.js +56 -0
- package/dist/anti-slop/rules/no-reduce-accumulator-copy.d.ts +2 -0
- package/dist/anti-slop/rules/no-reduce-accumulator-copy.js +99 -0
- package/dist/anti-slop/rules/no-reflect-apply.d.ts +2 -0
- package/dist/anti-slop/rules/no-reflect-apply.js +25 -0
- package/dist/anti-slop/rules/no-reflect-get.d.ts +2 -0
- package/dist/anti-slop/rules/no-reflect-get.js +25 -0
- package/dist/anti-slop/rules/no-runtime-typeof.d.ts +2 -0
- package/dist/anti-slop/rules/no-runtime-typeof.js +64 -0
- package/dist/anti-slop/rules/no-shape-in-symbol-names.d.ts +2 -0
- package/dist/anti-slop/rules/no-shape-in-symbol-names.js +40 -0
- package/dist/anti-slop/rules/no-unknown-parameters.d.ts +2 -0
- package/dist/anti-slop/rules/no-unknown-parameters.js +51 -0
- package/dist/anti-slop/rules/no-unknown-returns.d.ts +2 -0
- package/dist/anti-slop/rules/no-unknown-returns.js +58 -0
- package/dist/anti-slop/rules/no-unknown-type-aliases.d.ts +2 -0
- package/dist/anti-slop/rules/no-unknown-type-aliases.js +40 -0
- package/dist/anti-slop/rules/no-unsafe-dictionary-type.d.ts +2 -0
- package/dist/anti-slop/rules/no-unsafe-dictionary-type.js +134 -0
- package/dist/anti-slop/rules/no-widen-then-assert.d.ts +2 -0
- package/dist/anti-slop/rules/no-widen-then-assert.js +270 -0
- package/dist/anti-slop/rules/require-readable-spacing.d.ts +3 -0
- package/dist/anti-slop/rules/require-readable-spacing.js +65 -0
- package/dist/anti-slop/rules/require-safety-comment-for-type-assertion.d.ts +2 -0
- package/dist/anti-slop/rules/require-safety-comment-for-type-assertion.js +100 -0
- package/dist/anti-slop/shared/array-method.d.ts +12 -0
- package/dist/anti-slop/shared/array-method.js +84 -0
- package/dist/anti-slop/shared/dictionary-types.d.ts +20 -0
- package/dist/anti-slop/shared/dictionary-types.js +377 -0
- package/dist/anti-slop/shared/function-parameters.d.ts +8 -0
- package/dist/anti-slop/shared/function-parameters.js +40 -0
- package/dist/anti-slop/shared/lexical-type-parameters.d.ts +5 -0
- package/dist/anti-slop/shared/lexical-type-parameters.js +47 -0
- package/dist/anti-slop/shared/reflect-method.d.ts +3 -0
- package/dist/anti-slop/shared/reflect-method.js +20 -0
- package/dist/anti-slop/shared/scope.d.ts +3 -0
- package/dist/anti-slop/shared/scope.js +11 -0
- package/dist/anti-slop/shared/type-alias-resolution.d.ts +23 -0
- package/dist/anti-slop/shared/type-alias-resolution.js +162 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-ast.d.ts +27 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-ast.js +28 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.d.ts +37 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-between-statements.js +703 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-options.d.ts +16 -0
- package/dist/anti-slop/vendor/eslint-stylistic/padding-line-options.js +2 -0
- package/dist/configs/base.d.ts +28 -0
- package/dist/configs/base.js +27 -0
- package/dist/configs/effect-starter.d.ts +10 -0
- package/dist/configs/effect-starter.js +10 -0
- package/dist/configs/effect.d.ts +14 -0
- package/dist/configs/effect.js +16 -0
- package/dist/effect-starter.d.ts +3 -0
- package/dist/effect-starter.js +40 -0
- package/package.json +46 -4
- package/src/anti-slop/LICENSE +21 -0
- package/src/anti-slop/UPSTREAM.md +14 -0
- package/src/anti-slop/vendor/eslint-stylistic/LICENSE +22 -0
- package/src/anti-slop/vendor/eslint-stylistic/UPSTREAM.md +28 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import createPaddingLineRule from "../vendor/eslint-stylistic/padding-line-between-statements.js";
|
|
2
|
+
/** A `const`/`let`/`var`/`using` declaration, optionally exported, written on one line. */
|
|
3
|
+
function isSinglelineBinding(node) {
|
|
4
|
+
const declaration = node.type === "ExportNamedDeclaration" ? node.declaration : node;
|
|
5
|
+
return declaration?.type === "VariableDeclaration" && node.loc.start.line === node.loc.end.line;
|
|
6
|
+
}
|
|
7
|
+
/** Comments above a statement belong to it; a comment trailing the previous line does not. */
|
|
8
|
+
function hasLeadingComment(node, sourceCode) {
|
|
9
|
+
const previousLine = sourceCode.getTokenBefore(node)?.loc.end.line;
|
|
10
|
+
return sourceCode
|
|
11
|
+
.getCommentsBefore(node)
|
|
12
|
+
.some((comment) => comment.loc.start.line !== previousLine);
|
|
13
|
+
}
|
|
14
|
+
const singlelineBinding = {
|
|
15
|
+
test: (node) => isSinglelineBinding(node),
|
|
16
|
+
};
|
|
17
|
+
const undocumentedSinglelineBinding = {
|
|
18
|
+
test: (node, sourceCode) => isSinglelineBinding(node) && !hasLeadingComment(node, sourceCode),
|
|
19
|
+
};
|
|
20
|
+
const paddingRule = createPaddingLineRule([
|
|
21
|
+
{ blankLine: "always", prev: "import", next: "*" },
|
|
22
|
+
{ blankLine: "always", prev: "*", next: { selector: "Program > :not(ImportDeclaration)" } },
|
|
23
|
+
{ blankLine: "always", prev: { selector: "Program > :not(ImportDeclaration)" }, next: "*" },
|
|
24
|
+
{ blankLine: "always", prev: "*", next: ["function", "class", "interface", "type"] },
|
|
25
|
+
{ blankLine: "always", prev: ["function", "class", "interface", "type"], next: "*" },
|
|
26
|
+
{
|
|
27
|
+
blankLine: "always",
|
|
28
|
+
prev: "*",
|
|
29
|
+
next: ["multiline-const", "multiline-let", "multiline-var", "multiline-using"],
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
blankLine: "always",
|
|
33
|
+
prev: ["multiline-const", "multiline-let", "multiline-var", "multiline-using"],
|
|
34
|
+
next: "*",
|
|
35
|
+
},
|
|
36
|
+
{ blankLine: "always", prev: "*", next: ["return", "if", "switch", "try", "for", "while", "do"] },
|
|
37
|
+
{ blankLine: "always", prev: "block-like", next: "*" },
|
|
38
|
+
{ blankLine: "any", prev: "import", next: "import" },
|
|
39
|
+
// Consecutive single-line bindings form one group at any scope, including
|
|
40
|
+
// module scope. A binding with its own leading comment starts a new group.
|
|
41
|
+
{ blankLine: "any", prev: "singleline-binding", next: "undocumented-singleline-binding" },
|
|
42
|
+
{
|
|
43
|
+
blankLine: "any",
|
|
44
|
+
prev: {
|
|
45
|
+
selector: ':matches(TSDeclareFunction, ExportNamedDeclaration[declaration.type="TSDeclareFunction"])',
|
|
46
|
+
},
|
|
47
|
+
next: {
|
|
48
|
+
selector: ':matches(TSDeclareFunction, FunctionDeclaration, ExportNamedDeclaration[declaration.type="TSDeclareFunction"], ExportNamedDeclaration[declaration.type="FunctionDeclaration"])',
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
], {
|
|
52
|
+
"singleline-binding": singlelineBinding,
|
|
53
|
+
"undocumented-singleline-binding": undocumentedSinglelineBinding,
|
|
54
|
+
});
|
|
55
|
+
/** Restore structural blank lines with whitespace-only fixes; keep single-line binding groups and overloads grouped. */
|
|
56
|
+
export const requireReadableSpacingRule = {
|
|
57
|
+
...paddingRule,
|
|
58
|
+
meta: {
|
|
59
|
+
...paddingRule.meta,
|
|
60
|
+
docs: {
|
|
61
|
+
description: "Require readable spacing between declarations and logical statement groups.",
|
|
62
|
+
},
|
|
63
|
+
schema: [],
|
|
64
|
+
},
|
|
65
|
+
};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { defineRule } from "@oxlint/plugins";
|
|
2
|
+
const DEFAULT_SAFETY_MARKERS = ["SAFETY"];
|
|
3
|
+
const commentOwnerKinds = new Set([
|
|
4
|
+
"ExpressionStatement",
|
|
5
|
+
"PropertyDefinition",
|
|
6
|
+
"ReturnStatement",
|
|
7
|
+
"ThrowStatement",
|
|
8
|
+
"VariableDeclaration",
|
|
9
|
+
]);
|
|
10
|
+
function isConstAssertion(node) {
|
|
11
|
+
return (node.typeAnnotation.type === "TSTypeReference" &&
|
|
12
|
+
node.typeAnnotation.typeName.type === "Identifier" &&
|
|
13
|
+
node.typeAnnotation.typeName.name === "const");
|
|
14
|
+
}
|
|
15
|
+
function configuredSafetyMarkers(option) {
|
|
16
|
+
if (typeof option !== "object" || option === null || !("markers" in option)) {
|
|
17
|
+
return DEFAULT_SAFETY_MARKERS;
|
|
18
|
+
}
|
|
19
|
+
const configured = option.markers;
|
|
20
|
+
if (!Array.isArray(configured))
|
|
21
|
+
return DEFAULT_SAFETY_MARKERS;
|
|
22
|
+
const markers = configured.flatMap((marker) => typeof marker === "string" && marker.trim().length > 0 ? [marker.trim()] : []);
|
|
23
|
+
return markers.length > 0 ? markers : DEFAULT_SAFETY_MARKERS;
|
|
24
|
+
}
|
|
25
|
+
function markerPattern(markers) {
|
|
26
|
+
const alternation = markers
|
|
27
|
+
.map((marker) => marker.replaceAll(/[.*+?^${}()|[\]\\]/gu, String.raw `\$&`))
|
|
28
|
+
.join("|");
|
|
29
|
+
return new RegExp(String.raw `(?:^|[^\p{L}\p{N}_])(?:${alternation})\s*:\s*\S`, "u");
|
|
30
|
+
}
|
|
31
|
+
function hasSafetyJustificationBefore(sourceCode, owner, assertion, pattern) {
|
|
32
|
+
return sourceCode
|
|
33
|
+
.getCommentsBefore(owner)
|
|
34
|
+
.some((comment) => comment.end <= assertion.start && pattern.test(comment.value));
|
|
35
|
+
}
|
|
36
|
+
function hasSafetyComment(sourceCode, node, pattern) {
|
|
37
|
+
let current = node;
|
|
38
|
+
while (true) {
|
|
39
|
+
if (hasSafetyJustificationBefore(sourceCode, current, node, pattern))
|
|
40
|
+
return true;
|
|
41
|
+
if (commentOwnerKinds.has(current.type)) {
|
|
42
|
+
const exportDeclaration = current.parent;
|
|
43
|
+
return (exportDeclaration.type === "ExportNamedDeclaration" &&
|
|
44
|
+
exportDeclaration.declaration === current &&
|
|
45
|
+
hasSafetyJustificationBefore(sourceCode, exportDeclaration, node, pattern));
|
|
46
|
+
}
|
|
47
|
+
if (current.parent.type === "Program")
|
|
48
|
+
return false;
|
|
49
|
+
current = current.parent;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Require every non-const type assertion to state the invariant TypeScript cannot express. */
|
|
53
|
+
export const requireSafetyCommentForTypeAssertionRule = defineRule({
|
|
54
|
+
meta: {
|
|
55
|
+
type: "problem",
|
|
56
|
+
docs: {
|
|
57
|
+
description: "Require a nearby SAFETY comment for every TypeScript type assertion except const assertions.",
|
|
58
|
+
},
|
|
59
|
+
messages: {
|
|
60
|
+
missingSafetyComment: "This type assertion has no `{{marker}}:` justification. State the checked invariant immediately before the assertion or its containing statement.",
|
|
61
|
+
},
|
|
62
|
+
schema: [
|
|
63
|
+
{
|
|
64
|
+
type: "object",
|
|
65
|
+
properties: {
|
|
66
|
+
markers: {
|
|
67
|
+
type: "array",
|
|
68
|
+
items: { type: "string", minLength: 1 },
|
|
69
|
+
minItems: 1,
|
|
70
|
+
uniqueItems: true,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
additionalProperties: false,
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
defaultOptions: [{ markers: ["SAFETY"] }],
|
|
77
|
+
},
|
|
78
|
+
createOnce(context) {
|
|
79
|
+
const patterns = new Map();
|
|
80
|
+
const checkAssertion = (node) => {
|
|
81
|
+
if (isConstAssertion(node))
|
|
82
|
+
return;
|
|
83
|
+
const markers = configuredSafetyMarkers(context.options?.[0]);
|
|
84
|
+
const patternKey = markers.join("\u0000");
|
|
85
|
+
const pattern = patterns.get(patternKey) ?? markerPattern(markers);
|
|
86
|
+
patterns.set(patternKey, pattern);
|
|
87
|
+
if (hasSafetyComment(context.sourceCode, node, pattern))
|
|
88
|
+
return;
|
|
89
|
+
context.report({
|
|
90
|
+
node,
|
|
91
|
+
messageId: "missingSafetyComment",
|
|
92
|
+
data: { marker: markers[0] ?? DEFAULT_SAFETY_MARKERS[0] },
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
return {
|
|
96
|
+
TSAsExpression: checkAssertion,
|
|
97
|
+
TSTypeAssertion: checkAssertion,
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ESTree, SourceCode, Variable } from "@oxlint/plugins";
|
|
2
|
+
/** Unwrap syntax-only wrappers when inspecting array methods and accumulator references. */
|
|
3
|
+
export declare function unwrapArrayExpression(node: ESTree.Node): ESTree.Node;
|
|
4
|
+
/** Resolve a local binding by scope, not by identifier spelling. */
|
|
5
|
+
export declare function resolveArrayBinding(sourceCode: SourceCode, node: ESTree.Node): Variable | null;
|
|
6
|
+
/** Read static method names, including computed string literals, without evaluating expressions. */
|
|
7
|
+
export declare function arrayMethodTarget(node: ESTree.Node): {
|
|
8
|
+
readonly name: string;
|
|
9
|
+
readonly object: ESTree.Node;
|
|
10
|
+
} | null;
|
|
11
|
+
/** Recognize local array evidence; unknown receivers and iterator pipelines are deliberately excluded. */
|
|
12
|
+
export declare function isKnownArrayExpression(sourceCode: SourceCode, node: ESTree.Node, visited?: Set<Variable>): boolean;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/** Unwrap syntax-only wrappers when inspecting array methods and accumulator references. */
|
|
2
|
+
export function unwrapArrayExpression(node) {
|
|
3
|
+
while (node.type === "ParenthesizedExpression" ||
|
|
4
|
+
node.type === "ChainExpression" ||
|
|
5
|
+
node.type === "TSAsExpression" ||
|
|
6
|
+
node.type === "TSTypeAssertion" ||
|
|
7
|
+
node.type === "TSNonNullExpression" ||
|
|
8
|
+
node.type === "TSSatisfiesExpression") {
|
|
9
|
+
node = node.expression;
|
|
10
|
+
}
|
|
11
|
+
return node;
|
|
12
|
+
}
|
|
13
|
+
/** Resolve a local binding by scope, not by identifier spelling. */
|
|
14
|
+
export function resolveArrayBinding(sourceCode, node) {
|
|
15
|
+
node = unwrapArrayExpression(node);
|
|
16
|
+
if (node.type !== "Identifier")
|
|
17
|
+
return null;
|
|
18
|
+
let scope = sourceCode.getScope(node);
|
|
19
|
+
while (scope !== null) {
|
|
20
|
+
const variable = scope.set.get(node.name);
|
|
21
|
+
if (variable !== undefined)
|
|
22
|
+
return variable;
|
|
23
|
+
scope = scope.upper;
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
/** Read static method names, including computed string literals, without evaluating expressions. */
|
|
28
|
+
export function arrayMethodTarget(node) {
|
|
29
|
+
node = unwrapArrayExpression(node);
|
|
30
|
+
if (node.type !== "MemberExpression")
|
|
31
|
+
return null;
|
|
32
|
+
const property = node.property;
|
|
33
|
+
if (!node.computed && property.type === "Identifier") {
|
|
34
|
+
return { name: property.name, object: node.object };
|
|
35
|
+
}
|
|
36
|
+
if (node.computed && property.type === "Literal" && typeof property.value === "string") {
|
|
37
|
+
return { name: property.value, object: node.object };
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
function isArrayAnnotation(type) {
|
|
42
|
+
if (type.type === "TSArrayType" || type.type === "TSTupleType")
|
|
43
|
+
return true;
|
|
44
|
+
if (type.type === "TSParenthesizedType")
|
|
45
|
+
return isArrayAnnotation(type.typeAnnotation);
|
|
46
|
+
if (type.type === "TSTypeOperator" && type.operator === "readonly") {
|
|
47
|
+
return isArrayAnnotation(type.typeAnnotation);
|
|
48
|
+
}
|
|
49
|
+
return (type.type === "TSTypeReference" && type.typeName.type === "Identifier" &&
|
|
50
|
+
(type.typeName.name === "Array" || type.typeName.name === "ReadonlyArray"));
|
|
51
|
+
}
|
|
52
|
+
/** Recognize local array evidence; unknown receivers and iterator pipelines are deliberately excluded. */
|
|
53
|
+
export function isKnownArrayExpression(sourceCode, node, visited = new Set()) {
|
|
54
|
+
node = unwrapArrayExpression(node);
|
|
55
|
+
if (node.type === "ArrayExpression")
|
|
56
|
+
return true;
|
|
57
|
+
if (node.type === "CallExpression") {
|
|
58
|
+
const method = arrayMethodTarget(node.callee);
|
|
59
|
+
return (method !== null &&
|
|
60
|
+
["map", "filter", "flatMap", "slice", "concat", "toSorted", "toReversed", "toSpliced"].includes(method.name) &&
|
|
61
|
+
isKnownArrayExpression(sourceCode, method.object, visited));
|
|
62
|
+
}
|
|
63
|
+
if (node.type !== "Identifier")
|
|
64
|
+
return false;
|
|
65
|
+
const variable = resolveArrayBinding(sourceCode, node);
|
|
66
|
+
if (variable === null || visited.has(variable))
|
|
67
|
+
return false;
|
|
68
|
+
visited.add(variable);
|
|
69
|
+
if (variable.references.some(reference => reference.isWrite() && !reference.init))
|
|
70
|
+
return false;
|
|
71
|
+
for (const identifier of variable.identifiers) {
|
|
72
|
+
const annotation = identifier.typeAnnotation?.typeAnnotation;
|
|
73
|
+
if (annotation !== undefined)
|
|
74
|
+
return isArrayAnnotation(annotation);
|
|
75
|
+
}
|
|
76
|
+
for (const definition of variable.defs) {
|
|
77
|
+
if (definition.type === "Variable" && definition.node.type === "VariableDeclarator" &&
|
|
78
|
+
definition.node.id.type === "Identifier" && definition.node.init !== null &&
|
|
79
|
+
definition.node.parent.type === "VariableDeclaration" && definition.node.parent.kind === "const") {
|
|
80
|
+
return isKnownArrayExpression(sourceCode, definition.node.init, visited);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ESTree } from "@oxlint/plugins";
|
|
2
|
+
import { type TypeAliasEnvironment as LexicalTypeAliasEnvironment } from "./type-alias-resolution.ts";
|
|
3
|
+
export type UnsafeDictionary = {
|
|
4
|
+
readonly kind: "unsafe-dictionary";
|
|
5
|
+
readonly unsafeValue: "any" | "empty-object" | "object" | "union" | "unknown";
|
|
6
|
+
};
|
|
7
|
+
export type WideningTargetKind = "anonymous object" | "generic container" | "object" | "open dictionary" | "unknown";
|
|
8
|
+
export type WideningTarget = {
|
|
9
|
+
readonly kind: WideningTargetKind;
|
|
10
|
+
};
|
|
11
|
+
export type TypeEnvironment = {
|
|
12
|
+
readonly interfaces: ReadonlyMap<string, readonly ESTree.TSInterfaceDeclaration[]>;
|
|
13
|
+
readonly typeAliases: LexicalTypeAliasEnvironment;
|
|
14
|
+
};
|
|
15
|
+
export declare function createTypeEnvironment(program: ESTree.Program, visitorKeys: Readonly<Record<string, readonly string[]>>): TypeEnvironment;
|
|
16
|
+
export declare function classifyUnsafeDictionaryValue(valueType: ESTree.TSType, environment: TypeEnvironment): UnsafeDictionary | null;
|
|
17
|
+
export declare function classifyUnsafeDictionary(type: ESTree.TSType, environment: TypeEnvironment): UnsafeDictionary | null;
|
|
18
|
+
export declare function classifyWideningTarget(type: ESTree.TSType, environment: TypeEnvironment): WideningTarget | null;
|
|
19
|
+
export declare function isPopulatedObjectExpression(expression: ESTree.Expression): boolean;
|
|
20
|
+
export declare function isKnownEvidenceExpression(expression: ESTree.Expression): boolean;
|
|
@@ -0,0 +1,377 @@
|
|
|
1
|
+
import { createTypeAliasEnvironment, hasVisibleTypeBinding, visibleTypeAlias, } from "./type-alias-resolution.js";
|
|
2
|
+
const BUILT_INS = new Set([
|
|
3
|
+
"Record",
|
|
4
|
+
"Readonly",
|
|
5
|
+
"Partial",
|
|
6
|
+
"Required",
|
|
7
|
+
"Pick",
|
|
8
|
+
"Omit",
|
|
9
|
+
"PropertyKey",
|
|
10
|
+
"NonNullable",
|
|
11
|
+
]);
|
|
12
|
+
const TRANSPARENT_WRAPPERS = new Set(["Readonly", "Partial", "Required", "NonNullable"]);
|
|
13
|
+
function declaredStatement(statement) {
|
|
14
|
+
return statement.type === "ExportNamedDeclaration" ||
|
|
15
|
+
statement.type === "ExportDefaultDeclaration"
|
|
16
|
+
? (statement.declaration ?? null)
|
|
17
|
+
: statement;
|
|
18
|
+
}
|
|
19
|
+
export function createTypeEnvironment(program, visitorKeys) {
|
|
20
|
+
const interfaces = new Map();
|
|
21
|
+
for (const statement of program.body) {
|
|
22
|
+
const declaration = declaredStatement(statement);
|
|
23
|
+
if (declaration?.type !== "TSInterfaceDeclaration")
|
|
24
|
+
continue;
|
|
25
|
+
const declarations = interfaces.get(declaration.id.name) ?? [];
|
|
26
|
+
declarations.push(declaration);
|
|
27
|
+
interfaces.set(declaration.id.name, declarations);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
interfaces,
|
|
31
|
+
typeAliases: createTypeAliasEnvironment(program, visitorKeys),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function typeReferenceName(type) {
|
|
35
|
+
return type.typeName.type === "Identifier" ? type.typeName.name : null;
|
|
36
|
+
}
|
|
37
|
+
function isBuiltIn(name, use, environment) {
|
|
38
|
+
return (BUILT_INS.has(name) &&
|
|
39
|
+
!hasVisibleTypeBinding(name, use, environment.typeAliases));
|
|
40
|
+
}
|
|
41
|
+
function isUnappliedReferenceTo(type, name) {
|
|
42
|
+
const unwrapped = unwrapTransparentType(type);
|
|
43
|
+
return (unwrapped.type === "TSTypeReference" &&
|
|
44
|
+
typeReferenceName(unwrapped) === name &&
|
|
45
|
+
(unwrapped.typeArguments === null ||
|
|
46
|
+
unwrapped.typeArguments === undefined ||
|
|
47
|
+
unwrapped.typeArguments.params.length === 0));
|
|
48
|
+
}
|
|
49
|
+
function unwrapTransparentType(type) {
|
|
50
|
+
let current = type;
|
|
51
|
+
while (current.type === "TSParenthesizedType" ||
|
|
52
|
+
(current.type === "TSTypeOperator" && current.operator === "readonly")) {
|
|
53
|
+
current = current.typeAnnotation;
|
|
54
|
+
}
|
|
55
|
+
return current;
|
|
56
|
+
}
|
|
57
|
+
function isNeverType(type) {
|
|
58
|
+
return unwrapTransparentType(type).type === "TSNeverKeyword";
|
|
59
|
+
}
|
|
60
|
+
function isEffectivelyEmptyMember(member) {
|
|
61
|
+
return (member.type === "TSPropertySignature" &&
|
|
62
|
+
member.optional === true &&
|
|
63
|
+
member.typeAnnotation !== null &&
|
|
64
|
+
member.typeAnnotation !== undefined &&
|
|
65
|
+
isNeverType(member.typeAnnotation.typeAnnotation));
|
|
66
|
+
}
|
|
67
|
+
function isEffectivelyEmptyTypeLiteral(type) {
|
|
68
|
+
return type.members.length === 0 || type.members.every(isEffectivelyEmptyMember);
|
|
69
|
+
}
|
|
70
|
+
function isEffectivelyEmptyInterface(declarations) {
|
|
71
|
+
if (declarations.length !== 1)
|
|
72
|
+
return false;
|
|
73
|
+
const [type] = declarations;
|
|
74
|
+
return (type !== undefined &&
|
|
75
|
+
type.extends.length === 0 &&
|
|
76
|
+
(type.body.body.length === 0 || type.body.body.every(isEffectivelyEmptyMember)));
|
|
77
|
+
}
|
|
78
|
+
function resolvedSubstitutionArgument(type, base, resolving = new Set()) {
|
|
79
|
+
const unwrapped = unwrapTransparentType(type);
|
|
80
|
+
if (unwrapped.type !== "TSTypeReference")
|
|
81
|
+
return type;
|
|
82
|
+
const name = typeReferenceName(unwrapped);
|
|
83
|
+
if (name === null || resolving.has(name))
|
|
84
|
+
return type;
|
|
85
|
+
const substitution = base.get(name);
|
|
86
|
+
if (substitution === undefined)
|
|
87
|
+
return type;
|
|
88
|
+
const nextResolving = new Set(resolving);
|
|
89
|
+
nextResolving.add(name);
|
|
90
|
+
return resolvedSubstitutionArgument(substitution, base, nextResolving);
|
|
91
|
+
}
|
|
92
|
+
function aliasSubstitution(alias, type, base) {
|
|
93
|
+
const parameters = alias.typeParameters?.params ?? [];
|
|
94
|
+
const arguments_ = type.typeArguments?.params ?? [];
|
|
95
|
+
const next = new Map(base);
|
|
96
|
+
for (const [index, parameter] of parameters.entries()) {
|
|
97
|
+
const argument = arguments_[index] ?? parameter.default;
|
|
98
|
+
if (argument === null || argument === undefined)
|
|
99
|
+
return null;
|
|
100
|
+
next.set(parameter.name.name, resolvedSubstitutionArgument(argument, next));
|
|
101
|
+
}
|
|
102
|
+
return next;
|
|
103
|
+
}
|
|
104
|
+
function unsafeDirectValue(type, environment, substitutions, resolvingAliases) {
|
|
105
|
+
const unwrapped = unwrapTransparentType(type);
|
|
106
|
+
if (unwrapped.type === "TSUnknownKeyword")
|
|
107
|
+
return "unknown";
|
|
108
|
+
if (unwrapped.type === "TSAnyKeyword")
|
|
109
|
+
return "any";
|
|
110
|
+
if (unwrapped.type === "TSObjectKeyword")
|
|
111
|
+
return "object";
|
|
112
|
+
if (unwrapped.type === "TSTypeLiteral" && isEffectivelyEmptyTypeLiteral(unwrapped))
|
|
113
|
+
return "empty-object";
|
|
114
|
+
if (unwrapped.type === "TSUnionType") {
|
|
115
|
+
return unwrapped.types.some((member) => unsafeDirectValue(member, environment, substitutions, resolvingAliases) !== null)
|
|
116
|
+
? "union"
|
|
117
|
+
: null;
|
|
118
|
+
}
|
|
119
|
+
if (unwrapped.type === "TSIntersectionType") {
|
|
120
|
+
const unsafeMembers = unwrapped.types.map((member) => unsafeDirectValue(member, environment, substitutions, resolvingAliases));
|
|
121
|
+
if (unsafeMembers.includes("any"))
|
|
122
|
+
return "any";
|
|
123
|
+
return unsafeMembers.length > 0 && unsafeMembers.every((member) => member !== null)
|
|
124
|
+
? unsafeMembers[0]
|
|
125
|
+
: null;
|
|
126
|
+
}
|
|
127
|
+
if (unwrapped.type !== "TSTypeReference")
|
|
128
|
+
return null;
|
|
129
|
+
const name = typeReferenceName(unwrapped);
|
|
130
|
+
if (name === null)
|
|
131
|
+
return null;
|
|
132
|
+
if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn(name, unwrapped, environment)) {
|
|
133
|
+
const wrapped = unwrapped.typeArguments?.params[0];
|
|
134
|
+
return wrapped === undefined
|
|
135
|
+
? null
|
|
136
|
+
: unsafeDirectValue(wrapped, environment, substitutions, resolvingAliases);
|
|
137
|
+
}
|
|
138
|
+
const substitution = substitutions.get(name);
|
|
139
|
+
if (substitution !== undefined) {
|
|
140
|
+
return isUnappliedReferenceTo(substitution, name)
|
|
141
|
+
? null
|
|
142
|
+
: unsafeDirectValue(substitution, environment, substitutions, resolvingAliases);
|
|
143
|
+
}
|
|
144
|
+
const interfaceDeclarations = environment.interfaces.get(name);
|
|
145
|
+
if (interfaceDeclarations !== undefined) {
|
|
146
|
+
return isEffectivelyEmptyInterface(interfaceDeclarations) ? "empty-object" : null;
|
|
147
|
+
}
|
|
148
|
+
const alias = visibleTypeAlias(name, unwrapped, environment.typeAliases);
|
|
149
|
+
if (alias === null || resolvingAliases.has(name))
|
|
150
|
+
return null;
|
|
151
|
+
const nextSubstitutions = aliasSubstitution(alias, unwrapped, substitutions);
|
|
152
|
+
if (nextSubstitutions === null)
|
|
153
|
+
return null;
|
|
154
|
+
const nextResolving = new Set(resolvingAliases);
|
|
155
|
+
nextResolving.add(name);
|
|
156
|
+
return unsafeDirectValue(alias.typeAnnotation, environment, nextSubstitutions, nextResolving);
|
|
157
|
+
}
|
|
158
|
+
function dictionaryValueTypes(type, environment, substitutions, resolvingAliases) {
|
|
159
|
+
const unwrapped = unwrapTransparentType(type);
|
|
160
|
+
if (unwrapped.type === "TSTypeLiteral") {
|
|
161
|
+
return unwrapped.members.flatMap((member) => member.type === "TSIndexSignature" && member.typeAnnotation !== null
|
|
162
|
+
? [{ type: member.typeAnnotation.typeAnnotation, substitutions }]
|
|
163
|
+
: []);
|
|
164
|
+
}
|
|
165
|
+
if (unwrapped.type === "TSMappedType") {
|
|
166
|
+
return unwrapped.typeAnnotation === null
|
|
167
|
+
? []
|
|
168
|
+
: [{ type: unwrapped.typeAnnotation, substitutions }];
|
|
169
|
+
}
|
|
170
|
+
if (unwrapped.type !== "TSTypeReference")
|
|
171
|
+
return [];
|
|
172
|
+
const name = typeReferenceName(unwrapped);
|
|
173
|
+
if (name === null)
|
|
174
|
+
return [];
|
|
175
|
+
const substitution = substitutions.get(name);
|
|
176
|
+
if (substitution !== undefined) {
|
|
177
|
+
return isUnappliedReferenceTo(substitution, name)
|
|
178
|
+
? []
|
|
179
|
+
: dictionaryValueTypes(substitution, environment, substitutions, resolvingAliases);
|
|
180
|
+
}
|
|
181
|
+
if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn(name, unwrapped, environment)) {
|
|
182
|
+
const wrapped = unwrapped.typeArguments?.params[0];
|
|
183
|
+
return wrapped === undefined
|
|
184
|
+
? []
|
|
185
|
+
: dictionaryValueTypes(wrapped, environment, substitutions, resolvingAliases);
|
|
186
|
+
}
|
|
187
|
+
if (name === "Record" && isBuiltIn(name, unwrapped, environment)) {
|
|
188
|
+
const value = unwrapped.typeArguments?.params[1] ?? null;
|
|
189
|
+
return value === null ? [] : [{ type: value, substitutions }];
|
|
190
|
+
}
|
|
191
|
+
if ((name === "Pick" || name === "Omit") &&
|
|
192
|
+
isBuiltIn(name, unwrapped, environment)) {
|
|
193
|
+
const source = unwrapped.typeArguments?.params[0];
|
|
194
|
+
return source === undefined
|
|
195
|
+
? []
|
|
196
|
+
: dictionaryValueTypes(source, environment, substitutions, resolvingAliases);
|
|
197
|
+
}
|
|
198
|
+
const alias = visibleTypeAlias(name, unwrapped, environment.typeAliases);
|
|
199
|
+
if (alias === null || resolvingAliases.has(name))
|
|
200
|
+
return [];
|
|
201
|
+
const nextSubstitutions = aliasSubstitution(alias, unwrapped, substitutions);
|
|
202
|
+
if (nextSubstitutions === null)
|
|
203
|
+
return [];
|
|
204
|
+
const nextResolving = new Set(resolvingAliases);
|
|
205
|
+
nextResolving.add(name);
|
|
206
|
+
return dictionaryValueTypes(alias.typeAnnotation, environment, nextSubstitutions, nextResolving);
|
|
207
|
+
}
|
|
208
|
+
export function classifyUnsafeDictionaryValue(valueType, environment) {
|
|
209
|
+
const unsafeValue = unsafeDirectValue(valueType, environment, new Map(), new Set());
|
|
210
|
+
return unsafeValue === null ? null : { kind: "unsafe-dictionary", unsafeValue };
|
|
211
|
+
}
|
|
212
|
+
export function classifyUnsafeDictionary(type, environment) {
|
|
213
|
+
for (const valueType of dictionaryValueTypes(type, environment, new Map(), new Set())) {
|
|
214
|
+
const unsafeValue = unsafeDirectValue(valueType.type, environment, valueType.substitutions, new Set());
|
|
215
|
+
if (unsafeValue !== null)
|
|
216
|
+
return { kind: "unsafe-dictionary", unsafeValue };
|
|
217
|
+
}
|
|
218
|
+
return null;
|
|
219
|
+
}
|
|
220
|
+
export function classifyWideningTarget(type, environment) {
|
|
221
|
+
const unwrapped = unwrapTransparentType(type);
|
|
222
|
+
if (unwrapped.type === "TSUnknownKeyword")
|
|
223
|
+
return { kind: "unknown" };
|
|
224
|
+
if (unwrapped.type === "TSObjectKeyword")
|
|
225
|
+
return { kind: "object" };
|
|
226
|
+
if (unwrapped.type === "TSTypeLiteral") {
|
|
227
|
+
return unwrapped.members.some((member) => member.type === "TSIndexSignature")
|
|
228
|
+
? { kind: "open dictionary" }
|
|
229
|
+
: unwrapped.members.length > 0
|
|
230
|
+
? { kind: "anonymous object" }
|
|
231
|
+
: null;
|
|
232
|
+
}
|
|
233
|
+
if (unwrapped.type === "TSMappedType")
|
|
234
|
+
return { kind: "open dictionary" };
|
|
235
|
+
if (unwrapped.type !== "TSTypeReference")
|
|
236
|
+
return null;
|
|
237
|
+
const name = typeReferenceName(unwrapped);
|
|
238
|
+
if (name === null)
|
|
239
|
+
return null;
|
|
240
|
+
if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn(name, unwrapped, environment)) {
|
|
241
|
+
const wrapped = unwrapped.typeArguments?.params[0];
|
|
242
|
+
return wrapped === undefined ? null : classifyWideningTarget(wrapped, environment);
|
|
243
|
+
}
|
|
244
|
+
if (name === "Record" && isBuiltIn(name, unwrapped, environment)) {
|
|
245
|
+
return hasBroadRecordKey(unwrapped, environment, new Map())
|
|
246
|
+
? { kind: "open dictionary" }
|
|
247
|
+
: null;
|
|
248
|
+
}
|
|
249
|
+
const alias = visibleTypeAlias(name, unwrapped, environment.typeAliases);
|
|
250
|
+
if (alias === null)
|
|
251
|
+
return null;
|
|
252
|
+
if ((alias.typeParameters?.params.length ?? 0) > 0) {
|
|
253
|
+
const substitutions = aliasSubstitution(alias, unwrapped, new Map());
|
|
254
|
+
const resolved = substitutions === null
|
|
255
|
+
? null
|
|
256
|
+
: classifyAliasBroadTarget(alias.typeAnnotation, environment, substitutions, new Set([name]));
|
|
257
|
+
return resolved?.kind === "open dictionary" ? { kind: "generic container" } : null;
|
|
258
|
+
}
|
|
259
|
+
const substitutions = aliasSubstitution(alias, unwrapped, new Map());
|
|
260
|
+
if (substitutions === null)
|
|
261
|
+
return null;
|
|
262
|
+
const resolved = classifyAliasBroadTarget(alias.typeAnnotation, environment, substitutions, new Set([name]));
|
|
263
|
+
return resolved;
|
|
264
|
+
}
|
|
265
|
+
function hasBroadRecordKey(type, environment, substitutions) {
|
|
266
|
+
const key = type.typeArguments?.params[0];
|
|
267
|
+
return key === undefined || isBroadMappedKey(key, environment, substitutions);
|
|
268
|
+
}
|
|
269
|
+
function isBroadMappedKey(type, environment, substitutions, visitedAliases = new Set()) {
|
|
270
|
+
const unwrapped = unwrapTransparentType(type);
|
|
271
|
+
if (unwrapped.type === "TSStringKeyword" ||
|
|
272
|
+
unwrapped.type === "TSNumberKeyword" ||
|
|
273
|
+
unwrapped.type === "TSSymbolKeyword") {
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
if (unwrapped.type === "TSUnionType") {
|
|
277
|
+
return unwrapped.types.some((member) => isBroadMappedKey(member, environment, substitutions, visitedAliases));
|
|
278
|
+
}
|
|
279
|
+
if (unwrapped.type !== "TSTypeReference")
|
|
280
|
+
return false;
|
|
281
|
+
const name = typeReferenceName(unwrapped);
|
|
282
|
+
if (name === null)
|
|
283
|
+
return false;
|
|
284
|
+
const substitution = substitutions.get(name);
|
|
285
|
+
if (substitution !== undefined && !isUnappliedReferenceTo(substitution, name)) {
|
|
286
|
+
return isBroadMappedKey(substitution, environment, substitutions, visitedAliases);
|
|
287
|
+
}
|
|
288
|
+
if (name === "PropertyKey" && isBuiltIn(name, unwrapped, environment))
|
|
289
|
+
return true;
|
|
290
|
+
const alias = visibleTypeAlias(name, unwrapped, environment.typeAliases);
|
|
291
|
+
if (alias === null ||
|
|
292
|
+
(alias.typeParameters?.params.length ?? 0) > 0 ||
|
|
293
|
+
visitedAliases.has(name)) {
|
|
294
|
+
return false;
|
|
295
|
+
}
|
|
296
|
+
const nextVisited = new Set(visitedAliases);
|
|
297
|
+
nextVisited.add(name);
|
|
298
|
+
return isBroadMappedKey(alias.typeAnnotation, environment, substitutions, nextVisited);
|
|
299
|
+
}
|
|
300
|
+
function classifyAliasBroadTarget(type, environment, substitutions, resolvingAliases) {
|
|
301
|
+
const unwrapped = unwrapTransparentType(type);
|
|
302
|
+
if (unwrapped.type === "TSUnknownKeyword")
|
|
303
|
+
return { kind: "unknown" };
|
|
304
|
+
if (unwrapped.type === "TSObjectKeyword")
|
|
305
|
+
return { kind: "object" };
|
|
306
|
+
if (unwrapped.type === "TSTypeLiteral") {
|
|
307
|
+
return unwrapped.members.some((member) => member.type === "TSIndexSignature")
|
|
308
|
+
? { kind: "open dictionary" }
|
|
309
|
+
: null;
|
|
310
|
+
}
|
|
311
|
+
if (unwrapped.type === "TSMappedType") {
|
|
312
|
+
return isBroadMappedKey(unwrapped.constraint, environment, substitutions)
|
|
313
|
+
? { kind: "open dictionary" }
|
|
314
|
+
: null;
|
|
315
|
+
}
|
|
316
|
+
if (unwrapped.type !== "TSTypeReference")
|
|
317
|
+
return null;
|
|
318
|
+
const name = typeReferenceName(unwrapped);
|
|
319
|
+
if (name === null)
|
|
320
|
+
return null;
|
|
321
|
+
const substitution = substitutions.get(name);
|
|
322
|
+
if (substitution !== undefined) {
|
|
323
|
+
return isUnappliedReferenceTo(substitution, name)
|
|
324
|
+
? null
|
|
325
|
+
: classifyAliasBroadTarget(substitution, environment, substitutions, resolvingAliases);
|
|
326
|
+
}
|
|
327
|
+
if (TRANSPARENT_WRAPPERS.has(name) && isBuiltIn(name, unwrapped, environment)) {
|
|
328
|
+
const wrapped = unwrapped.typeArguments?.params[0];
|
|
329
|
+
return wrapped === undefined
|
|
330
|
+
? null
|
|
331
|
+
: classifyAliasBroadTarget(wrapped, environment, substitutions, resolvingAliases);
|
|
332
|
+
}
|
|
333
|
+
if (name === "Record" && isBuiltIn(name, unwrapped, environment)) {
|
|
334
|
+
return hasBroadRecordKey(unwrapped, environment, substitutions)
|
|
335
|
+
? { kind: "open dictionary" }
|
|
336
|
+
: null;
|
|
337
|
+
}
|
|
338
|
+
const alias = visibleTypeAlias(name, unwrapped, environment.typeAliases);
|
|
339
|
+
if (alias === null || resolvingAliases.has(name))
|
|
340
|
+
return null;
|
|
341
|
+
const nextSubstitutions = aliasSubstitution(alias, unwrapped, substitutions);
|
|
342
|
+
if (nextSubstitutions === null)
|
|
343
|
+
return null;
|
|
344
|
+
const nextResolving = new Set(resolvingAliases);
|
|
345
|
+
nextResolving.add(name);
|
|
346
|
+
return classifyAliasBroadTarget(alias.typeAnnotation, environment, nextSubstitutions, nextResolving);
|
|
347
|
+
}
|
|
348
|
+
export function isPopulatedObjectExpression(expression) {
|
|
349
|
+
let current = expression;
|
|
350
|
+
while (current.type === "ParenthesizedExpression" ||
|
|
351
|
+
current.type === "TSAsExpression" ||
|
|
352
|
+
current.type === "TSTypeAssertion" ||
|
|
353
|
+
current.type === "TSNonNullExpression") {
|
|
354
|
+
current = current.expression;
|
|
355
|
+
}
|
|
356
|
+
return current.type === "ObjectExpression" && current.properties.length > 0;
|
|
357
|
+
}
|
|
358
|
+
export function isKnownEvidenceExpression(expression) {
|
|
359
|
+
let current = expression;
|
|
360
|
+
while (current.type === "ParenthesizedExpression" ||
|
|
361
|
+
current.type === "TSAsExpression" ||
|
|
362
|
+
current.type === "TSTypeAssertion" ||
|
|
363
|
+
current.type === "TSNonNullExpression" ||
|
|
364
|
+
current.type === "TSSatisfiesExpression") {
|
|
365
|
+
current = current.expression;
|
|
366
|
+
}
|
|
367
|
+
if (current.type === "ObjectExpression")
|
|
368
|
+
return true;
|
|
369
|
+
return (current.type === "ArrayExpression" ||
|
|
370
|
+
current.type === "ArrowFunctionExpression" ||
|
|
371
|
+
current.type === "ClassExpression" ||
|
|
372
|
+
current.type === "FunctionExpression" ||
|
|
373
|
+
current.type === "NewExpression" ||
|
|
374
|
+
current.type === "Literal" ||
|
|
375
|
+
current.type === "TemplateLiteral" ||
|
|
376
|
+
current.type === "UnaryExpression");
|
|
377
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ESTree, SourceCode } from "@oxlint/plugins";
|
|
2
|
+
export type FunctionParameter = ESTree.ParamPattern;
|
|
3
|
+
/** Return whether a type is or contains TypeScript's absorbing unknown top type. */
|
|
4
|
+
export declare function containsUnknownType(type: ESTree.TSType): boolean;
|
|
5
|
+
/** Return the TypeScript annotation attached to a function parameter or its wrapped binding. */
|
|
6
|
+
export declare function functionParameterTypeAnnotation(parameter: FunctionParameter): ESTree.TSTypeAnnotation | null | undefined;
|
|
7
|
+
/** Return only a function parameter's local binding, excluding its annotation and default value. */
|
|
8
|
+
export declare function functionParameterBindingName(parameter: FunctionParameter, sourceCode: SourceCode): string;
|