@eslint-react/core 3.0.0-next.8 → 3.0.0-next.81
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/index.d.ts +348 -326
- package/dist/index.js +715 -550
- package/package.json +10 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,17 +1,25 @@
|
|
|
1
1
|
import * as ast from "@eslint-react/ast";
|
|
2
|
-
import { unit } from "@eslint-react/eff";
|
|
3
2
|
import { TSESTree } from "@typescript-eslint/types";
|
|
4
3
|
import { RegExpLike, RuleContext } from "@eslint-react/shared";
|
|
5
4
|
import { ESLintUtils, TSESTree as TSESTree$1 } from "@typescript-eslint/utils";
|
|
6
5
|
import { Scope } from "@typescript-eslint/scope-manager";
|
|
7
6
|
import * as typescript from "typescript";
|
|
8
7
|
|
|
8
|
+
//#region src/api/find-import-source.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* Find the import source of a variable
|
|
11
|
+
* @param name The variable name
|
|
12
|
+
* @param initialScope The initial scope to search
|
|
13
|
+
* @returns The import source or null if not found
|
|
14
|
+
*/
|
|
15
|
+
declare function findImportSource(name: string, initialScope: Scope): string | null;
|
|
16
|
+
//#endregion
|
|
9
17
|
//#region src/api/is-from-react.d.ts
|
|
10
18
|
/**
|
|
11
19
|
* Check if a variable is initialized from React import
|
|
12
20
|
* @param name The variable name
|
|
13
21
|
* @param initialScope The initial scope
|
|
14
|
-
* @param importSource Alternative import source of React (
|
|
22
|
+
* @param importSource Alternative import source of React (ex: "preact/compat")
|
|
15
23
|
* @returns True if the variable is initialized or derived from React import
|
|
16
24
|
*/
|
|
17
25
|
declare function isInitializedFromReact(name: string, initialScope: Scope, importSource?: string): boolean;
|
|
@@ -21,7 +29,7 @@ declare function isInitializedFromReact(name: string, initialScope: Scope, impor
|
|
|
21
29
|
* if a variable is initialized from React Native import
|
|
22
30
|
* @param name The variable name
|
|
23
31
|
* @param initialScope The initial scope
|
|
24
|
-
* @param importSource Alternative import source of React Native (
|
|
32
|
+
* @param importSource Alternative import source of React Native (ex: "react-native-web")
|
|
25
33
|
* @returns True if the variable is initialized from React Native import
|
|
26
34
|
*/
|
|
27
35
|
declare function isInitializedFromReactNative(name: string, initialScope: Scope, importSource?: string): boolean;
|
|
@@ -29,20 +37,20 @@ declare function isInitializedFromReactNative(name: string, initialScope: Scope,
|
|
|
29
37
|
//#region src/api/is-react-api.d.ts
|
|
30
38
|
declare namespace isReactAPI {
|
|
31
39
|
type ReturnType = {
|
|
32
|
-
(context: RuleContext, node:
|
|
33
|
-
(context: RuleContext): (node:
|
|
40
|
+
(context: RuleContext, node: null | TSESTree.Node): node is TSESTree.Identifier | TSESTree.MemberExpression;
|
|
41
|
+
(context: RuleContext): (node: null | TSESTree.Node) => node is TSESTree.MemberExpression | TSESTree.Identifier;
|
|
34
42
|
};
|
|
35
43
|
}
|
|
36
44
|
/**
|
|
37
45
|
* Check if the node is a React API identifier or member expression
|
|
38
|
-
* @param api The React API name to check against (
|
|
46
|
+
* @param api The React API name to check against (ex: "useState", "React.memo")
|
|
39
47
|
* @returns A predicate function to check if a node matches the API
|
|
40
48
|
*/
|
|
41
49
|
declare function isReactAPI(api: string): isReactAPI.ReturnType;
|
|
42
50
|
declare namespace isReactAPICall {
|
|
43
51
|
type ReturnType = {
|
|
44
|
-
(context: RuleContext, node:
|
|
45
|
-
(context: RuleContext): (node:
|
|
52
|
+
(context: RuleContext, node: null | TSESTree.Node): node is TSESTree.CallExpression;
|
|
53
|
+
(context: RuleContext): (node: null | TSESTree.Node) => node is TSESTree.CallExpression;
|
|
46
54
|
};
|
|
47
55
|
}
|
|
48
56
|
/**
|
|
@@ -78,19 +86,19 @@ declare const isForwardRefCall: isReactAPICall.ReturnType;
|
|
|
78
86
|
declare const isMemoCall: isReactAPICall.ReturnType;
|
|
79
87
|
declare const isLazyCall: isReactAPICall.ReturnType;
|
|
80
88
|
//#endregion
|
|
81
|
-
//#region src/component/component-detection
|
|
89
|
+
//#region src/component/component-detection.d.ts
|
|
82
90
|
type ComponentDetectionHint = bigint;
|
|
83
91
|
/**
|
|
84
92
|
* Hints for component collector
|
|
85
93
|
*/
|
|
86
94
|
declare const ComponentDetectionHint: {
|
|
87
|
-
readonly
|
|
95
|
+
readonly DoNotIncludeFunctionDefinedAsArrayFlatMapCallback: bigint;
|
|
96
|
+
readonly DoNotIncludeFunctionDefinedAsArrayMapCallback: bigint;
|
|
97
|
+
readonly DoNotIncludeFunctionDefinedInArrayExpression: bigint;
|
|
98
|
+
readonly DoNotIncludeFunctionDefinedInArrayPattern: bigint;
|
|
88
99
|
readonly DoNotIncludeFunctionDefinedOnClassMethod: bigint;
|
|
89
100
|
readonly DoNotIncludeFunctionDefinedOnClassProperty: bigint;
|
|
90
|
-
readonly
|
|
91
|
-
readonly DoNotIncludeFunctionDefinedInArrayExpression: bigint;
|
|
92
|
-
readonly DoNotIncludeFunctionDefinedAsArrayMapCallback: bigint;
|
|
93
|
-
readonly DoNotIncludeFunctionDefinedAsArrayFlatMapCallback: bigint;
|
|
101
|
+
readonly DoNotIncludeFunctionDefinedOnObjectMethod: bigint;
|
|
94
102
|
readonly None: 0n;
|
|
95
103
|
readonly DoNotIncludeJsxWithNullValue: bigint;
|
|
96
104
|
readonly DoNotIncludeJsxWithNumberValue: bigint;
|
|
@@ -108,6 +116,15 @@ declare const ComponentDetectionHint: {
|
|
|
108
116
|
* Default component detection hint
|
|
109
117
|
*/
|
|
110
118
|
declare const DEFAULT_COMPONENT_DETECTION_HINT: bigint;
|
|
119
|
+
/**
|
|
120
|
+
* Determine if a function node represents a valid React component definition
|
|
121
|
+
*
|
|
122
|
+
* @param context The rule context
|
|
123
|
+
* @param node The function node to analyze
|
|
124
|
+
* @param hint Component detection hints (bit flags) to customize detection logic
|
|
125
|
+
* @returns `true` if the node is considered a component definition
|
|
126
|
+
*/
|
|
127
|
+
declare function isComponentDefinition(context: RuleContext, node: ast.TSESTreeFunction, hint: bigint): boolean;
|
|
111
128
|
//#endregion
|
|
112
129
|
//#region src/semantic/semantic-node.d.ts
|
|
113
130
|
/**
|
|
@@ -116,19 +133,19 @@ declare const DEFAULT_COMPONENT_DETECTION_HINT: bigint;
|
|
|
116
133
|
*/
|
|
117
134
|
interface SemanticNode {
|
|
118
135
|
/** The identifier of the node */
|
|
119
|
-
id:
|
|
136
|
+
id: null | TSESTree.Node;
|
|
120
137
|
/** The unique key of the node */
|
|
121
138
|
key: string;
|
|
122
139
|
/** The kind of the node */
|
|
123
140
|
kind: string;
|
|
124
141
|
/** The name of the node */
|
|
125
|
-
name:
|
|
126
|
-
/** The AST node */
|
|
127
|
-
node: TSESTree.Node;
|
|
142
|
+
name: null | string;
|
|
128
143
|
/** The flag of the node */
|
|
129
144
|
flag: bigint;
|
|
130
145
|
/** The hint of the node */
|
|
131
146
|
hint: bigint;
|
|
147
|
+
/** The AST node */
|
|
148
|
+
node: TSESTree.Node;
|
|
132
149
|
}
|
|
133
150
|
//#endregion
|
|
134
151
|
//#region src/semantic/semantic-func.d.ts
|
|
@@ -138,36 +155,23 @@ interface SemanticNode {
|
|
|
138
155
|
*/
|
|
139
156
|
interface SemanticFunc extends SemanticNode {
|
|
140
157
|
/** The identifier of the function */
|
|
141
|
-
id: ast.FunctionID
|
|
158
|
+
id: ast.FunctionID;
|
|
142
159
|
/** The AST node of the function */
|
|
143
160
|
node: ast.TSESTreeFunction;
|
|
144
161
|
/** The name of the function */
|
|
145
|
-
name: string |
|
|
162
|
+
name: string | null;
|
|
146
163
|
/** The return type annotation of the function */
|
|
147
|
-
type: TSESTree.TSTypeAnnotation |
|
|
164
|
+
type: TSESTree.TSTypeAnnotation | null;
|
|
148
165
|
/** The body of the function */
|
|
149
166
|
body: TSESTree.BlockStatement | TSESTree.Expression;
|
|
150
|
-
/** The directives of the function (
|
|
167
|
+
/** The directives of the function (ex: "use strict", "use client", "use server", etc.) */
|
|
151
168
|
directives: ast.TSESTreeDirective[];
|
|
152
169
|
/** The parameters of the function */
|
|
153
170
|
parameters: TSESTree.Parameter[];
|
|
154
171
|
/** The type parameters of the function */
|
|
155
|
-
typeParameters: TSESTree.TSTypeParameterDeclaration |
|
|
172
|
+
typeParameters: TSESTree.TSTypeParameterDeclaration | null;
|
|
156
173
|
}
|
|
157
174
|
//#endregion
|
|
158
|
-
//#region src/component/component-flag.d.ts
|
|
159
|
-
type ComponentFlag = bigint;
|
|
160
|
-
/**
|
|
161
|
-
* Component flag constants
|
|
162
|
-
*/
|
|
163
|
-
declare const ComponentFlag: {
|
|
164
|
-
/** No flags set */None: bigint; /** Indicates the component is a pure component (e.g., extends PureComponent) */
|
|
165
|
-
PureComponent: bigint; /** Indicates the component creates elements using `createElement` instead of JSX */
|
|
166
|
-
CreateElement: bigint; /** Indicates the component is memoized (e.g., React.memo) */
|
|
167
|
-
Memo: bigint; /** Indicates the component forwards a ref (e.g., React.forwardRef) */
|
|
168
|
-
ForwardRef: bigint;
|
|
169
|
-
};
|
|
170
|
-
//#endregion
|
|
171
175
|
//#region src/component/component-semantic-node.d.ts
|
|
172
176
|
/**
|
|
173
177
|
* Represents a React Function Component
|
|
@@ -176,7 +180,7 @@ interface FunctionComponentSemanticNode extends SemanticNode {
|
|
|
176
180
|
/**
|
|
177
181
|
* The identifier or identifier sequence of the component
|
|
178
182
|
*/
|
|
179
|
-
id:
|
|
183
|
+
id: ast.FunctionID;
|
|
180
184
|
/**
|
|
181
185
|
* The kind of component
|
|
182
186
|
*/
|
|
@@ -188,11 +192,11 @@ interface FunctionComponentSemanticNode extends SemanticNode {
|
|
|
188
192
|
/**
|
|
189
193
|
* Flags describing the component's characteristics
|
|
190
194
|
*/
|
|
191
|
-
flag:
|
|
195
|
+
flag: bigint;
|
|
192
196
|
/**
|
|
193
197
|
* Hint for how the component was detected
|
|
194
198
|
*/
|
|
195
|
-
hint:
|
|
199
|
+
hint: bigint;
|
|
196
200
|
/**
|
|
197
201
|
* List of expressions returned by the component
|
|
198
202
|
*/
|
|
@@ -200,7 +204,7 @@ interface FunctionComponentSemanticNode extends SemanticNode {
|
|
|
200
204
|
/**
|
|
201
205
|
* The initialization path of the function
|
|
202
206
|
*/
|
|
203
|
-
initPath:
|
|
207
|
+
initPath: null | ast.FunctionInitPath;
|
|
204
208
|
/**
|
|
205
209
|
* Indicates if the component is inside an export default declaration
|
|
206
210
|
*/
|
|
@@ -216,9 +220,9 @@ interface FunctionComponentSemanticNode extends SemanticNode {
|
|
|
216
220
|
/**
|
|
217
221
|
* The display name of the component
|
|
218
222
|
*/
|
|
219
|
-
displayName:
|
|
223
|
+
displayName: null | TSESTree.Expression;
|
|
220
224
|
/**
|
|
221
|
-
* The directives used in the function (
|
|
225
|
+
* The directives used in the function (ex: "use strict", "use client", etc.)
|
|
222
226
|
*/
|
|
223
227
|
directives: ast.TSESTreeDirective[];
|
|
224
228
|
}
|
|
@@ -229,7 +233,7 @@ interface ClassComponentSemanticNode extends SemanticNode {
|
|
|
229
233
|
/**
|
|
230
234
|
* The identifier of the component
|
|
231
235
|
*/
|
|
232
|
-
id:
|
|
236
|
+
id: null | TSESTree.BindingName;
|
|
233
237
|
/**
|
|
234
238
|
* The kind of component
|
|
235
239
|
*/
|
|
@@ -241,11 +245,11 @@ interface ClassComponentSemanticNode extends SemanticNode {
|
|
|
241
245
|
/**
|
|
242
246
|
* Flags describing the component's characteristics
|
|
243
247
|
*/
|
|
244
|
-
flag:
|
|
248
|
+
flag: bigint;
|
|
245
249
|
/**
|
|
246
250
|
* Hint for how the component was detected
|
|
247
251
|
*/
|
|
248
|
-
hint:
|
|
252
|
+
hint: bigint;
|
|
249
253
|
/**
|
|
250
254
|
* List of methods and properties in the class
|
|
251
255
|
*/
|
|
@@ -253,7 +257,7 @@ interface ClassComponentSemanticNode extends SemanticNode {
|
|
|
253
257
|
/**
|
|
254
258
|
* The display name of the component
|
|
255
259
|
*/
|
|
256
|
-
displayName:
|
|
260
|
+
displayName: null | TSESTree.Expression;
|
|
257
261
|
}
|
|
258
262
|
/**
|
|
259
263
|
* Represents a React Component
|
|
@@ -273,7 +277,7 @@ declare namespace useComponentCollector {
|
|
|
273
277
|
ctx: {
|
|
274
278
|
getAllComponents: (node: TSESTree.Program) => FunctionComponentSemanticNode[];
|
|
275
279
|
getCurrentEntries: () => FunctionEntry$1[];
|
|
276
|
-
getCurrentEntry: () => FunctionEntry$1 |
|
|
280
|
+
getCurrentEntry: () => FunctionEntry$1 | null;
|
|
277
281
|
};
|
|
278
282
|
visitor: ESLintUtils.RuleListener;
|
|
279
283
|
};
|
|
@@ -301,48 +305,8 @@ declare namespace useComponentCollectorLegacy {
|
|
|
301
305
|
* @returns The ctx and visitor of the collector
|
|
302
306
|
*/
|
|
303
307
|
declare function useComponentCollectorLegacy(context: RuleContext): useComponentCollectorLegacy.ReturnType;
|
|
304
|
-
/**
|
|
305
|
-
* Check whether the given node is a this.setState() call
|
|
306
|
-
* @param node The node to check
|
|
307
|
-
* @internal
|
|
308
|
-
*/
|
|
309
|
-
declare function isThisSetState(node: TSESTree$1.CallExpression): boolean;
|
|
310
|
-
/**
|
|
311
|
-
* Check whether the given node is an assignment to this.state
|
|
312
|
-
* @param node The node to check
|
|
313
|
-
* @internal
|
|
314
|
-
*/
|
|
315
|
-
declare function isAssignmentToThisState(node: TSESTree$1.AssignmentExpression): boolean;
|
|
316
308
|
//#endregion
|
|
317
|
-
//#region src/component/component-
|
|
318
|
-
/**
|
|
319
|
-
* Determine if a function node represents a valid React component definition
|
|
320
|
-
*
|
|
321
|
-
* @param context The rule context
|
|
322
|
-
* @param node The function node to analyze
|
|
323
|
-
* @param hint Component detection hints (bit flags) to customize detection logic
|
|
324
|
-
* @returns `true` if the node is considered a component definition
|
|
325
|
-
*/
|
|
326
|
-
declare function isComponentDefinition(context: RuleContext, node: ast.TSESTreeFunction, hint: bigint): boolean;
|
|
327
|
-
//#endregion
|
|
328
|
-
//#region src/component/component-id.d.ts
|
|
329
|
-
/**
|
|
330
|
-
* Get function component identifier from `const Component = memo(() => {});`
|
|
331
|
-
* @param context The rule context
|
|
332
|
-
* @param node The function node to analyze
|
|
333
|
-
* @returns The function identifier or `unit` if not found
|
|
334
|
-
*/
|
|
335
|
-
declare function getFunctionComponentId(context: RuleContext, node: ast.TSESTreeFunction): ast.FunctionID | unit;
|
|
336
|
-
//#endregion
|
|
337
|
-
//#region src/component/component-init-path.d.ts
|
|
338
|
-
/**
|
|
339
|
-
* Get component flag from init path
|
|
340
|
-
* @param initPath The init path of the function component
|
|
341
|
-
* @returns The component flag
|
|
342
|
-
*/
|
|
343
|
-
declare function getComponentFlagFromInitPath(initPath: FunctionComponentSemanticNode["initPath"]): bigint;
|
|
344
|
-
//#endregion
|
|
345
|
-
//#region src/component/component-is.d.ts
|
|
309
|
+
//#region src/component/component-detection-legacy.d.ts
|
|
346
310
|
/**
|
|
347
311
|
* Check if a node is a React class component
|
|
348
312
|
* @param node The AST node to check
|
|
@@ -355,22 +319,6 @@ declare function isClassComponent(node: TSESTree.Node): node is ast.TSESTreeClas
|
|
|
355
319
|
* @returns `true` if the node is a PureComponent, `false` otherwise
|
|
356
320
|
*/
|
|
357
321
|
declare function isPureComponent(node: TSESTree.Node): boolean;
|
|
358
|
-
//#endregion
|
|
359
|
-
//#region src/component/component-method-callback.d.ts
|
|
360
|
-
/**
|
|
361
|
-
* Check if the given node is a componentDidMount callback
|
|
362
|
-
* @param node The node to check
|
|
363
|
-
* @returns True if the node is a componentDidMount callback, false otherwise
|
|
364
|
-
*/
|
|
365
|
-
declare function isComponentDidMountCallback(node: TSESTree.Node): boolean;
|
|
366
|
-
/**
|
|
367
|
-
* Check if the given node is a componentWillUnmount callback
|
|
368
|
-
* @param node The node to check
|
|
369
|
-
* @returns True if the node is a componentWillUnmount callback, false otherwise
|
|
370
|
-
*/
|
|
371
|
-
declare function isComponentWillUnmountCallback(node: TSESTree.Node): boolean;
|
|
372
|
-
//#endregion
|
|
373
|
-
//#region src/component/component-method-is.d.ts
|
|
374
322
|
declare const isRender: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
375
323
|
declare const isComponentDidCatch: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
376
324
|
declare const isComponentDidMount: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
@@ -389,28 +337,18 @@ declare const isUnsafeComponentWillUpdate: (node: TSESTree.Node) => node is ast.
|
|
|
389
337
|
declare const isGetDefaultProps: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
390
338
|
declare const isGetDerivedStateFromProps: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
391
339
|
declare const isGetDerivedStateFromError: (node: TSESTree.Node) => node is ast.TSESTreeMethodOrProperty;
|
|
392
|
-
//#endregion
|
|
393
|
-
//#region src/component/component-name.d.ts
|
|
394
|
-
/**
|
|
395
|
-
* Check if a string matches the strict component name pattern
|
|
396
|
-
* @param name The name to check
|
|
397
|
-
*/
|
|
398
|
-
declare function isComponentName(name: string): boolean;
|
|
399
340
|
/**
|
|
400
|
-
* Check if
|
|
401
|
-
* @param
|
|
341
|
+
* Check if the given node is a componentDidMount callback
|
|
342
|
+
* @param node The node to check
|
|
343
|
+
* @returns True if the node is a componentDidMount callback, false otherwise
|
|
402
344
|
*/
|
|
403
|
-
declare function
|
|
345
|
+
declare function isComponentDidMountCallback(node: TSESTree.Node): boolean;
|
|
404
346
|
/**
|
|
405
|
-
* Check if
|
|
406
|
-
* @param
|
|
407
|
-
* @
|
|
408
|
-
* @param allowNone Whether to allow no name
|
|
409
|
-
* @returns Whether the function has a loose component name
|
|
347
|
+
* Check if the given node is a componentWillUnmount callback
|
|
348
|
+
* @param node The node to check
|
|
349
|
+
* @returns True if the node is a componentWillUnmount callback, false otherwise
|
|
410
350
|
*/
|
|
411
|
-
declare function
|
|
412
|
-
//#endregion
|
|
413
|
-
//#region src/component/component-render-method.d.ts
|
|
351
|
+
declare function isComponentWillUnmountCallback(node: TSESTree.Node): boolean;
|
|
414
352
|
/**
|
|
415
353
|
* Check whether given node is a render method of a class component
|
|
416
354
|
* @example
|
|
@@ -424,57 +362,79 @@ declare function isFunctionWithLooseComponentName(context: RuleContext, fn: ast.
|
|
|
424
362
|
* @returns `true` if node is a render function, `false` if not
|
|
425
363
|
*/
|
|
426
364
|
declare function isRenderMethodLike(node: TSESTree.Node): node is ast.TSESTreeMethodOrProperty;
|
|
427
|
-
//#endregion
|
|
428
|
-
//#region src/component/component-render-prop.d.ts
|
|
429
365
|
/**
|
|
430
|
-
*
|
|
366
|
+
* Check if the given node is a function within a render method of a class component
|
|
367
|
+
*
|
|
368
|
+
* @param node The AST node to check
|
|
369
|
+
* @returns `true` if the node is a render function inside a class component
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
431
372
|
* ```tsx
|
|
432
|
-
*
|
|
433
|
-
*
|
|
434
|
-
*
|
|
435
|
-
* ` ^^^^^^^^^^^^^ `
|
|
373
|
+
* class Component extends React.Component {
|
|
374
|
+
* renderHeader = () => <div />; // Returns true
|
|
375
|
+
* }
|
|
436
376
|
* ```
|
|
437
|
-
* @param context The rule context
|
|
438
|
-
* @param node The AST node to check
|
|
439
|
-
* @returns `true` if node is a render function, `false` if not
|
|
440
377
|
*/
|
|
441
|
-
declare function
|
|
378
|
+
declare function isRenderMethodCallback(node: ast.TSESTreeFunction): boolean;
|
|
442
379
|
/**
|
|
443
|
-
*
|
|
444
|
-
*
|
|
445
|
-
*
|
|
446
|
-
* ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
|
|
447
|
-
* ```
|
|
448
|
-
* @param context The rule context
|
|
449
|
-
* @param node The AST node to check
|
|
450
|
-
* @returns `true` if node is a render prop, `false` if not
|
|
380
|
+
* Check whether the given node is a this.setState() call
|
|
381
|
+
* @param node The node to check
|
|
382
|
+
* @internal
|
|
451
383
|
*/
|
|
452
|
-
declare function
|
|
384
|
+
declare function isThisSetState(node: TSESTree.CallExpression): boolean;
|
|
453
385
|
/**
|
|
454
|
-
*
|
|
455
|
-
*
|
|
456
|
-
* const rows = { render: () => <div /> }
|
|
457
|
-
* ` ^^^^^^^^^^^^^ `
|
|
458
|
-
* _ = <Component rows={ [{ render: () => <div /> }] } />
|
|
459
|
-
* ` ^^^^^^^^^^^^^ `
|
|
460
|
-
* ```
|
|
386
|
+
* Check whether the given node is an assignment to this.state
|
|
387
|
+
* @param node The node to check
|
|
461
388
|
* @internal
|
|
462
|
-
* @param node The AST node to check
|
|
463
|
-
* @returns `true` if component is declared inside a render property, `false` if not
|
|
464
389
|
*/
|
|
465
|
-
declare function
|
|
390
|
+
declare function isAssignmentToThisState(node: TSESTree.AssignmentExpression): boolean;
|
|
391
|
+
//#endregion
|
|
392
|
+
//#region src/component/component-flag.d.ts
|
|
466
393
|
/**
|
|
467
|
-
*
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
394
|
+
* Component flag constants
|
|
395
|
+
*/
|
|
396
|
+
declare const ComponentFlag: {
|
|
397
|
+
/** Indicates the component creates elements using `createElement` instead of JSX */CreateElement: bigint; /** Indicates the component forwards a ref (ex: React.forwardRef) */
|
|
398
|
+
ForwardRef: bigint; /** Indicates the component is memoized (ex: React.memo) */
|
|
399
|
+
Memo: bigint; /** No flags set */
|
|
400
|
+
None: bigint; /** Indicates the component is a pure component (ex: extends PureComponent) */
|
|
401
|
+
PureComponent: bigint;
|
|
402
|
+
};
|
|
403
|
+
/**
|
|
404
|
+
* Get component flag from init path
|
|
405
|
+
* @param initPath The init path of the function component
|
|
406
|
+
* @returns The component flag
|
|
407
|
+
*/
|
|
408
|
+
declare function getComponentFlagFromInitPath(initPath: FunctionComponentSemanticNode["initPath"]): bigint;
|
|
409
|
+
//#endregion
|
|
410
|
+
//#region src/component/component-id.d.ts
|
|
411
|
+
/**
|
|
412
|
+
* Get function component identifier from `const Component = memo(() => {});`
|
|
413
|
+
* @param context The rule context
|
|
414
|
+
* @param node The function node to analyze
|
|
415
|
+
* @returns The function identifier or `null` if not found
|
|
416
|
+
*/
|
|
417
|
+
declare function getFunctionComponentId(context: RuleContext, node: ast.TSESTreeFunction): ast.FunctionID;
|
|
418
|
+
//#endregion
|
|
419
|
+
//#region src/component/component-name.d.ts
|
|
420
|
+
/**
|
|
421
|
+
* Check if a string matches the strict component name pattern
|
|
422
|
+
* @param name The name to check
|
|
423
|
+
*/
|
|
424
|
+
declare function isComponentName(name: string): boolean;
|
|
425
|
+
/**
|
|
426
|
+
* Check if a string matches the loose component name pattern
|
|
427
|
+
* @param name The name to check
|
|
476
428
|
*/
|
|
477
|
-
declare function
|
|
429
|
+
declare function isComponentNameLoose(name: string): boolean;
|
|
430
|
+
/**
|
|
431
|
+
* Check if a function has a loose component name
|
|
432
|
+
* @param context The rule context
|
|
433
|
+
* @param fn The function to check
|
|
434
|
+
* @param allowNone Whether to allow no name
|
|
435
|
+
* @returns Whether the function has a loose component name
|
|
436
|
+
*/
|
|
437
|
+
declare function isFunctionWithLooseComponentName(context: RuleContext, fn: ast.TSESTreeFunction, allowNone?: boolean): boolean;
|
|
478
438
|
//#endregion
|
|
479
439
|
//#region src/component/component-wrapper.d.ts
|
|
480
440
|
/**
|
|
@@ -510,7 +470,7 @@ declare function isComponentWrapperCallbackLoose(context: RuleContext, node: TSE
|
|
|
510
470
|
/**
|
|
511
471
|
* Represents the kind of a React function
|
|
512
472
|
*/
|
|
513
|
-
type
|
|
473
|
+
type FunctionKind = "client-function" | "server-function";
|
|
514
474
|
//#endregion
|
|
515
475
|
//#region src/function/function-semantic-node.d.ts
|
|
516
476
|
/**
|
|
@@ -536,35 +496,17 @@ interface ServerFunctionSemanticNode extends SemanticFunc {
|
|
|
536
496
|
*/
|
|
537
497
|
type FunctionSemanticNode = ClientFunctionSemanticNode | ServerFunctionSemanticNode;
|
|
538
498
|
//#endregion
|
|
539
|
-
//#region src/hierarchy/find-enclosing-component-or-hook.d.ts
|
|
540
|
-
type FindEnclosingComponentOrHookFilter = (n: TSESTree.Node, name: string | null) => boolean;
|
|
541
|
-
/**
|
|
542
|
-
* Find the enclosing React component or hook for a given AST node
|
|
543
|
-
* @param node The AST node to start the search from
|
|
544
|
-
* @param test Optional test function to customize component or hook identification
|
|
545
|
-
* @returns The enclosing component or hook node, or `null` if none is ASAST.
|
|
546
|
-
*/
|
|
547
|
-
declare function findEnclosingComponentOrHook(node: TSESTree.Node | unit, test?: FindEnclosingComponentOrHookFilter): TSESTree.ArrowFunctionExpression | TSESTree.FunctionDeclarationWithName | TSESTree.FunctionDeclarationWithOptionalName | TSESTree.FunctionExpression | undefined;
|
|
548
|
-
//#endregion
|
|
549
|
-
//#region src/hierarchy/is-inside-component-or-hook.d.ts
|
|
550
|
-
/**
|
|
551
|
-
* Check if a given AST node is inside a React component or hook
|
|
552
|
-
* @param node The AST node to check
|
|
553
|
-
* @returns True if the node is inside a component or hook, false otherwise
|
|
554
|
-
*/
|
|
555
|
-
declare function isInsideComponentOrHook(node: TSESTree.Node | unit): boolean;
|
|
556
|
-
//#endregion
|
|
557
499
|
//#region src/hook/hook-callback.d.ts
|
|
558
500
|
/**
|
|
559
501
|
* Determine if a node is the setup function passed to a useEffect-like hook
|
|
560
502
|
* @param node The AST node to check
|
|
561
503
|
*/
|
|
562
|
-
declare function isUseEffectSetupCallback(node: TSESTree.Node |
|
|
504
|
+
declare function isUseEffectSetupCallback(node: TSESTree.Node | null): boolean;
|
|
563
505
|
/**
|
|
564
506
|
* Determine if a node is the cleanup function returned by a useEffect-like hook's setup function
|
|
565
507
|
* @param node The AST node to check
|
|
566
508
|
*/
|
|
567
|
-
declare function isUseEffectCleanupCallback(node: TSESTree.Node |
|
|
509
|
+
declare function isUseEffectCleanupCallback(node: TSESTree.Node | null): boolean;
|
|
568
510
|
//#endregion
|
|
569
511
|
//#region src/hook/hook-semantic-node.d.ts
|
|
570
512
|
/**
|
|
@@ -573,14 +515,14 @@ declare function isUseEffectCleanupCallback(node: TSESTree.Node | unit): boolean
|
|
|
573
515
|
*/
|
|
574
516
|
interface HookSemanticNode extends SemanticNode {
|
|
575
517
|
/** The identifier of the hook */
|
|
576
|
-
id: ast.FunctionID
|
|
518
|
+
id: ast.FunctionID;
|
|
577
519
|
/** The AST node of the hook */
|
|
578
520
|
node: ast.TSESTreeFunction;
|
|
579
521
|
/** The name of the hook */
|
|
580
522
|
name: string;
|
|
581
523
|
/** The other hooks called by the hook */
|
|
582
524
|
hookCalls: TSESTree.CallExpression[];
|
|
583
|
-
/** The directives used in the function (
|
|
525
|
+
/** The directives used in the function (ex: "use strict", "use client", etc.) */
|
|
584
526
|
directives: TSESTree.StringLiteral[];
|
|
585
527
|
}
|
|
586
528
|
//#endregion
|
|
@@ -594,7 +536,7 @@ declare namespace useHookCollector {
|
|
|
594
536
|
ctx: {
|
|
595
537
|
getAllHooks(node: TSESTree$1.Program): HookSemanticNode[];
|
|
596
538
|
getCurrentEntries(): FunctionEntry[];
|
|
597
|
-
getCurrentEntry(): FunctionEntry |
|
|
539
|
+
getCurrentEntry(): FunctionEntry | null;
|
|
598
540
|
};
|
|
599
541
|
visitor: ESLintUtils.RuleListener;
|
|
600
542
|
};
|
|
@@ -620,53 +562,53 @@ declare function isHookId(id: TSESTree.Node): id is TSESTree.Identifier | TSESTr
|
|
|
620
562
|
* @param node The function node to check
|
|
621
563
|
* @returns True if the function is a React Hook, false otherwise
|
|
622
564
|
*/
|
|
623
|
-
declare function isHook(node: ast.TSESTreeFunction |
|
|
565
|
+
declare function isHook(node: ast.TSESTreeFunction | null): boolean;
|
|
624
566
|
/**
|
|
625
567
|
* Check if the given node is a React Hook call by its name.
|
|
626
568
|
* @param node The node to check.
|
|
627
569
|
* @returns `true` if the node is a React Hook call, `false` otherwise.
|
|
628
570
|
*/
|
|
629
|
-
declare function isHookCall(node: TSESTree.Node |
|
|
571
|
+
declare function isHookCall(node: TSESTree.Node | null): node is TSESTree.CallExpression;
|
|
630
572
|
/**
|
|
631
573
|
* Check if a node is a call to a specific React hook.
|
|
632
574
|
* Returns a function that accepts a hook name to check against.
|
|
633
575
|
* @param node The AST node to check
|
|
634
576
|
* @returns A function that takes a hook name and returns boolean
|
|
635
577
|
*/
|
|
636
|
-
declare function isHookCallWithName(node: TSESTree.Node |
|
|
578
|
+
declare function isHookCallWithName(node: TSESTree.Node | null): (name: string) => boolean;
|
|
637
579
|
/**
|
|
638
580
|
* Detect useEffect calls and variations (useLayoutEffect, etc.) using a regex pattern
|
|
639
581
|
* @param node The AST node to check
|
|
640
582
|
* @param additionalEffectHooks Regex pattern matching custom hooks that should be treated as effect hooks
|
|
641
583
|
* @returns True if the node is a useEffect-like call
|
|
642
584
|
*/
|
|
643
|
-
declare function isUseEffectLikeCall(node: TSESTree.Node |
|
|
585
|
+
declare function isUseEffectLikeCall(node: TSESTree.Node | null, additionalEffectHooks?: RegExpLike): node is TSESTree.CallExpression;
|
|
644
586
|
/**
|
|
645
587
|
* Detect useState calls and variations (useCustomState, etc.) using a regex pattern
|
|
646
588
|
* @param node The AST node to check
|
|
647
589
|
* @param additionalStateHooks Regex pattern matching custom hooks that should be treated as state hooks
|
|
648
590
|
* @returns True if the node is a useState-like call
|
|
649
591
|
*/
|
|
650
|
-
declare function isUseStateLikeCall(node: TSESTree.Node |
|
|
651
|
-
declare const isUseCall: (node: TSESTree.Node |
|
|
652
|
-
declare const isUseActionStateCall: (node: TSESTree.Node |
|
|
653
|
-
declare const isUseCallbackCall: (node: TSESTree.Node |
|
|
654
|
-
declare const isUseContextCall: (node: TSESTree.Node |
|
|
655
|
-
declare const isUseDebugValueCall: (node: TSESTree.Node |
|
|
656
|
-
declare const isUseDeferredValueCall: (node: TSESTree.Node |
|
|
657
|
-
declare const isUseEffectCall: (node: TSESTree.Node |
|
|
658
|
-
declare const isUseFormStatusCall: (node: TSESTree.Node |
|
|
659
|
-
declare const isUseIdCall: (node: TSESTree.Node |
|
|
660
|
-
declare const isUseImperativeHandleCall: (node: TSESTree.Node |
|
|
661
|
-
declare const isUseInsertionEffectCall: (node: TSESTree.Node |
|
|
662
|
-
declare const isUseLayoutEffectCall: (node: TSESTree.Node |
|
|
663
|
-
declare const isUseMemoCall: (node: TSESTree.Node |
|
|
664
|
-
declare const isUseOptimisticCall: (node: TSESTree.Node |
|
|
665
|
-
declare const isUseReducerCall: (node: TSESTree.Node |
|
|
666
|
-
declare const isUseRefCall: (node: TSESTree.Node |
|
|
667
|
-
declare const isUseStateCall: (node: TSESTree.Node |
|
|
668
|
-
declare const isUseSyncExternalStoreCall: (node: TSESTree.Node |
|
|
669
|
-
declare const isUseTransitionCall: (node: TSESTree.Node |
|
|
592
|
+
declare function isUseStateLikeCall(node: TSESTree.Node | null, additionalStateHooks?: RegExpLike): node is TSESTree.CallExpression;
|
|
593
|
+
declare const isUseCall: (node: TSESTree.Node | null) => boolean;
|
|
594
|
+
declare const isUseActionStateCall: (node: TSESTree.Node | null) => boolean;
|
|
595
|
+
declare const isUseCallbackCall: (node: TSESTree.Node | null) => boolean;
|
|
596
|
+
declare const isUseContextCall: (node: TSESTree.Node | null) => boolean;
|
|
597
|
+
declare const isUseDebugValueCall: (node: TSESTree.Node | null) => boolean;
|
|
598
|
+
declare const isUseDeferredValueCall: (node: TSESTree.Node | null) => boolean;
|
|
599
|
+
declare const isUseEffectCall: (node: TSESTree.Node | null) => boolean;
|
|
600
|
+
declare const isUseFormStatusCall: (node: TSESTree.Node | null) => boolean;
|
|
601
|
+
declare const isUseIdCall: (node: TSESTree.Node | null) => boolean;
|
|
602
|
+
declare const isUseImperativeHandleCall: (node: TSESTree.Node | null) => boolean;
|
|
603
|
+
declare const isUseInsertionEffectCall: (node: TSESTree.Node | null) => boolean;
|
|
604
|
+
declare const isUseLayoutEffectCall: (node: TSESTree.Node | null) => boolean;
|
|
605
|
+
declare const isUseMemoCall: (node: TSESTree.Node | null) => boolean;
|
|
606
|
+
declare const isUseOptimisticCall: (node: TSESTree.Node | null) => boolean;
|
|
607
|
+
declare const isUseReducerCall: (node: TSESTree.Node | null) => boolean;
|
|
608
|
+
declare const isUseRefCall: (node: TSESTree.Node | null) => boolean;
|
|
609
|
+
declare const isUseStateCall: (node: TSESTree.Node | null) => boolean;
|
|
610
|
+
declare const isUseSyncExternalStoreCall: (node: TSESTree.Node | null) => boolean;
|
|
611
|
+
declare const isUseTransitionCall: (node: TSESTree.Node | null) => boolean;
|
|
670
612
|
//#endregion
|
|
671
613
|
//#region src/hook/hook-name.d.ts
|
|
672
614
|
declare const REACT_BUILTIN_HOOK_NAMES: readonly ["use", "useActionState", "useCallback", "useContext", "useDebugValue", "useDeferredValue", "useEffect", "useFormStatus", "useId", "useImperativeHandle", "useInsertionEffect", "useLayoutEffect", "useMemo", "useOptimistic", "useReducer", "useRef", "useState", "useSyncExternalStore", "useTransition"];
|
|
@@ -678,36 +620,21 @@ declare const REACT_BUILTIN_HOOK_NAMES: readonly ["use", "useActionState", "useC
|
|
|
678
620
|
*/
|
|
679
621
|
declare function isHookName(name: string): boolean;
|
|
680
622
|
//#endregion
|
|
681
|
-
//#region src/jsx/jsx-attribute.d.ts
|
|
682
|
-
/**
|
|
683
|
-
* Creates a helper function to find a specific JSX attribute by name
|
|
684
|
-
* Handles direct attributes and spread attributes (variables or object literals)
|
|
685
|
-
* @param context The ESLint rule context
|
|
686
|
-
* @param node The JSX element node
|
|
687
|
-
* @param initialScope (Optional) The initial scope to use for variable resolution
|
|
688
|
-
*/
|
|
689
|
-
declare function getJsxAttribute(context: RuleContext, node: TSESTree.JSXElement, initialScope?: Scope): (name: string) => TSESTree.JSXAttribute | TSESTree.JSXSpreadAttribute | undefined;
|
|
690
|
-
//#endregion
|
|
691
|
-
//#region src/jsx/jsx-attribute-name.d.ts
|
|
692
|
-
/**
|
|
693
|
-
* Get the stringified name of a JSX attribute
|
|
694
|
-
* @param context The ESLint rule context
|
|
695
|
-
* @param node The JSX attribute node
|
|
696
|
-
* @returns The name of the attribute
|
|
697
|
-
*/
|
|
698
|
-
declare function getJsxAttributeName(context: RuleContext, node: TSESTree$1.JSXAttribute): string;
|
|
699
|
-
//#endregion
|
|
700
623
|
//#region src/jsx/jsx-attribute-value.d.ts
|
|
701
624
|
/**
|
|
702
625
|
* Represents possible JSX attribute value types that can be resolved
|
|
703
626
|
*/
|
|
704
627
|
type JsxAttributeValue = {
|
|
628
|
+
kind: "missing";
|
|
629
|
+
node: TSESTree.JSXEmptyExpression;
|
|
630
|
+
toStatic(): null;
|
|
631
|
+
} | {
|
|
705
632
|
kind: "boolean";
|
|
706
633
|
toStatic(): true;
|
|
707
634
|
} | {
|
|
708
635
|
kind: "element";
|
|
709
636
|
node: TSESTree.JSXElement;
|
|
710
|
-
toStatic():
|
|
637
|
+
toStatic(): null;
|
|
711
638
|
} | {
|
|
712
639
|
kind: "literal";
|
|
713
640
|
node: TSESTree.Literal;
|
|
@@ -718,44 +645,14 @@ type JsxAttributeValue = {
|
|
|
718
645
|
toStatic(): unknown;
|
|
719
646
|
} | {
|
|
720
647
|
kind: "spreadProps";
|
|
648
|
+
getProperty(name: string): unknown;
|
|
721
649
|
node: TSESTree.JSXSpreadAttribute["argument"];
|
|
722
|
-
toStatic(
|
|
650
|
+
toStatic(): null;
|
|
723
651
|
} | {
|
|
724
652
|
kind: "spreadChild";
|
|
653
|
+
getChildren(at: number): unknown;
|
|
725
654
|
node: TSESTree.JSXSpreadChild["expression"];
|
|
726
|
-
toStatic():
|
|
727
|
-
};
|
|
728
|
-
/**
|
|
729
|
-
* Resolve the static value of a JSX attribute or spread attribute
|
|
730
|
-
*
|
|
731
|
-
* @param context - The ESLint rule context
|
|
732
|
-
* @param attribute - The JSX attribute node to resolve
|
|
733
|
-
* @returns An object containing the value kind, the node (if applicable), and a `toStatic` helper
|
|
734
|
-
*/
|
|
735
|
-
declare function resolveJsxAttributeValue(context: RuleContext, attribute: ast.TSESTreeJSXAttributeLike): {
|
|
736
|
-
readonly kind: "boolean";
|
|
737
|
-
readonly toStatic: () => true;
|
|
738
|
-
readonly node?: never;
|
|
739
|
-
} | {
|
|
740
|
-
readonly kind: "literal";
|
|
741
|
-
readonly node: TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral;
|
|
742
|
-
readonly toStatic: () => string | number | bigint | boolean | RegExp | null;
|
|
743
|
-
} | {
|
|
744
|
-
readonly kind: "expression";
|
|
745
|
-
readonly node: TSESTree.JSXEmptyExpression | TSESTree.Expression;
|
|
746
|
-
readonly toStatic: () => unknown;
|
|
747
|
-
} | {
|
|
748
|
-
readonly kind: "element";
|
|
749
|
-
readonly node: TSESTree.JSXElement;
|
|
750
|
-
readonly toStatic: () => undefined;
|
|
751
|
-
} | {
|
|
752
|
-
readonly kind: "spreadChild";
|
|
753
|
-
readonly node: TSESTree.JSXEmptyExpression | TSESTree.Expression;
|
|
754
|
-
readonly toStatic: () => undefined;
|
|
755
|
-
} | {
|
|
756
|
-
readonly kind: "spreadProps";
|
|
757
|
-
readonly node: TSESTree.Expression;
|
|
758
|
-
readonly toStatic: (name?: string) => unknown;
|
|
655
|
+
toStatic(): null;
|
|
759
656
|
};
|
|
760
657
|
//#endregion
|
|
761
658
|
//#region src/jsx/jsx-config.d.ts
|
|
@@ -815,81 +712,206 @@ declare const JsxDetectionHint: {
|
|
|
815
712
|
* Skips undefined and boolean literals (common in React)
|
|
816
713
|
*/
|
|
817
714
|
declare const DEFAULT_JSX_DETECTION_HINT: bigint;
|
|
818
|
-
/**
|
|
819
|
-
* Check if a node is a `JSXText` or a `Literal` node
|
|
820
|
-
* @param node The AST node to check
|
|
821
|
-
* @returns `true` if the node is a `JSXText` or a `Literal` node
|
|
822
|
-
*/
|
|
823
|
-
declare function isJsxText(node: TSESTree$1.Node | null | unit): node is TSESTree$1.JSXText | TSESTree$1.Literal;
|
|
824
715
|
/**
|
|
825
716
|
* Determine if a node represents JSX-like content based on heuristics
|
|
826
717
|
* Supports configuration through hint flags to customize detection behavior
|
|
827
718
|
*
|
|
828
|
-
* @param
|
|
829
|
-
* @param code.getScope The function to get the scope of a node
|
|
719
|
+
* @param context The rule context with scope lookup capability
|
|
830
720
|
* @param node The AST node to analyze
|
|
831
721
|
* @param hint The configuration flags to adjust detection behavior
|
|
832
722
|
* @returns boolean Whether the node is considered JSX-like
|
|
833
723
|
*/
|
|
834
|
-
declare function isJsxLike(
|
|
835
|
-
getScope: (node: TSESTree$1.Node) => Scope;
|
|
836
|
-
}, node: TSESTree$1.Node | unit | null, hint?: JsxDetectionHint): boolean;
|
|
724
|
+
declare function isJsxLike(context: RuleContext, node: TSESTree$1.Node | null, hint?: JsxDetectionHint): boolean;
|
|
837
725
|
//#endregion
|
|
838
|
-
//#region src/jsx/jsx-
|
|
726
|
+
//#region src/jsx/jsx-inspector.d.ts
|
|
839
727
|
/**
|
|
840
|
-
*
|
|
841
|
-
*
|
|
728
|
+
* A stateful helper that binds an ESLint `RuleContext` once and exposes
|
|
729
|
+
* ergonomic methods for the most common JSX inspection tasks that rules need.
|
|
842
730
|
*
|
|
843
|
-
*
|
|
844
|
-
* @param node AST node to check
|
|
845
|
-
* @returns boolean indicating if the element is a host element
|
|
846
|
-
*/
|
|
847
|
-
declare function isJsxHostElement(context: RuleContext, node: TSESTree.Node): boolean;
|
|
848
|
-
/**
|
|
849
|
-
* Determine if a JSX element is a React Fragment
|
|
850
|
-
* Fragments can be imported from React and used like <Fragment> or <React.Fragment>
|
|
731
|
+
* ### Typical usage inside a rule's `create` function
|
|
851
732
|
*
|
|
852
|
-
*
|
|
853
|
-
*
|
|
854
|
-
*
|
|
855
|
-
* @param jsxConfig.jsxFragmentFactory Name of the fragment factory (e.g., React.Fragment)
|
|
856
|
-
* @returns boolean indicating if the element is a Fragment
|
|
857
|
-
*/
|
|
858
|
-
declare function isJsxFragmentElement(context: RuleContext, node: TSESTree.Node, jsxConfig?: Pick<JsxConfig, "jsxFragmentFactory">): boolean;
|
|
859
|
-
//#endregion
|
|
860
|
-
//#region src/jsx/jsx-element-type.d.ts
|
|
861
|
-
/**
|
|
862
|
-
* Extracts the element type name from a JSX element or fragment
|
|
863
|
-
* For JSX elements, returns the stringified name (e.g., "div", "Button", "React.Fragment")
|
|
864
|
-
* For JSX fragments, returns an empty string
|
|
733
|
+
* ```ts
|
|
734
|
+
* export function create(context: RuleContext) {
|
|
735
|
+
* const jsx = JsxInspector.from(context);
|
|
865
736
|
*
|
|
866
|
-
*
|
|
867
|
-
*
|
|
868
|
-
*
|
|
869
|
-
|
|
870
|
-
declare function getJsxElementType(context: RuleContext, node: TSESTree.JSXElement | TSESTree.JSXFragment): string;
|
|
871
|
-
//#endregion
|
|
872
|
-
//#region src/jsx/jsx-hierarchy.d.ts
|
|
873
|
-
/**
|
|
874
|
-
* Traverses up the AST to find a parent JSX attribute node that matches a given test
|
|
737
|
+
* return defineRuleListener({
|
|
738
|
+
* JSXElement(node) {
|
|
739
|
+
* // element type
|
|
740
|
+
* const type = jsx.getElementType(node); // "div" | "React.Fragment" | …
|
|
875
741
|
*
|
|
876
|
-
*
|
|
877
|
-
*
|
|
878
|
-
*
|
|
879
|
-
* @returns The first matching JSX attribute node found when traversing upwards, or undefined
|
|
880
|
-
*/
|
|
881
|
-
declare function findParentJsxAttribute(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | unit;
|
|
882
|
-
//#endregion
|
|
883
|
-
//#region src/jsx/jsx-stringify.d.ts
|
|
884
|
-
/**
|
|
885
|
-
* Incomplete but sufficient stringification of JSX nodes for common use cases
|
|
742
|
+
* // attribute lookup + value resolution in one step
|
|
743
|
+
* const val = jsx.getAttributeValue(node, "sandbox");
|
|
744
|
+
* if (typeof val?.getStatic() === "string") { … }
|
|
886
745
|
*
|
|
887
|
-
*
|
|
888
|
-
*
|
|
746
|
+
* // simple boolean checks
|
|
747
|
+
* if (jsx.isHostElement(node)) { … }
|
|
748
|
+
* if (jsx.isFragmentElement(node)) { … }
|
|
749
|
+
* if (jsx.hasAttribute(node, "key")) { … }
|
|
750
|
+
* },
|
|
751
|
+
* });
|
|
752
|
+
* }
|
|
753
|
+
* ```
|
|
889
754
|
*/
|
|
890
|
-
declare
|
|
755
|
+
declare class JsxInspector {
|
|
756
|
+
#private;
|
|
757
|
+
readonly context: RuleContext;
|
|
758
|
+
/**
|
|
759
|
+
* Merged JSX configuration (tsconfig compiler options + pragma annotations).
|
|
760
|
+
* The result is lazily computed and cached for the lifetime of this inspector.
|
|
761
|
+
*/
|
|
762
|
+
get jsxConfig(): Required<JsxConfig>;
|
|
763
|
+
private constructor();
|
|
764
|
+
/**
|
|
765
|
+
* Walk **up** the AST from `node` to find the nearest ancestor that is a
|
|
766
|
+
* `JSXAttribute` and passes the optional `test` predicate.
|
|
767
|
+
* @param node The starting node for the search.
|
|
768
|
+
* @param test A predicate function to test each ancestor node.
|
|
769
|
+
*/
|
|
770
|
+
static findParentAttribute(node: TSESTree.Node, test?: (node: TSESTree.JSXAttribute) => boolean): TSESTree.JSXAttribute | null;
|
|
771
|
+
/**
|
|
772
|
+
* Create a new `JsxInspector` bound to the given rule context.
|
|
773
|
+
* @param context The ESLint rule context to bind to this inspector instance.
|
|
774
|
+
*/
|
|
775
|
+
static from(context: RuleContext): JsxInspector;
|
|
776
|
+
/**
|
|
777
|
+
* Whether the node is a `JSXText` or a `Literal` node.
|
|
778
|
+
* @param node The node to check.
|
|
779
|
+
*/
|
|
780
|
+
static isJsxText(node: TSESTree.Node | null): node is TSESTree.JSXText | TSESTree.Literal;
|
|
781
|
+
/**
|
|
782
|
+
* Find a JSX attribute (or spread attribute containing the property) by name
|
|
783
|
+
* on a given element.
|
|
784
|
+
*
|
|
785
|
+
* Returns the **last** matching attribute (to mirror React's behaviour where
|
|
786
|
+
* later props win), or `undefined` if not found.
|
|
787
|
+
* @param node The JSX element to search for the attribute.
|
|
788
|
+
* @param name The name of the attribute to find (ex: `"className"`).
|
|
789
|
+
*/
|
|
790
|
+
findAttribute(node: TSESTree.JSXElement, name: string): ast.TSESTreeJSXAttributeLike | undefined;
|
|
791
|
+
/**
|
|
792
|
+
* Get the stringified name of a `JSXAttribute` node
|
|
793
|
+
* (ex: `"className"`, `"aria-label"`, `"xml:space"`).
|
|
794
|
+
* @param node The `JSXAttribute` node to extract the name from.
|
|
795
|
+
* @returns The stringified name of the attribute.
|
|
796
|
+
*/
|
|
797
|
+
getAttributeName(node: TSESTree.JSXAttribute): string;
|
|
798
|
+
/**
|
|
799
|
+
* Resolve the static value of an attribute, automatically handling the
|
|
800
|
+
* `spreadProps` case by extracting the named property.
|
|
801
|
+
*
|
|
802
|
+
* This eliminates the repetitive pattern:
|
|
803
|
+
* ```ts
|
|
804
|
+
* const v = core.resolveJsxAttributeValue(ctx, attr);
|
|
805
|
+
* const s = v.kind === "spreadProps" ? v.getProperty(name) : v.toStatic();
|
|
806
|
+
* ```
|
|
807
|
+
*
|
|
808
|
+
* Returns `undefined` when the attribute is not present or its value
|
|
809
|
+
* cannot be statically determined.
|
|
810
|
+
* @param node The JSX element to search for the attribute.
|
|
811
|
+
* @param name The name of the attribute to resolve (ex: `"className"`).
|
|
812
|
+
* @returns The static value of the attribute, or `undefined` if not found or not statically resolvable.
|
|
813
|
+
*/
|
|
814
|
+
getAttributeStaticValue(node: TSESTree.JSXElement, name: string): unknown;
|
|
815
|
+
/**
|
|
816
|
+
* **All-in-one helper** – find an attribute by name on an element *and*
|
|
817
|
+
* resolve its value in a single call.
|
|
818
|
+
*
|
|
819
|
+
* Returns `undefined` when the attribute is not present.
|
|
820
|
+
* @param node The JSX element to search for the attribute.
|
|
821
|
+
* @param name The name of the attribute to find and resolve (ex: `"className"`).
|
|
822
|
+
* @returns A descriptor of the attribute's value that can be further inspected, or `undefined` if the attribute is not found.
|
|
823
|
+
*/
|
|
824
|
+
getAttributeValue(node: TSESTree.JSXElement, name: string): JsxAttributeValue | undefined;
|
|
825
|
+
/**
|
|
826
|
+
* Get the **self name** (last segment) of a JSX element type.
|
|
827
|
+
*
|
|
828
|
+
* - `<Foo.Bar.Baz>` → `"Baz"`
|
|
829
|
+
* - `<div>` → `"div"`
|
|
830
|
+
* - `<></>` → `""`
|
|
831
|
+
* @param node The JSX element or fragment to extract the self name from.
|
|
832
|
+
*/
|
|
833
|
+
getElementSelfName(node: TSESTree.JSXElement | TSESTree.JSXFragment): string;
|
|
834
|
+
/**
|
|
835
|
+
* Get the string representation of a JSX element's type.
|
|
836
|
+
*
|
|
837
|
+
* - `<div>` → `"div"`
|
|
838
|
+
* - `<Foo.Bar>` → `"Foo.Bar"`
|
|
839
|
+
* - `<React.Fragment>` → `"React.Fragment"`
|
|
840
|
+
* - `<></>` (JSXFragment) → `""`
|
|
841
|
+
* @param node The JSX element or fragment to extract the type from.
|
|
842
|
+
*/
|
|
843
|
+
getElementType(node: TSESTree.JSXElement | TSESTree.JSXFragment): string;
|
|
844
|
+
/**
|
|
845
|
+
* Shorthand: check whether an attribute exists on the element.
|
|
846
|
+
* @param node The JSX element to check for the attribute.
|
|
847
|
+
* @param name The name of the attribute to check for (ex: `"className"`).
|
|
848
|
+
* @returns `true` if the attribute exists on the element, `false` otherwise.
|
|
849
|
+
*/
|
|
850
|
+
hasAttribute(node: TSESTree.JSXElement, name: string): boolean;
|
|
851
|
+
/**
|
|
852
|
+
* Whether the node is a React **Fragment** element (either `<Fragment>` /
|
|
853
|
+
* `<React.Fragment>` or the shorthand `<>` syntax).
|
|
854
|
+
*
|
|
855
|
+
* The check honours the configured `jsxFragmentFactory`.
|
|
856
|
+
* @param node The node to check.
|
|
857
|
+
*/
|
|
858
|
+
isFragmentElement(node: TSESTree.Node): node is TSESTree.JSXElement | TSESTree.JSXFragment;
|
|
859
|
+
/**
|
|
860
|
+
* Whether the node is a **host** (intrinsic / DOM) element – i.e. its tag
|
|
861
|
+
* name starts with a lowercase letter.
|
|
862
|
+
* @param node The node to check.
|
|
863
|
+
*/
|
|
864
|
+
isHostElement(node: TSESTree.Node): node is TSESTree.JSXElement;
|
|
865
|
+
/**
|
|
866
|
+
* Resolve the *value* of a JSX attribute (or spread attribute) into a
|
|
867
|
+
* descriptor that can be inspected further.
|
|
868
|
+
*
|
|
869
|
+
* See {@link JsxAttributeValue} for the full set of `kind` discriminants.
|
|
870
|
+
* @param attribute The attribute node to resolve the value of.
|
|
871
|
+
* @returns A descriptor of the attribute's value that can be further inspected.
|
|
872
|
+
*/
|
|
873
|
+
resolveAttributeValue(attribute: ast.TSESTreeJSXAttributeLike): {
|
|
874
|
+
readonly kind: "boolean";
|
|
875
|
+
readonly toStatic: () => true;
|
|
876
|
+
readonly node?: never;
|
|
877
|
+
readonly getChildren?: never;
|
|
878
|
+
} | {
|
|
879
|
+
readonly kind: "literal";
|
|
880
|
+
readonly node: TSESTree.BigIntLiteral | TSESTree.BooleanLiteral | TSESTree.NullLiteral | TSESTree.NumberLiteral | TSESTree.RegExpLiteral | TSESTree.StringLiteral;
|
|
881
|
+
readonly toStatic: () => string | number | bigint | boolean | RegExp | null;
|
|
882
|
+
readonly getChildren?: never;
|
|
883
|
+
} | {
|
|
884
|
+
readonly kind: "missing";
|
|
885
|
+
readonly node: TSESTree.JSXEmptyExpression;
|
|
886
|
+
readonly toStatic: () => null;
|
|
887
|
+
readonly getChildren?: never;
|
|
888
|
+
} | {
|
|
889
|
+
readonly kind: "expression";
|
|
890
|
+
readonly node: TSESTree.Expression;
|
|
891
|
+
readonly toStatic: () => unknown;
|
|
892
|
+
readonly getChildren?: never;
|
|
893
|
+
} | {
|
|
894
|
+
readonly kind: "element";
|
|
895
|
+
readonly node: TSESTree.JSXElement;
|
|
896
|
+
readonly toStatic: () => null;
|
|
897
|
+
readonly getChildren?: never;
|
|
898
|
+
} | {
|
|
899
|
+
readonly kind: "spreadChild";
|
|
900
|
+
readonly node: TSESTree.JSXEmptyExpression | TSESTree.Expression;
|
|
901
|
+
readonly toStatic: () => null;
|
|
902
|
+
readonly getChildren: (_at: number) => null;
|
|
903
|
+
} | {
|
|
904
|
+
readonly kind: "spreadProps";
|
|
905
|
+
readonly node: TSESTree.Expression;
|
|
906
|
+
readonly toStatic: () => null;
|
|
907
|
+
readonly getProperty: (name: string) => unknown;
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
//#endregion
|
|
911
|
+
//#region src/ref/ref-id.d.ts
|
|
912
|
+
declare function isRefId(node: TSESTree.Expression | TSESTree.PrivateIdentifier): boolean;
|
|
891
913
|
//#endregion
|
|
892
|
-
//#region src/ref/
|
|
914
|
+
//#region src/ref/ref-init.d.ts
|
|
893
915
|
/**
|
|
894
916
|
* Check if the variable with the given name is initialized or derived from a ref
|
|
895
917
|
* @param name The variable name
|
|
@@ -901,9 +923,9 @@ declare function isInitializedFromRef(name: string, initialScope: Scope): boolea
|
|
|
901
923
|
* Get the init expression of a ref variable
|
|
902
924
|
* @param name The variable name
|
|
903
925
|
* @param initialScope The initial scope
|
|
904
|
-
* @returns The init expression node if the variable is derived from a ref, or
|
|
926
|
+
* @returns The init expression node if the variable is derived from a ref, or null otherwise
|
|
905
927
|
*/
|
|
906
|
-
declare function getRefInit(name: string, initialScope: Scope): TSESTree$1.Expression |
|
|
928
|
+
declare function getRefInit(name: string, initialScope: Scope): TSESTree$1.Expression | null;
|
|
907
929
|
//#endregion
|
|
908
930
|
//#region src/ref/ref-name.d.ts
|
|
909
931
|
/**
|
|
@@ -911,6 +933,6 @@ declare function getRefInit(name: string, initialScope: Scope): TSESTree$1.Expre
|
|
|
911
933
|
* @param name The name to check
|
|
912
934
|
* @returns True if the name is "ref" or ends with "Ref"
|
|
913
935
|
*/
|
|
914
|
-
declare function
|
|
936
|
+
declare function isRefLikeName(name: string): boolean;
|
|
915
937
|
//#endregion
|
|
916
|
-
export { ClassComponentSemanticNode, ClientFunctionSemanticNode, ComponentDetectionHint, ComponentFlag,
|
|
938
|
+
export { ClassComponentSemanticNode, ClientFunctionSemanticNode, ComponentDetectionHint, ComponentFlag, ComponentSemanticNode, DEFAULT_COMPONENT_DETECTION_HINT, DEFAULT_JSX_DETECTION_HINT, FunctionComponentSemanticNode, FunctionKind, FunctionSemanticNode, HookSemanticNode, JsxAttributeValue, JsxConfig, JsxDetectionHint, JsxEmit, JsxInspector, REACT_BUILTIN_HOOK_NAMES, SemanticFunc, SemanticNode, ServerFunctionSemanticNode, findImportSource, getComponentFlagFromInitPath, getFunctionComponentId, getJsxConfigFromAnnotation, getJsxConfigFromContext, getRefInit, isAssignmentToThisState, isCaptureOwnerStack, isCaptureOwnerStackCall, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCloneElement, isCloneElementCall, isComponentDefinition, isComponentDidCatch, isComponentDidMount, isComponentDidMountCallback, isComponentDidUpdate, isComponentName, isComponentNameLoose, isComponentWillMount, isComponentWillReceiveProps, isComponentWillUnmount, isComponentWillUnmountCallback, isComponentWillUpdate, isComponentWrapperCall, isComponentWrapperCallLoose, isComponentWrapperCallback, isComponentWrapperCallbackLoose, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isForwardRef, isForwardRefCall, isFunctionWithLooseComponentName, isGetChildContext, isGetDefaultProps, isGetDerivedStateFromError, isGetDerivedStateFromProps, isGetInitialState, isGetSnapshotBeforeUpdate, isHook, isHookCall, isHookCallWithName, isHookId, isHookName, isInitializedFromReact, isInitializedFromReactNative, isInitializedFromRef, isJsxLike, isLazy, isLazyCall, isMemo, isMemoCall, isPureComponent, isReactAPI, isReactAPICall, isRefId, isRefLikeName, isRender, isRenderMethodCallback, isRenderMethodLike, isShouldComponentUpdate, isThisSetState, isUnsafeComponentWillMount, isUnsafeComponentWillReceiveProps, isUnsafeComponentWillUpdate, isUseActionStateCall, isUseCall, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCleanupCallback, isUseEffectLikeCall, isUseEffectSetupCallback, isUseFormStatusCall, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseOptimisticCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseStateLikeCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|