@eslint-react/ast 2.0.0-next.2 → 2.0.0-next.200

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +188 -206
  2. package/dist/index.js +592 -546
  3. package/package.json +8 -9
package/dist/index.d.ts CHANGED
@@ -1,12 +1,60 @@
1
- import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/types';
2
- import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
3
- import { _ } from '@eslint-react/eff';
1
+ import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types";
2
+ import { unit } from "@eslint-react/eff";
3
+ import { TSESTree as TSESTree$1 } from "@typescript-eslint/utils";
4
4
 
5
+ //#region src/array-index.d.ts
6
+ declare function getArrayMethodCallbackIndexParamPosition(methodName: string): number;
7
+ //#endregion
8
+ //#region src/array-method.d.ts
5
9
  declare function isArrayFromCall(node: TSESTree.Node, loose?: boolean): node is TSESTree.CallExpression;
6
10
  declare function isArrayMapCall(node: TSESTree.Node, loose?: boolean): node is TSESTree.CallExpression;
7
-
8
- declare function getArrayMethodCallbackIndexParamPosition(methodName: string): number;
9
-
11
+ //#endregion
12
+ //#region src/node-equal.d.ts
13
+ /**
14
+ * Determines whether node equals to another node
15
+ * @param a node to compare
16
+ * @param b node to compare
17
+ * @returns `true` if node equal
18
+ * @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
19
+ */
20
+ declare const isNodeEqual: {
21
+ (a: TSESTree.Node): (b: TSESTree.Node) => boolean;
22
+ (a: TSESTree.Node, b: TSESTree.Node): boolean;
23
+ };
24
+ //#endregion
25
+ //#region src/node-format.d.ts
26
+ /**
27
+ * @internal
28
+ */
29
+ declare function toDelimiterFormat(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
30
+ /**
31
+ * Incomplete but sufficient stringification of AST nodes for common use cases
32
+ *
33
+ * @internal
34
+ */
35
+ declare function toStringFormat(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
36
+ //#endregion
37
+ //#region src/node-is.d.ts
38
+ declare const is: <NodeType extends TSESTree.AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
39
+ type: NodeType;
40
+ }>;
41
+ declare const isOneOf: <NodeTypes extends readonly TSESTree.AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
42
+ type: NodeTypes[number];
43
+ }>;
44
+ declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
45
+ declare const isFunctionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | TSESTree.TSCallSignatureDeclaration | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSDeclareFunctionNoDeclare | TSESTree.TSDeclareFunctionWithDeclare | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSFunctionType | TSESTree.TSMethodSignatureComputedName | TSESTree.TSMethodSignatureNonComputedName;
46
+ declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
47
+ declare const isMethodOrProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
48
+ declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
49
+ declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
50
+ declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
51
+ declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
52
+ declare const isJSX: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXAttribute | TSESTree.JSXClosingElement | TSESTree.JSXClosingFragment | TSESTree.JSXElement | TSESTree.JSXEmptyExpression | TSESTree.JSXExpressionContainer | TSESTree.JSXFragment | TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment | TSESTree.JSXSpreadAttribute | TSESTree.JSXSpreadChild | TSESTree.JSXText;
53
+ declare const isLoop: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
54
+ declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
55
+ declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
56
+ //#endregion
57
+ //#region src/node-types.d.ts
10
58
  type TSESTreeFunction = TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclaration | TSESTree$1.FunctionExpression;
11
59
  type TSESTreeFunctionType = TSESTree$1.TSCallSignatureDeclaration | TSESTree$1.TSConstructSignatureDeclaration | TSESTree$1.TSDeclareFunction | TSESTree$1.TSEmptyBodyFunctionExpression | TSESTree$1.TSFunctionType | TSESTree$1.TSMethodSignature | TSESTreeFunction;
12
60
  type TSESTreeClass = TSESTree$1.ClassDeclaration | TSESTree$1.ClassExpression;
@@ -15,154 +63,36 @@ type TSESTreeLoop = TSESTree$1.DoWhileStatement | TSESTree$1.ForInStatement | TS
15
63
  type TSESTreeArrayTupleType = TSESTree$1.TSArrayType | TSESTree$1.TSTupleType;
16
64
  type TSESTreeProperty = TSESTree$1.PropertyDefinition | TSESTree$1.TSIndexSignature | TSESTree$1.TSParameterProperty | TSESTree$1.TSPropertySignature;
17
65
  type TSESTreeJSX = TSESTree$1.JSXAttribute | TSESTree$1.JSXChild | TSESTree$1.JSXClosingElement | TSESTree$1.JSXClosingFragment | TSESTree$1.JSXElement | TSESTree$1.JSXEmptyExpression | TSESTree$1.JSXExpression | TSESTree$1.JSXExpressionContainer | TSESTree$1.JSXFragment | TSESTree$1.JSXIdentifier | TSESTree$1.JSXIdentifierToken | TSESTree$1.JSXMemberExpression | TSESTree$1.JSXNamespacedName | TSESTree$1.JSXOpeningElement | TSESTree$1.JSXOpeningFragment | TSESTree$1.JSXSpreadAttribute | TSESTree$1.JSXSpreadChild | TSESTree$1.JSXTagNameExpression | TSESTree$1.JSXText | TSESTree$1.JSXTextToken;
66
+ type TSESTreeJSXAttributeLike = TSESTree$1.JSXAttribute | TSESTree$1.JSXSpreadAttribute;
18
67
  type TSESTreeDestructuringPattern = TSESTree$1.ArrayPattern | TSESTree$1.AssignmentPattern | TSESTree$1.ObjectPattern | TSESTree$1.RestElement;
19
68
  type TSESTreeTypeDeclaration = TSESTree$1.TSInterfaceDeclaration | TSESTree$1.TSTypeAliasDeclaration;
20
69
  type TSESTreeTypeExpression = TSESTree$1.TSAsExpression | TSESTree$1.TSNonNullExpression | TSESTree$1.TSSatisfiesExpression | TSESTree$1.TSTypeAssertion | TSESTree$1.TSInstantiationExpression;
21
70
  type TSESTreeTypeAssertionExpression = TSESTree$1.TSAsExpression | TSESTree$1.TSNonNullExpression | TSESTree$1.TSSatisfiesExpression | TSESTree$1.TSTypeAssertion;
22
-
71
+ //#endregion
72
+ //#region src/class-id.d.ts
73
+ declare function getClassId(node: TSESTreeClass): TSESTree.Identifier | unit;
74
+ //#endregion
75
+ //#region src/expression-base.d.ts
23
76
  /**
24
- * Gets class identifier from ClassDeclaration or ClassExpression
25
- * @param node The AST node to check
26
- * @returns class identifier or null
77
+ * Unwraps any type expressions to get the underlying JavaScript expression node.
78
+ * Recursively processes nodes until a non-type expression is found.
79
+ *
80
+ * @param node - The AST node to unwrap
81
+ * @returns The underlying JavaScript expression node
27
82
  */
28
- declare function getClassId(node: TSESTreeClass): TSESTree.Identifier | _;
29
-
83
+ declare function getUnderlyingExpression(node: TSESTree.Node): Exclude<TSESTree.Node, TSESTreeTypeExpression>;
84
+ //#endregion
85
+ //#region src/expression-is.d.ts
30
86
  /**
31
- * Recursively get the inner expression until it's not a TypeExpression
32
- * @param node - The node to get the expression from
33
- * @returns The inner expression
87
+ * Checks if the given expression is a 'this' expression.
88
+ * Unwraps any type expressions before checking.
89
+ *
90
+ * @param node - The expression node to check
91
+ * @returns true if the expression is a ThisExpression, false otherwise
34
92
  */
35
- declare function getJSExpression(node: TSESTree.Node): Exclude<TSESTree.Node, TSESTreeTypeExpression>;
36
93
  declare function isThisExpression(node: TSESTree.Expression): boolean;
37
-
38
- /**
39
- * Gets the static name of a function AST node. For function declarations it is
40
- * easy. For anonymous function expressions it is much harder. If you search for
41
- * `IsAnonymousFunctionDefinition()` in the ECMAScript spec you'll find places
42
- * where JS gives anonymous function expressions names. We roughly detect the
43
- * same AST nodes with some exceptions to better fit our use case.
44
- */
45
-
46
- declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | _;
47
-
48
- type FunctionInitPath =
49
- /**
50
- * function Comp() { return <div />; }
51
- */
52
- readonly [TSESTree.FunctionDeclaration]
53
- /**
54
- * const Comp = () => <div />;
55
- * const Comp = function () { return <div />; };
56
- */
57
- | readonly [
58
- TSESTree.VariableDeclaration,
59
- TSESTree.VariableDeclarator,
60
- TSESTreeFunction
61
- ]
62
- /**
63
- * const Comp = React.memo(() => <div />);
64
- * const Comp = React.forwardRef(() => <div />);
65
- */
66
- | readonly [
67
- TSESTree.VariableDeclaration,
68
- TSESTree.VariableDeclarator,
69
- TSESTree.CallExpression,
70
- TSESTreeFunction
71
- ]
72
- /**
73
- * const Comp = React.memo(React.forwardRef(() => <div />));
74
- */
75
- | readonly [
76
- TSESTree.VariableDeclaration,
77
- TSESTree.VariableDeclarator,
78
- TSESTree.CallExpression,
79
- TSESTree.CallExpression,
80
- TSESTreeFunction
81
- ]
82
- /**
83
- * const Comps = {
84
- * TopNav() { return <div />; },
85
- * SidPanel: () => <div />,
86
- * }
87
- */
88
- | readonly [
89
- TSESTree.VariableDeclaration,
90
- TSESTree.VariableDeclarator,
91
- TSESTree.ObjectExpression,
92
- TSESTree.Property,
93
- TSESTreeFunction
94
- ]
95
- /**
96
- * const Comps = {
97
- * TopNav: React.memo(() => <div />),
98
- * SidPanel: React.forwardRef(() => <div />),
99
- * }
100
- */
101
- | readonly [
102
- TSESTree.VariableDeclaration,
103
- TSESTree.VariableDeclarator,
104
- TSESTree.ObjectExpression,
105
- TSESTree.Property,
106
- TSESTree.CallExpression,
107
- TSESTreeFunction
108
- ]
109
- /**
110
- * const Comps = {
111
- * TopNav: React.memo(React.forwardRef(() => <div />)),
112
- * SidPanel: React.forwardRef(React.memo(() => <div />)),
113
- * }
114
- */
115
- | readonly [
116
- TSESTree.VariableDeclaration,
117
- TSESTree.VariableDeclarator,
118
- TSESTree.ObjectExpression,
119
- TSESTree.Property,
120
- TSESTree.CallExpression,
121
- TSESTree.CallExpression,
122
- TSESTreeFunction
123
- ]
124
- /**
125
- * class Comp {
126
- * TopNav() { return <div />; }
127
- * }
128
- */
129
- | readonly [
130
- TSESTree.ClassDeclaration,
131
- TSESTree.ClassBody,
132
- TSESTree.MethodDefinition,
133
- TSESTreeFunction
134
- ]
135
- /**
136
- * class Comp {
137
- * TopNav = () => <div />;
138
- * }
139
- */
140
- | readonly [
141
- TSESTree.ClassDeclaration,
142
- TSESTree.ClassBody,
143
- TSESTree.PropertyDefinition,
144
- TSESTreeFunction
145
- ];
146
- declare function getFunctionInitPath(node: TSESTreeFunction): FunctionInitPath | _;
147
- declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
148
-
149
- declare function isEmptyFunction(node: TSESTreeFunction): boolean;
150
-
151
- /**
152
- * Find the parent node that satisfies the test function
153
- * @param node The AST node
154
- * @param test The test function
155
- * @returns The parent node that satisfies the test function or `_` if not found
156
- */
157
- declare function findParentNode<A extends TSESTree.Node>(node: TSESTree.Node | _, test: (n: TSESTree.Node) => n is A): A | _;
158
- /**
159
- * Find the parent node that satisfies the test function or `_` if not found
160
- * @param node The AST node
161
- * @param test The test function
162
- * @returns The parent node that satisfies the test function
163
- */
164
- declare function findParentNode(node: TSESTree.Node | _, test: (node: TSESTree.Node) => boolean): TSESTree.Node | _;
165
-
94
+ //#endregion
95
+ //#region src/expression-nested.d.ts
166
96
  /**
167
97
  * Get all nested identifiers in a expression like node
168
98
  * @param node The node to get the nested identifiers from
@@ -182,7 +112,7 @@ declare function getNestedReturnStatements(node: TSESTree.Node): readonly TSESTr
182
112
  * node, and it will return an array of all nested expressions of type T.
183
113
  */
184
114
  declare function getNestedExpressionsOfType<TNodeType extends AST_NODE_TYPES>(type: TNodeType): (node: TSESTree.Node) => Extract<TSESTree.Node, {
185
- type: TNodeType;
115
+ type: TNodeType;
186
116
  }>[];
187
117
  /**
188
118
  * Get all nested new expressions in an expression like node
@@ -196,89 +126,141 @@ declare const getNestedNewExpressions: (node: TSESTree.Node) => TSESTree.NewExpr
196
126
  * @returns All nested call expressions
197
127
  */
198
128
  declare const getNestedCallExpressions: (node: TSESTree.Node) => TSESTree.CallExpression[];
199
-
200
- declare const is: <NodeType extends TSESTree.AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
201
- type: NodeType;
202
- }>;
203
- declare const isOneOf: <NodeTypes extends readonly TSESTree.AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
204
- type: NodeTypes[number];
205
- }>;
206
- declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
207
- declare const isFunctionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | TSESTree.TSCallSignatureDeclaration | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSDeclareFunctionNoDeclare | TSESTree.TSDeclareFunctionWithDeclare | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSFunctionType | TSESTree.TSMethodSignatureComputedName | TSESTree.TSMethodSignatureNonComputedName;
208
- declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
209
- declare const isMethodOrProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
210
- declare const isLoop: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
211
- declare const isControlFlow: (data: TSESTree.Node | null | undefined) => data is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.SwitchStatement | TSESTree.WhileStatement;
212
- declare const isConditional: (data: TSESTree.Node | null | undefined) => data is TSESTree.ConditionalExpression | TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.IfStatement | TSESTree.LogicalExpression | TSESTree.SwitchStatement | TSESTree.WhileStatement;
213
- declare const isArrayTupleType: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSArrayType | TSESTree.TSTupleType;
214
- declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
215
- declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
216
- declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
217
- declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
218
- declare const isJSX: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXAttribute | TSESTree.JSXClosingElement | TSESTree.JSXClosingFragment | TSESTree.JSXElement | TSESTree.JSXEmptyExpression | TSESTree.JSXExpressionContainer | TSESTree.JSXFragment | TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment | TSESTree.JSXSpreadAttribute | TSESTree.JSXSpreadChild | TSESTree.JSXText;
219
- declare const isDestructuringPattern: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrayPattern | TSESTree.AssignmentPattern | TSESTree.ObjectPattern | TSESTree.RestElement;
220
- declare const isTypeDeclaration: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSInterfaceDeclaration | TSESTree.TSTypeAliasDeclaration;
221
- declare const isLeftHandSideExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.CallExpression | TSESTree.ClassExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression;
222
- declare const isLeftHandSideExpressionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrayExpression | TSESTree.ArrayPattern | TSESTree.ArrowFunctionExpression | TSESTree.CallExpression | TSESTree.ClassExpression | TSESTree.FunctionExpression | TSESTree.Identifier | TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral | TSESTree.MemberExpressionComputedName | TSESTree.MemberExpressionNonComputedName | TSESTree.MetaProperty | TSESTree.ObjectExpression | TSESTree.ObjectPattern | TSESTree.SequenceExpression | TSESTree.Super | TSESTree.TaggedTemplateExpression | TSESTree.TemplateLiteral | TSESTree.ThisExpression | TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSTypeAssertion;
223
- declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
224
- declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
225
-
129
+ //#endregion
130
+ //#region src/function-id.d.ts
226
131
  /**
227
- * Check if a node is multiline
228
- * @param node The AST node to check
229
- * @returns `true` if the node is multiline
132
+ * Gets the static name of a function AST node. For function declarations it is
133
+ * easy. For anonymous function expressions it is much harder. If you search for
134
+ * `IsAnonymousFunctionDefinition()` in the ECMAScript spec you'll find places
135
+ * where JS gives anonymous function expressions names. We roughly detect the
136
+ * same AST nodes with some exceptions to better fit our use case.
230
137
  */
231
- declare function isMultiLine(node: TSESTree.Node): boolean;
138
+ declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | unit;
139
+ //#endregion
140
+ //#region src/function-init-path.d.ts
232
141
  /**
233
- * Check if a node is a line break
234
- * @param node The AST node to check
235
- * @returns boolean
142
+ * Represents various AST paths for React component function declarations.
143
+ * Each tuple type represents a specific component definition pattern.
236
144
  */
237
- declare function isLineBreak(node: TSESTree.Node): boolean;
238
-
145
+ type FunctionInitPath = readonly [TSESTree.FunctionDeclaration] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.CallExpression, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.CallExpression, TSESTree.CallExpression, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.ObjectExpression, TSESTree.Property, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.ObjectExpression, TSESTree.Property, TSESTree.CallExpression, TSESTreeFunction] | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.ObjectExpression, TSESTree.Property, TSESTree.CallExpression, TSESTree.CallExpression, TSESTreeFunction] | readonly [TSESTree.ClassDeclaration, TSESTree.ClassBody, TSESTree.MethodDefinition, TSESTreeFunction] | readonly [TSESTree.ClassDeclaration, TSESTree.ClassBody, TSESTree.PropertyDefinition, TSESTreeFunction];
146
+ /**
147
+ * Identifies the initialization path of a function node in the AST.
148
+ * Determines what kind of component declaration pattern the function belongs to.
149
+ *
150
+ * @param node - The function node to analyze
151
+ * @returns The function initialization path or unit if not identifiable
152
+ */
153
+ declare function getFunctionInitPath(node: TSESTreeFunction): unit | FunctionInitPath;
154
+ /**
155
+ * Checks if a specific function call exists in the function initialization path.
156
+ * Useful for detecting HOCs like React.memo, React.forwardRef, etc.
157
+ *
158
+ * @param callName - The name of the call to check for (e.g., "memo", "forwardRef")
159
+ * @param initPath - The function initialization path to search in
160
+ * @returns True if the call exists in the path, false otherwise
161
+ */
162
+ declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
163
+ //#endregion
164
+ //#region src/function-is.d.ts
165
+ declare function isFunctionEmpty(node: TSESTreeFunction): boolean;
166
+ declare function isFunctionImmediatelyInvoked(node: TSESTreeFunction): boolean;
167
+ //#endregion
168
+ //#region src/literal.d.ts
239
169
  declare function isLiteral(node: TSESTree.Node): node is TSESTree.Literal;
240
170
  declare function isLiteral(node: TSESTree.Node, type: "boolean"): node is TSESTree.BooleanLiteral;
241
171
  declare function isLiteral(node: TSESTree.Node, type: "null"): node is TSESTree.NullLiteral;
242
172
  declare function isLiteral(node: TSESTree.Node, type: "number"): node is TSESTree.NumberLiteral;
243
173
  declare function isLiteral(node: TSESTree.Node, type: "regexp"): node is TSESTree.RegExpLiteral;
244
174
  declare function isLiteral(node: TSESTree.Node, type: "string"): node is TSESTree.StringLiteral;
245
-
175
+ //#endregion
176
+ //#region src/misc.d.ts
246
177
  /**
247
- * Determines whether node equals to another node
248
- * @param a node to compare
249
- * @param b node to compare
250
- * @returns `true` if node equal
251
- * @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
178
+ * Check if a node is multiline
179
+ * @param node The AST node to check
180
+ * @returns `true` if the node is multiline
252
181
  */
253
- declare const isNodeEqual: {
254
- (a: TSESTree.Node): (b: TSESTree.Node) => boolean;
255
- (a: TSESTree.Node, b: TSESTree.Node): boolean;
182
+ declare function isMultiLine(node: TSESTree.Node): boolean;
183
+ /**
184
+ * Check if a node is a line break
185
+ * @param node The AST node to check
186
+ * @returns boolean
187
+ */
188
+ declare function isLineBreak(node: TSESTree.Node): boolean;
189
+ //#endregion
190
+ //#region src/node-selectors.d.ts
191
+ type ImplicitReturnArrowFunctionExpression = TSESTree$1.ArrowFunctionExpression & {
192
+ body: TSESTree$1.Expression;
256
193
  };
257
-
194
+ type ObjectDestructuringVariableDeclarator = TSESTree$1.VariableDeclarator & {
195
+ id: TSESTree$1.ObjectPattern;
196
+ init: TSESTree$1.Identifier;
197
+ };
198
+ type DisplayNameAssignmentExpression = TSESTree$1.AssignmentExpression & {
199
+ type: "AssignmentExpression";
200
+ left: TSESTree$1.MemberExpression & {
201
+ property: TSESTree$1.Identifier & {
202
+ name: "displayName";
203
+ };
204
+ };
205
+ operator: "=";
206
+ right: TSESTree$1.Literal;
207
+ };
208
+ declare const SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION = "ArrowFunctionExpression[body.type!='BlockStatement']";
209
+ declare const SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR: string;
210
+ declare const SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION: string;
211
+ //#endregion
212
+ //#region src/process-env-node-env.d.ts
258
213
  /**
259
214
  * Check if the given node is a member expression that accesses `process.env.NODE_ENV`
260
215
  * @param node The AST node
261
216
  * @returns True if the node is a member expression that accesses `process.env.NODE_ENV`, false otherwise
262
217
  */
263
- declare function isProcessEnvNodeEnv(node: TSESTree.Node | null | _): node is TSESTree.MemberExpression;
218
+ declare function isProcessEnvNodeEnv(node: TSESTree.Node | null | unit): node is TSESTree.MemberExpression;
264
219
  /**
265
- * Check if the given node is a binary expression that compares `process.env.NODE_ENV` with a string literal
220
+ * Check if the given node is a binary expression that compares `process.env.NODE_ENV` with a string literal.
266
221
  * @param node The AST node
267
222
  * @param operator The operator used in the comparison
268
223
  * @param value The string literal value to compare against
269
224
  * @returns True if the node is a binary expression that compares `process.env.NODE_ENV` with the specified value, false otherwise
270
225
  */
271
- declare function isProcessEnvNodeEnvCompare(node: TSESTree.Node | null | _, operator: "===" | "!==", value: "development" | "production"): node is TSESTree.BinaryExpression;
272
-
273
- declare function getPropertyName(node: TSESTree.Node): string | _;
274
-
275
- declare function toDelimiterCaseType(node: TSESTree.Node, delimiter?: string): "RegExp literal" | Lowercase<string> | `JSX ${Lowercase<string>}`;
226
+ declare function isProcessEnvNodeEnvCompare(node: TSESTree.Node | null | unit, operator: "===" | "!==", value: "development" | "production"): node is TSESTree.BinaryExpression;
227
+ //#endregion
228
+ //#region src/promise-then.d.ts
229
+ declare function isThenCall(node: TSESTree.CallExpression): boolean;
230
+ //#endregion
231
+ //#region src/property-name.d.ts
232
+ declare function getPropertyName(node: TSESTree.Node): string | unit;
233
+ //#endregion
234
+ //#region src/traverse-up.d.ts
276
235
  /**
277
- * Returns human readable node name for given AST node
278
- * @param node AST node
279
- * @param getText A function that returns the text of the node in the source code
280
- * @returns Human readable node name
236
+ * Find the parent node that satisfies the test function
237
+ * @param node The AST node
238
+ * @param test The test function
239
+ * @returns The parent node that satisfies the test function or `_` if not found
281
240
  */
282
- declare function toString(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
283
-
284
- export { type FunctionInitPath, type TSESTreeArrayTupleType, type TSESTreeClass, type TSESTreeDestructuringPattern, type TSESTreeFunction, type TSESTreeFunctionType, type TSESTreeJSX, type TSESTreeLoop, type TSESTreeMethodOrProperty, type TSESTreeProperty, type TSESTreeTypeAssertionExpression, type TSESTreeTypeDeclaration, type TSESTreeTypeExpression, findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getJSExpression, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isArrayTupleType, isClass, isConditional, isControlFlow, isDestructuringPattern, isEmptyFunction, isFunction, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLeftHandSideExpression, isLeftHandSideExpressionType, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThisExpression, isTypeAssertionExpression, isTypeDeclaration, isTypeExpression, toDelimiterCaseType, toString };
241
+ declare function findParentNode<A extends TSESTree.Node>(node: TSESTree.Node | unit, test: (n: TSESTree.Node) => n is A): A | unit;
242
+ /**
243
+ * Find the parent node that satisfies the test function or `_` if not found
244
+ * @param node The AST node
245
+ * @param test The test function
246
+ * @returns The parent node that satisfies the test function
247
+ */
248
+ declare function findParentNode(node: TSESTree.Node | unit, test: (node: TSESTree.Node) => boolean): TSESTree.Node | unit;
249
+ //#endregion
250
+ //#region src/vitest-mock.d.ts
251
+ /**
252
+ * Checks if the given node is a `vi.mock`.
253
+ * @param node The node to check
254
+ * @returns `true` if the node is a `vi.mock`, otherwise `false`.
255
+ * @internal
256
+ */
257
+ declare function isViMock(node: TSESTree.Node | null | unit): node is TSESTree.MemberExpression;
258
+ /**
259
+ * Checks if the given node is a `vi.mock` callback.
260
+ * @param node The node to check
261
+ * @returns `true` if the node is a `vi.mock` callback, otherwise `false`.
262
+ * @internal
263
+ */
264
+ declare function isViMockCallback(node: TSESTree.Node | null | unit): boolean;
265
+ //#endregion
266
+ export { DisplayNameAssignmentExpression, FunctionInitPath, ImplicitReturnArrowFunctionExpression, ObjectDestructuringVariableDeclarator, SEL_DISPLAY_NAME_ASSIGNMENT_EXPRESSION, SEL_IMPLICIT_RETURN_ARROW_FUNCTION_EXPRESSION, SEL_OBJECT_DESTRUCTURING_VARIABLE_DECLARATOR, TSESTreeArrayTupleType, TSESTreeClass, TSESTreeDestructuringPattern, TSESTreeFunction, TSESTreeFunctionType, TSESTreeJSX, TSESTreeJSXAttributeLike, TSESTreeLoop, TSESTreeMethodOrProperty, TSESTreeProperty, TSESTreeTypeAssertionExpression, TSESTreeTypeDeclaration, TSESTreeTypeExpression, findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, getUnderlyingExpression, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isClass, isFunction, isFunctionEmpty, isFunctionImmediatelyInvoked, isFunctionType, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProcessEnvNodeEnv, isProcessEnvNodeEnvCompare, isProperty, isThenCall, isThisExpression, isTypeAssertionExpression, isTypeExpression, isViMock, isViMockCallback, toDelimiterFormat, toStringFormat };