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