@eslint-react/ast 2.0.0-next.146 → 2.0.0-next.148

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 +53 -92
  2. package/dist/index.js +483 -450
  3. package/package.json +7 -7
package/dist/index.d.ts CHANGED
@@ -1,12 +1,15 @@
1
- import { TSESTree, AST_NODE_TYPES } from '@typescript-eslint/types';
2
- import { unit } from '@eslint-react/eff';
3
- import { TSESTree as TSESTree$1 } from '@typescript-eslint/utils';
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/ast-array-method.d.ts
5
6
  declare function isArrayFromCall(node: TSESTree.Node, loose?: boolean): node is TSESTree.CallExpression;
6
7
  declare function isArrayMapCall(node: TSESTree.Node, loose?: boolean): node is TSESTree.CallExpression;
7
-
8
+ //#endregion
9
+ //#region src/ast-array-method-callback.d.ts
8
10
  declare function getArrayMethodCallbackIndexParamPosition(methodName: string): number;
9
-
11
+ //#endregion
12
+ //#region src/ast-node-types.d.ts
10
13
  type TSESTreeFunction = TSESTree$1.ArrowFunctionExpression | TSESTree$1.FunctionDeclaration | TSESTree$1.FunctionExpression;
11
14
  type TSESTreeFunctionType = TSESTree$1.TSCallSignatureDeclaration | TSESTree$1.TSConstructSignatureDeclaration | TSESTree$1.TSDeclareFunction | TSESTree$1.TSEmptyBodyFunctionExpression | TSESTree$1.TSFunctionType | TSESTree$1.TSMethodSignature | TSESTreeFunction;
12
15
  type TSESTreeClass = TSESTree$1.ClassDeclaration | TSESTree$1.ClassExpression;
@@ -19,9 +22,11 @@ type TSESTreeDestructuringPattern = TSESTree$1.ArrayPattern | TSESTree$1.Assignm
19
22
  type TSESTreeTypeDeclaration = TSESTree$1.TSInterfaceDeclaration | TSESTree$1.TSTypeAliasDeclaration;
20
23
  type TSESTreeTypeExpression = TSESTree$1.TSAsExpression | TSESTree$1.TSNonNullExpression | TSESTree$1.TSSatisfiesExpression | TSESTree$1.TSTypeAssertion | TSESTree$1.TSInstantiationExpression;
21
24
  type TSESTreeTypeAssertionExpression = TSESTree$1.TSAsExpression | TSESTree$1.TSNonNullExpression | TSESTree$1.TSSatisfiesExpression | TSESTree$1.TSTypeAssertion;
22
-
25
+ //#endregion
26
+ //#region src/ast-class-id.d.ts
23
27
  declare function getClassId(node: TSESTreeClass): TSESTree.Identifier | unit;
24
-
28
+ //#endregion
29
+ //#region src/ast-expression.d.ts
25
30
  /**
26
31
  * Recursively get the inner expression until it's not a TypeExpression
27
32
  * @param node - The node to get the expression from
@@ -29,7 +34,8 @@ declare function getClassId(node: TSESTreeClass): TSESTree.Identifier | unit;
29
34
  */
30
35
  declare function getJSExpression(node: TSESTree.Node): Exclude<TSESTree.Node, TSESTreeTypeExpression>;
31
36
  declare function isThisExpression(node: TSESTree.Expression): boolean;
32
-
37
+ //#endregion
38
+ //#region src/ast-function-id.d.ts
33
39
  /**
34
40
  * Gets the static name of a function AST node. For function declarations it is
35
41
  * easy. For anonymous function expressions it is much harder. If you search for
@@ -38,8 +44,9 @@ declare function isThisExpression(node: TSESTree.Expression): boolean;
38
44
  * same AST nodes with some exceptions to better fit our use case.
39
45
  */
40
46
  declare function getFunctionId(node: TSESTree.Expression | TSESTreeFunction): TSESTree.Identifier | unit;
41
-
42
- type FunctionInitPath =
47
+ //#endregion
48
+ //#region src/ast-function-init-path.d.ts
49
+ type FunctionInitPath =
43
50
  /**
44
51
  * function Comp() { return <div />; }
45
52
  */
@@ -47,102 +54,50 @@ readonly [TSESTree.FunctionDeclaration]
47
54
  /**
48
55
  * const Comp = () => <div />;
49
56
  * const Comp = function () { return <div />; };
50
- */
51
- | readonly [
52
- TSESTree.VariableDeclaration,
53
- TSESTree.VariableDeclarator,
54
- TSESTreeFunction
55
- ]
57
+ */ | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTreeFunction]
56
58
  /**
57
59
  * const Comp = React.memo(() => <div />);
58
60
  * const Comp = React.forwardRef(() => <div />);
59
- */
60
- | readonly [
61
- TSESTree.VariableDeclaration,
62
- TSESTree.VariableDeclarator,
63
- TSESTree.CallExpression,
64
- TSESTreeFunction
65
- ]
61
+ */ | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.CallExpression, TSESTreeFunction]
66
62
  /**
67
63
  * const Comp = React.memo(React.forwardRef(() => <div />));
68
- */
69
- | readonly [
70
- TSESTree.VariableDeclaration,
71
- TSESTree.VariableDeclarator,
72
- TSESTree.CallExpression,
73
- TSESTree.CallExpression,
74
- TSESTreeFunction
75
- ]
64
+ */ | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.CallExpression, TSESTree.CallExpression, TSESTreeFunction]
76
65
  /**
77
66
  * const Comps = {
78
67
  * TopNav() { return <div />; },
79
68
  * SidPanel: () => <div />,
80
69
  * }
81
- */
82
- | readonly [
83
- TSESTree.VariableDeclaration,
84
- TSESTree.VariableDeclarator,
85
- TSESTree.ObjectExpression,
86
- TSESTree.Property,
87
- TSESTreeFunction
88
- ]
70
+ */ | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.ObjectExpression, TSESTree.Property, TSESTreeFunction]
89
71
  /**
90
72
  * const Comps = {
91
73
  * TopNav: React.memo(() => <div />),
92
74
  * SidPanel: React.forwardRef(() => <div />),
93
75
  * }
94
- */
95
- | readonly [
96
- TSESTree.VariableDeclaration,
97
- TSESTree.VariableDeclarator,
98
- TSESTree.ObjectExpression,
99
- TSESTree.Property,
100
- TSESTree.CallExpression,
101
- TSESTreeFunction
102
- ]
76
+ */ | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.ObjectExpression, TSESTree.Property, TSESTree.CallExpression, TSESTreeFunction]
103
77
  /**
104
78
  * const Comps = {
105
79
  * TopNav: React.memo(React.forwardRef(() => <div />)),
106
80
  * SidPanel: React.forwardRef(React.memo(() => <div />)),
107
81
  * }
108
- */
109
- | readonly [
110
- TSESTree.VariableDeclaration,
111
- TSESTree.VariableDeclarator,
112
- TSESTree.ObjectExpression,
113
- TSESTree.Property,
114
- TSESTree.CallExpression,
115
- TSESTree.CallExpression,
116
- TSESTreeFunction
117
- ]
82
+ */ | readonly [TSESTree.VariableDeclaration, TSESTree.VariableDeclarator, TSESTree.ObjectExpression, TSESTree.Property, TSESTree.CallExpression, TSESTree.CallExpression, TSESTreeFunction]
118
83
  /**
119
84
  * class Comp {
120
85
  * TopNav() { return <div />; }
121
86
  * }
122
- */
123
- | readonly [
124
- TSESTree.ClassDeclaration,
125
- TSESTree.ClassBody,
126
- TSESTree.MethodDefinition,
127
- TSESTreeFunction
128
- ]
87
+ */ | readonly [TSESTree.ClassDeclaration, TSESTree.ClassBody, TSESTree.MethodDefinition, TSESTreeFunction]
129
88
  /**
130
89
  * class Comp {
131
90
  * TopNav = () => <div />;
132
91
  * }
133
- */
134
- | readonly [
135
- TSESTree.ClassDeclaration,
136
- TSESTree.ClassBody,
137
- TSESTree.PropertyDefinition,
138
- TSESTreeFunction
139
- ];
92
+ */ | readonly [TSESTree.ClassDeclaration, TSESTree.ClassBody, TSESTree.PropertyDefinition, TSESTreeFunction];
140
93
  declare function getFunctionInitPath(node: TSESTreeFunction): unit | FunctionInitPath;
141
94
  declare function hasCallInFunctionInitPath(callName: string, initPath: FunctionInitPath): boolean;
142
-
95
+ //#endregion
96
+ //#region src/ast-function-is.d.ts
143
97
  declare function isEmptyFunction(node: TSESTreeFunction): boolean;
144
98
  declare function isImmediatelyInvokedFunction(node: TSESTreeFunction): boolean;
145
-
99
+ //#endregion
100
+ //#region src/ast-hierarchy.d.ts
146
101
  /**
147
102
  * Find the parent node that satisfies the test function
148
103
  * @param node The AST node
@@ -157,7 +112,6 @@ declare function findParentNode<A extends TSESTree.Node>(node: TSESTree.Node | u
157
112
  * @returns The parent node that satisfies the test function
158
113
  */
159
114
  declare function findParentNode(node: TSESTree.Node | unit, test: (node: TSESTree.Node) => boolean): TSESTree.Node | unit;
160
-
161
115
  /**
162
116
  * Get all nested identifiers in a expression like node
163
117
  * @param node The node to get the nested identifiers from
@@ -177,7 +131,7 @@ declare function getNestedReturnStatements(node: TSESTree.Node): readonly TSESTr
177
131
  * node, and it will return an array of all nested expressions of type T.
178
132
  */
179
133
  declare function getNestedExpressionsOfType<TNodeType extends AST_NODE_TYPES>(type: TNodeType): (node: TSESTree.Node) => Extract<TSESTree.Node, {
180
- type: TNodeType;
134
+ type: TNodeType;
181
135
  }>[];
182
136
  /**
183
137
  * Get all nested new expressions in an expression like node
@@ -191,7 +145,8 @@ declare const getNestedNewExpressions: (node: TSESTree.Node) => TSESTree.NewExpr
191
145
  * @returns All nested call expressions
192
146
  */
193
147
  declare const getNestedCallExpressions: (node: TSESTree.Node) => TSESTree.CallExpression[];
194
-
148
+ //#endregion
149
+ //#region src/ast-line.d.ts
195
150
  /**
196
151
  * Check if a node is multiline
197
152
  * @param node The AST node to check
@@ -204,14 +159,16 @@ declare function isMultiLine(node: TSESTree.Node): boolean;
204
159
  * @returns boolean
205
160
  */
206
161
  declare function isLineBreak(node: TSESTree.Node): boolean;
207
-
162
+ //#endregion
163
+ //#region src/ast-literal-is.d.ts
208
164
  declare function isLiteral(node: TSESTree.Node): node is TSESTree.Literal;
209
165
  declare function isLiteral(node: TSESTree.Node, type: "boolean"): node is TSESTree.BooleanLiteral;
210
166
  declare function isLiteral(node: TSESTree.Node, type: "null"): node is TSESTree.NullLiteral;
211
167
  declare function isLiteral(node: TSESTree.Node, type: "number"): node is TSESTree.NumberLiteral;
212
168
  declare function isLiteral(node: TSESTree.Node, type: "regexp"): node is TSESTree.RegExpLiteral;
213
169
  declare function isLiteral(node: TSESTree.Node, type: "string"): node is TSESTree.StringLiteral;
214
-
170
+ //#endregion
171
+ //#region src/ast-node-equal.d.ts
215
172
  /**
216
173
  * Determines whether node equals to another node
217
174
  * @param a node to compare
@@ -220,10 +177,11 @@ declare function isLiteral(node: TSESTree.Node, type: "string"): node is TSESTre
220
177
  * @see https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/util/isNodeEqual.ts
221
178
  */
222
179
  declare const isNodeEqual: {
223
- (a: TSESTree.Node): (b: TSESTree.Node) => boolean;
224
- (a: TSESTree.Node, b: TSESTree.Node): boolean;
180
+ (a: TSESTree.Node): (b: TSESTree.Node) => boolean;
181
+ (a: TSESTree.Node, b: TSESTree.Node): boolean;
225
182
  };
226
-
183
+ //#endregion
184
+ //#region src/ast-node-format.d.ts
227
185
  /**
228
186
  * @internal
229
187
  */
@@ -232,28 +190,31 @@ declare function toDelimiterFormat(node: TSESTree.Node, delimiter?: string): "Re
232
190
  * @internal
233
191
  */
234
192
  declare function toStringFormat(node: TSESTree.Node, getText: (node: TSESTree.Node) => string): string;
235
-
193
+ //#endregion
194
+ //#region src/ast-node-is.d.ts
236
195
  declare const is: <NodeType extends TSESTree.AST_NODE_TYPES>(nodeType: NodeType) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
237
- type: NodeType;
196
+ type: NodeType;
238
197
  }>;
239
198
  declare const isOneOf: <NodeTypes extends readonly TSESTree.AST_NODE_TYPES[]>(nodeTypes: NodeTypes) => (node: TSESTree.Node | null | undefined) => node is Extract<TSESTree.Node, {
240
- type: NodeTypes[number];
199
+ type: NodeTypes[number];
241
200
  }>;
242
201
  declare const isFunction: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression;
243
- 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;
244
- declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName | TSESTree.ClassExpression;
202
+ declare const isFunctionType: (node: TSESTree.Node | null | undefined) => node is TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | TSESTree.TSDeclareFunctionNoDeclare | TSESTree.TSDeclareFunctionWithDeclare | TSESTree.TSCallSignatureDeclaration | TSESTree.TSConstructSignatureDeclaration | TSESTree.TSEmptyBodyFunctionExpression | TSESTree.TSFunctionType | TSESTree.TSMethodSignatureComputedName | TSESTree.TSMethodSignatureNonComputedName;
203
+ declare const isClass: (node: TSESTree.Node | null | undefined) => node is TSESTree.ClassExpression | TSESTree.ClassDeclarationWithName | TSESTree.ClassDeclarationWithOptionalName;
245
204
  declare const isMethodOrProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.MethodDefinitionComputedName | TSESTree.MethodDefinitionNonComputedName | TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName;
246
205
  declare const isProperty: (node: TSESTree.Node | null | undefined) => node is TSESTree.PropertyDefinitionComputedName | TSESTree.PropertyDefinitionNonComputedName | TSESTree.TSIndexSignature | TSESTree.TSParameterProperty | TSESTree.TSPropertySignatureComputedName | TSESTree.TSPropertySignatureNonComputedName;
247
206
  declare const isJSXElement: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement;
248
207
  declare const isJSXFragment: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXFragment;
249
208
  declare const isJSXTagNameExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName;
250
- 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;
209
+ declare const isJSX: (node: TSESTree.Node | null | undefined) => node is TSESTree.JSXElement | TSESTree.JSXFragment | TSESTree.JSXAttribute | TSESTree.JSXClosingElement | TSESTree.JSXClosingFragment | TSESTree.JSXEmptyExpression | TSESTree.JSXExpressionContainer | TSESTree.JSXIdentifier | TSESTree.JSXMemberExpression | TSESTree.JSXNamespacedName | TSESTree.JSXOpeningElement | TSESTree.JSXOpeningFragment | TSESTree.JSXSpreadAttribute | TSESTree.JSXSpreadChild | TSESTree.JSXText;
251
210
  declare const isLoop: (node: TSESTree.Node | null | undefined) => node is TSESTree.DoWhileStatement | TSESTree.ForInStatement | TSESTree.ForOfStatement | TSESTree.ForStatement | TSESTree.WhileStatement;
252
211
  declare const isTypeExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSInstantiationExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
253
212
  declare const isTypeAssertionExpression: (node: TSESTree.Node | null | undefined) => node is TSESTree.TSAsExpression | TSESTree.TSNonNullExpression | TSESTree.TSSatisfiesExpression | TSESTree.TSTypeAssertion;
254
-
213
+ //#endregion
214
+ //#region src/ast-property-name.d.ts
255
215
  declare function getPropertyName(node: TSESTree.Node): string | unit;
256
-
216
+ //#endregion
217
+ //#region src/ast-then.d.ts
257
218
  declare function isThenCall(node: TSESTree.CallExpression): boolean;
258
-
259
- 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, isClass, isEmptyFunction, isFunction, isFunctionType, isImmediatelyInvokedFunction, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProperty, isThenCall, isThisExpression, isTypeAssertionExpression, isTypeExpression, toDelimiterFormat, toStringFormat };
219
+ //#endregion
220
+ export { FunctionInitPath, TSESTreeArrayTupleType, TSESTreeClass, TSESTreeDestructuringPattern, TSESTreeFunction, TSESTreeFunctionType, TSESTreeJSX, TSESTreeLoop, TSESTreeMethodOrProperty, TSESTreeProperty, TSESTreeTypeAssertionExpression, TSESTreeTypeDeclaration, TSESTreeTypeExpression, findParentNode, getArrayMethodCallbackIndexParamPosition, getClassId, getFunctionId, getFunctionInitPath, getJSExpression, getNestedCallExpressions, getNestedExpressionsOfType, getNestedIdentifiers, getNestedNewExpressions, getNestedReturnStatements, getPropertyName, hasCallInFunctionInitPath, is, isArrayFromCall, isArrayMapCall, isClass, isEmptyFunction, isFunction, isFunctionType, isImmediatelyInvokedFunction, isJSX, isJSXElement, isJSXFragment, isJSXTagNameExpression, isLineBreak, isLiteral, isLoop, isMethodOrProperty, isMultiLine, isNodeEqual, isOneOf, isProperty, isThenCall, isThisExpression, isTypeAssertionExpression, isTypeExpression, toDelimiterFormat, toStringFormat };