@eslint-react/core 1.28.0-next.2 → 1.28.0-next.4
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.mts +43 -43
- package/dist/index.d.ts +43 -43
- package/dist/index.js +27 -27
- package/dist/index.mjs +27 -27
- package/package.json +6 -6
package/dist/index.d.mts
CHANGED
|
@@ -137,7 +137,7 @@ declare namespace useComponentCollectorLegacy {
|
|
|
137
137
|
*/
|
|
138
138
|
declare function useComponentCollectorLegacy(): useComponentCollectorLegacy.ReturnType;
|
|
139
139
|
|
|
140
|
-
declare function getFunctionComponentIdentifier(node: AST.TSESTreeFunction
|
|
140
|
+
declare function getFunctionComponentIdentifier(context: RuleContext, node: AST.TSESTreeFunction): TSESTree.Identifier | TSESTree.Identifier[] | _;
|
|
141
141
|
|
|
142
142
|
type ERComponentKind = "classComponent" | "functionComponent";
|
|
143
143
|
|
|
@@ -170,7 +170,7 @@ declare function isInsideRenderMethod(node: TSESTree.Node): boolean;
|
|
|
170
170
|
declare const RE_COMPONENT_NAME: RegExp;
|
|
171
171
|
declare function getComponentNameFromIdentifier(node: TSESTree.Identifier | TSESTree.Identifier[] | _): string | undefined;
|
|
172
172
|
declare function isComponentName(name: string): boolean;
|
|
173
|
-
declare function hasNoneOrValidComponentName(node: AST.TSESTreeFunction
|
|
173
|
+
declare function hasNoneOrValidComponentName(context: RuleContext, node: AST.TSESTreeFunction): boolean;
|
|
174
174
|
|
|
175
175
|
type EREffectPhaseKind = "cleanup" | "setup";
|
|
176
176
|
type ERLifecyclePhaseKind = "mount" | "unmount";
|
|
@@ -192,22 +192,22 @@ declare const isInversePhase: {
|
|
|
192
192
|
* _ = <Component renderRow={() => <div />} />
|
|
193
193
|
* ` ^^^^^^^^^^^^^ `
|
|
194
194
|
* ```
|
|
195
|
-
* @param node The AST node to check
|
|
196
195
|
* @param context The rule context
|
|
196
|
+
* @param node The AST node to check
|
|
197
197
|
* @returns `true` if node is a render function, `false` if not
|
|
198
198
|
*/
|
|
199
|
-
declare function isRenderFunctionLoose(node: AST.TSESTreeFunction
|
|
199
|
+
declare function isRenderFunctionLoose(context: RuleContext, node: AST.TSESTreeFunction): boolean;
|
|
200
200
|
/**
|
|
201
201
|
* Unsafe check whether given JSXAttribute is a render prop
|
|
202
202
|
* ```jsx
|
|
203
203
|
* _ = <Component renderRow={() => <div />} />
|
|
204
204
|
* ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
|
|
205
205
|
* ```
|
|
206
|
-
* @param node The AST node to check
|
|
207
206
|
* @param context The rule context
|
|
207
|
+
* @param node The AST node to check
|
|
208
208
|
* @returns `true` if node is a render prop, `false` if not
|
|
209
209
|
*/
|
|
210
|
-
declare function isRenderPropLoose(node: TSESTree.JSXAttribute
|
|
210
|
+
declare function isRenderPropLoose(context: RuleContext, node: TSESTree.JSXAttribute): boolean;
|
|
211
211
|
/**
|
|
212
212
|
* Unsafe check whether given node is declared directly inside a render property
|
|
213
213
|
* ```jsx
|
|
@@ -238,7 +238,7 @@ type ERStateKind = "actionState" | "state";
|
|
|
238
238
|
declare function isThisSetState(node: TSESTree.CallExpression): boolean;
|
|
239
239
|
|
|
240
240
|
/** internal */
|
|
241
|
-
declare function hasValidHierarchy(node: AST.TSESTreeFunction,
|
|
241
|
+
declare function hasValidHierarchy(context: RuleContext, node: AST.TSESTreeFunction, hint: bigint): boolean;
|
|
242
242
|
|
|
243
243
|
/**
|
|
244
244
|
* Check if a node is a React class component
|
|
@@ -260,18 +260,18 @@ declare function isFunctionOfUseEffectCleanup(node: TSESTree.Node): boolean | un
|
|
|
260
260
|
|
|
261
261
|
/**
|
|
262
262
|
* Determines whether inside `createElement`'s props.
|
|
263
|
-
* @param node The AST node to check
|
|
264
263
|
* @param context The rule context
|
|
264
|
+
* @param node The AST node to check
|
|
265
265
|
* @returns `true` if the node is inside createElement's props
|
|
266
266
|
*/
|
|
267
|
-
declare function isInsideCreateElementProps(node: TSESTree.Node
|
|
267
|
+
declare function isInsideCreateElementProps(context: RuleContext, node: TSESTree.Node): boolean;
|
|
268
268
|
/**
|
|
269
269
|
* Determines whether inside `createElement`'s children.
|
|
270
|
-
* @param node The AST node to check
|
|
271
270
|
* @param context The rule context
|
|
271
|
+
* @param node The AST node to check
|
|
272
272
|
* @returns `true` if the node is inside createElement's children
|
|
273
273
|
*/
|
|
274
|
-
declare function isChildrenOfCreateElement(node: TSESTree.Node
|
|
274
|
+
declare function isChildrenOfCreateElement(context: RuleContext, node: TSESTree.Node): boolean;
|
|
275
275
|
|
|
276
276
|
declare function isInsideReactHook(node: TSESTree.Node): boolean | undefined;
|
|
277
277
|
|
|
@@ -304,25 +304,25 @@ declare function isReactHook(node: AST.TSESTreeFunction | _): boolean | undefine
|
|
|
304
304
|
* @returns `true` if the node is a React Hook call, `false` otherwise.
|
|
305
305
|
*/
|
|
306
306
|
declare function isReactHookCall(node: TSESTree.Node | _): boolean;
|
|
307
|
-
declare function isReactHookCallWithName(node: TSESTree.CallExpression | _
|
|
307
|
+
declare function isReactHookCallWithName(context: RuleContext, node: TSESTree.CallExpression | _): (name: string) => boolean;
|
|
308
308
|
declare function isReactHookCallWithNameLoose(node: TSESTree.CallExpression | _): (name: string) => boolean;
|
|
309
|
-
declare function isReactHookCallWithNameAlias(
|
|
309
|
+
declare function isReactHookCallWithNameAlias(context: RuleContext, name: string, alias: string[]): (node: TSESTree.CallExpression) => boolean;
|
|
310
310
|
declare function isUseEffectCallLoose(node: TSESTree.Node | _): boolean;
|
|
311
|
-
declare const isUseCallbackCall: (
|
|
312
|
-
declare const isUseContextCall: (
|
|
313
|
-
declare const isUseDebugValueCall: (
|
|
314
|
-
declare const isUseDeferredValueCall: (
|
|
315
|
-
declare const isUseEffectCall: (
|
|
316
|
-
declare const isUseIdCall: (
|
|
317
|
-
declare const isUseImperativeHandleCall: (
|
|
318
|
-
declare const isUseInsertionEffectCall: (
|
|
319
|
-
declare const isUseLayoutEffectCall: (
|
|
320
|
-
declare const isUseMemoCall: (
|
|
321
|
-
declare const isUseReducerCall: (
|
|
322
|
-
declare const isUseRefCall: (
|
|
323
|
-
declare const isUseStateCall: (
|
|
324
|
-
declare const isUseSyncExternalStoreCall: (
|
|
325
|
-
declare const isUseTransitionCall: (
|
|
311
|
+
declare const isUseCallbackCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
312
|
+
declare const isUseContextCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
313
|
+
declare const isUseDebugValueCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
314
|
+
declare const isUseDeferredValueCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
315
|
+
declare const isUseEffectCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
316
|
+
declare const isUseIdCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
317
|
+
declare const isUseImperativeHandleCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
318
|
+
declare const isUseInsertionEffectCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
319
|
+
declare const isUseLayoutEffectCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
320
|
+
declare const isUseMemoCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
321
|
+
declare const isUseReducerCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
322
|
+
declare const isUseRefCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
323
|
+
declare const isUseStateCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
324
|
+
declare const isUseSyncExternalStoreCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
325
|
+
declare const isUseTransitionCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
326
326
|
|
|
327
327
|
interface ERSemanticEntry {
|
|
328
328
|
node: TSESTree.Node;
|
|
@@ -332,7 +332,7 @@ interface ERSemanticEntry {
|
|
|
332
332
|
declare namespace isCallFromReact {
|
|
333
333
|
type ReturnType = {
|
|
334
334
|
(context: RuleContext): (node: TSESTree.Node) => node is TSESTree.CallExpression;
|
|
335
|
-
(node: TSESTree.Node
|
|
335
|
+
(context: RuleContext, node: TSESTree.Node): node is TSESTree.CallExpression;
|
|
336
336
|
};
|
|
337
337
|
}
|
|
338
338
|
declare function isCallFromReact(name: string): isCallFromReact.ReturnType;
|
|
@@ -341,7 +341,7 @@ declare namespace isCallFromReactMember {
|
|
|
341
341
|
(context: RuleContext): (node: TSESTree.Node) => node is TSESTree.CallExpression & {
|
|
342
342
|
callee: TSESTree.MemberExpression;
|
|
343
343
|
};
|
|
344
|
-
(node: TSESTree.Node
|
|
344
|
+
(context: RuleContext, node: TSESTree.Node): node is TSESTree.CallExpression & {
|
|
345
345
|
callee: TSESTree.MemberExpression;
|
|
346
346
|
};
|
|
347
347
|
};
|
|
@@ -361,10 +361,10 @@ declare function isDisplayNameAssignment(node: TSESTree.Node | _): node is TSEST
|
|
|
361
361
|
|
|
362
362
|
declare function isFromReactLoose(node: TSESTree.Identifier | TSESTree.MemberExpression, name: string): boolean;
|
|
363
363
|
declare function isFromReactStrict(node: TSESTree.Identifier | TSESTree.MemberExpression, name: string, importSource: string, initialScope: Scope): boolean;
|
|
364
|
-
declare function isFromReact(name: string): (node: TSESTree.Identifier | TSESTree.MemberExpression
|
|
364
|
+
declare function isFromReact(name: string): (context: RuleContext, node: TSESTree.Identifier | TSESTree.MemberExpression) => boolean;
|
|
365
365
|
declare function isFromReactMemberLoose(node: TSESTree.MemberExpression, memberName: string, name: string): boolean;
|
|
366
366
|
declare function isFromReactMemberStrict(node: TSESTree.MemberExpression, memberName: string, name: string, importSource: string, initialScope: Scope): boolean;
|
|
367
|
-
declare function isFromReactMember(memberName: string, name: string): (node: TSESTree.MemberExpression
|
|
367
|
+
declare function isFromReactMember(memberName: string, name: string): (context: RuleContext, node: TSESTree.MemberExpression) => boolean;
|
|
368
368
|
|
|
369
369
|
/**
|
|
370
370
|
* Check if an identifier is initialized from react
|
|
@@ -2398,17 +2398,17 @@ declare function isReactAPIWithName(name: string): ReturnType<typeof isFromReact
|
|
|
2398
2398
|
declare function isReactAPIWithName(name: string, member: string): ReturnType<typeof isFromReactMember>;
|
|
2399
2399
|
declare function isReactAPICallWithName(name: string): ReturnType<typeof isCallFromReact>;
|
|
2400
2400
|
declare function isReactAPICallWithName(name: string, member: string): ReturnType<typeof isCallFromReactMember>;
|
|
2401
|
-
declare const isChildrenCount: (
|
|
2402
|
-
declare const isChildrenForEach: (
|
|
2403
|
-
declare const isChildrenMap: (
|
|
2404
|
-
declare const isChildrenOnly: (
|
|
2405
|
-
declare const isChildrenToArray: (
|
|
2406
|
-
declare const isCloneElement: (node: Identifier | MemberExpression
|
|
2407
|
-
declare const isCreateContext: (node: Identifier | MemberExpression
|
|
2408
|
-
declare const isCreateElement: (node: Identifier | MemberExpression
|
|
2409
|
-
declare const isCreateRef: (node: Identifier | MemberExpression
|
|
2410
|
-
declare const isForwardRef: (node: Identifier | MemberExpression
|
|
2411
|
-
declare const isMemo: (node: Identifier | MemberExpression
|
|
2401
|
+
declare const isChildrenCount: (context: _eslint_react_shared.RuleContext, node: MemberExpression) => boolean;
|
|
2402
|
+
declare const isChildrenForEach: (context: _eslint_react_shared.RuleContext, node: MemberExpression) => boolean;
|
|
2403
|
+
declare const isChildrenMap: (context: _eslint_react_shared.RuleContext, node: MemberExpression) => boolean;
|
|
2404
|
+
declare const isChildrenOnly: (context: _eslint_react_shared.RuleContext, node: MemberExpression) => boolean;
|
|
2405
|
+
declare const isChildrenToArray: (context: _eslint_react_shared.RuleContext, node: MemberExpression) => boolean;
|
|
2406
|
+
declare const isCloneElement: (context: _eslint_react_shared.RuleContext, node: Identifier | MemberExpression) => boolean;
|
|
2407
|
+
declare const isCreateContext: (context: _eslint_react_shared.RuleContext, node: Identifier | MemberExpression) => boolean;
|
|
2408
|
+
declare const isCreateElement: (context: _eslint_react_shared.RuleContext, node: Identifier | MemberExpression) => boolean;
|
|
2409
|
+
declare const isCreateRef: (context: _eslint_react_shared.RuleContext, node: Identifier | MemberExpression) => boolean;
|
|
2410
|
+
declare const isForwardRef: (context: _eslint_react_shared.RuleContext, node: Identifier | MemberExpression) => boolean;
|
|
2411
|
+
declare const isMemo: (context: _eslint_react_shared.RuleContext, node: Identifier | MemberExpression) => boolean;
|
|
2412
2412
|
declare const isChildrenCountCall: isCallFromReactMember.ReturnType;
|
|
2413
2413
|
declare const isChildrenForEachCall: isCallFromReactMember.ReturnType;
|
|
2414
2414
|
declare const isChildrenMapCall: isCallFromReactMember.ReturnType;
|
package/dist/index.d.ts
CHANGED
|
@@ -137,7 +137,7 @@ declare namespace useComponentCollectorLegacy {
|
|
|
137
137
|
*/
|
|
138
138
|
declare function useComponentCollectorLegacy(): useComponentCollectorLegacy.ReturnType;
|
|
139
139
|
|
|
140
|
-
declare function getFunctionComponentIdentifier(node: AST.TSESTreeFunction
|
|
140
|
+
declare function getFunctionComponentIdentifier(context: RuleContext, node: AST.TSESTreeFunction): TSESTree.Identifier | TSESTree.Identifier[] | _;
|
|
141
141
|
|
|
142
142
|
type ERComponentKind = "classComponent" | "functionComponent";
|
|
143
143
|
|
|
@@ -170,7 +170,7 @@ declare function isInsideRenderMethod(node: TSESTree.Node): boolean;
|
|
|
170
170
|
declare const RE_COMPONENT_NAME: RegExp;
|
|
171
171
|
declare function getComponentNameFromIdentifier(node: TSESTree.Identifier | TSESTree.Identifier[] | _): string | undefined;
|
|
172
172
|
declare function isComponentName(name: string): boolean;
|
|
173
|
-
declare function hasNoneOrValidComponentName(node: AST.TSESTreeFunction
|
|
173
|
+
declare function hasNoneOrValidComponentName(context: RuleContext, node: AST.TSESTreeFunction): boolean;
|
|
174
174
|
|
|
175
175
|
type EREffectPhaseKind = "cleanup" | "setup";
|
|
176
176
|
type ERLifecyclePhaseKind = "mount" | "unmount";
|
|
@@ -192,22 +192,22 @@ declare const isInversePhase: {
|
|
|
192
192
|
* _ = <Component renderRow={() => <div />} />
|
|
193
193
|
* ` ^^^^^^^^^^^^^ `
|
|
194
194
|
* ```
|
|
195
|
-
* @param node The AST node to check
|
|
196
195
|
* @param context The rule context
|
|
196
|
+
* @param node The AST node to check
|
|
197
197
|
* @returns `true` if node is a render function, `false` if not
|
|
198
198
|
*/
|
|
199
|
-
declare function isRenderFunctionLoose(node: AST.TSESTreeFunction
|
|
199
|
+
declare function isRenderFunctionLoose(context: RuleContext, node: AST.TSESTreeFunction): boolean;
|
|
200
200
|
/**
|
|
201
201
|
* Unsafe check whether given JSXAttribute is a render prop
|
|
202
202
|
* ```jsx
|
|
203
203
|
* _ = <Component renderRow={() => <div />} />
|
|
204
204
|
* ` ^^^^^^^^^^^^^^^^^^^^^^^^^ `
|
|
205
205
|
* ```
|
|
206
|
-
* @param node The AST node to check
|
|
207
206
|
* @param context The rule context
|
|
207
|
+
* @param node The AST node to check
|
|
208
208
|
* @returns `true` if node is a render prop, `false` if not
|
|
209
209
|
*/
|
|
210
|
-
declare function isRenderPropLoose(node: TSESTree.JSXAttribute
|
|
210
|
+
declare function isRenderPropLoose(context: RuleContext, node: TSESTree.JSXAttribute): boolean;
|
|
211
211
|
/**
|
|
212
212
|
* Unsafe check whether given node is declared directly inside a render property
|
|
213
213
|
* ```jsx
|
|
@@ -238,7 +238,7 @@ type ERStateKind = "actionState" | "state";
|
|
|
238
238
|
declare function isThisSetState(node: TSESTree.CallExpression): boolean;
|
|
239
239
|
|
|
240
240
|
/** internal */
|
|
241
|
-
declare function hasValidHierarchy(node: AST.TSESTreeFunction,
|
|
241
|
+
declare function hasValidHierarchy(context: RuleContext, node: AST.TSESTreeFunction, hint: bigint): boolean;
|
|
242
242
|
|
|
243
243
|
/**
|
|
244
244
|
* Check if a node is a React class component
|
|
@@ -260,18 +260,18 @@ declare function isFunctionOfUseEffectCleanup(node: TSESTree.Node): boolean | un
|
|
|
260
260
|
|
|
261
261
|
/**
|
|
262
262
|
* Determines whether inside `createElement`'s props.
|
|
263
|
-
* @param node The AST node to check
|
|
264
263
|
* @param context The rule context
|
|
264
|
+
* @param node The AST node to check
|
|
265
265
|
* @returns `true` if the node is inside createElement's props
|
|
266
266
|
*/
|
|
267
|
-
declare function isInsideCreateElementProps(node: TSESTree.Node
|
|
267
|
+
declare function isInsideCreateElementProps(context: RuleContext, node: TSESTree.Node): boolean;
|
|
268
268
|
/**
|
|
269
269
|
* Determines whether inside `createElement`'s children.
|
|
270
|
-
* @param node The AST node to check
|
|
271
270
|
* @param context The rule context
|
|
271
|
+
* @param node The AST node to check
|
|
272
272
|
* @returns `true` if the node is inside createElement's children
|
|
273
273
|
*/
|
|
274
|
-
declare function isChildrenOfCreateElement(node: TSESTree.Node
|
|
274
|
+
declare function isChildrenOfCreateElement(context: RuleContext, node: TSESTree.Node): boolean;
|
|
275
275
|
|
|
276
276
|
declare function isInsideReactHook(node: TSESTree.Node): boolean | undefined;
|
|
277
277
|
|
|
@@ -304,25 +304,25 @@ declare function isReactHook(node: AST.TSESTreeFunction | _): boolean | undefine
|
|
|
304
304
|
* @returns `true` if the node is a React Hook call, `false` otherwise.
|
|
305
305
|
*/
|
|
306
306
|
declare function isReactHookCall(node: TSESTree.Node | _): boolean;
|
|
307
|
-
declare function isReactHookCallWithName(node: TSESTree.CallExpression | _
|
|
307
|
+
declare function isReactHookCallWithName(context: RuleContext, node: TSESTree.CallExpression | _): (name: string) => boolean;
|
|
308
308
|
declare function isReactHookCallWithNameLoose(node: TSESTree.CallExpression | _): (name: string) => boolean;
|
|
309
|
-
declare function isReactHookCallWithNameAlias(
|
|
309
|
+
declare function isReactHookCallWithNameAlias(context: RuleContext, name: string, alias: string[]): (node: TSESTree.CallExpression) => boolean;
|
|
310
310
|
declare function isUseEffectCallLoose(node: TSESTree.Node | _): boolean;
|
|
311
|
-
declare const isUseCallbackCall: (
|
|
312
|
-
declare const isUseContextCall: (
|
|
313
|
-
declare const isUseDebugValueCall: (
|
|
314
|
-
declare const isUseDeferredValueCall: (
|
|
315
|
-
declare const isUseEffectCall: (
|
|
316
|
-
declare const isUseIdCall: (
|
|
317
|
-
declare const isUseImperativeHandleCall: (
|
|
318
|
-
declare const isUseInsertionEffectCall: (
|
|
319
|
-
declare const isUseLayoutEffectCall: (
|
|
320
|
-
declare const isUseMemoCall: (
|
|
321
|
-
declare const isUseReducerCall: (
|
|
322
|
-
declare const isUseRefCall: (
|
|
323
|
-
declare const isUseStateCall: (
|
|
324
|
-
declare const isUseSyncExternalStoreCall: (
|
|
325
|
-
declare const isUseTransitionCall: (
|
|
311
|
+
declare const isUseCallbackCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
312
|
+
declare const isUseContextCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
313
|
+
declare const isUseDebugValueCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
314
|
+
declare const isUseDeferredValueCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
315
|
+
declare const isUseEffectCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
316
|
+
declare const isUseIdCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
317
|
+
declare const isUseImperativeHandleCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
318
|
+
declare const isUseInsertionEffectCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
319
|
+
declare const isUseLayoutEffectCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
320
|
+
declare const isUseMemoCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
321
|
+
declare const isUseReducerCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
322
|
+
declare const isUseRefCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
323
|
+
declare const isUseStateCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
324
|
+
declare const isUseSyncExternalStoreCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
325
|
+
declare const isUseTransitionCall: (context: Readonly<_typescript_eslint_utils_ts_eslint.RuleContext<string, readonly unknown[]>>, node: TSESTree.CallExpression | undefined) => boolean;
|
|
326
326
|
|
|
327
327
|
interface ERSemanticEntry {
|
|
328
328
|
node: TSESTree.Node;
|
|
@@ -332,7 +332,7 @@ interface ERSemanticEntry {
|
|
|
332
332
|
declare namespace isCallFromReact {
|
|
333
333
|
type ReturnType = {
|
|
334
334
|
(context: RuleContext): (node: TSESTree.Node) => node is TSESTree.CallExpression;
|
|
335
|
-
(node: TSESTree.Node
|
|
335
|
+
(context: RuleContext, node: TSESTree.Node): node is TSESTree.CallExpression;
|
|
336
336
|
};
|
|
337
337
|
}
|
|
338
338
|
declare function isCallFromReact(name: string): isCallFromReact.ReturnType;
|
|
@@ -341,7 +341,7 @@ declare namespace isCallFromReactMember {
|
|
|
341
341
|
(context: RuleContext): (node: TSESTree.Node) => node is TSESTree.CallExpression & {
|
|
342
342
|
callee: TSESTree.MemberExpression;
|
|
343
343
|
};
|
|
344
|
-
(node: TSESTree.Node
|
|
344
|
+
(context: RuleContext, node: TSESTree.Node): node is TSESTree.CallExpression & {
|
|
345
345
|
callee: TSESTree.MemberExpression;
|
|
346
346
|
};
|
|
347
347
|
};
|
|
@@ -361,10 +361,10 @@ declare function isDisplayNameAssignment(node: TSESTree.Node | _): node is TSEST
|
|
|
361
361
|
|
|
362
362
|
declare function isFromReactLoose(node: TSESTree.Identifier | TSESTree.MemberExpression, name: string): boolean;
|
|
363
363
|
declare function isFromReactStrict(node: TSESTree.Identifier | TSESTree.MemberExpression, name: string, importSource: string, initialScope: Scope): boolean;
|
|
364
|
-
declare function isFromReact(name: string): (node: TSESTree.Identifier | TSESTree.MemberExpression
|
|
364
|
+
declare function isFromReact(name: string): (context: RuleContext, node: TSESTree.Identifier | TSESTree.MemberExpression) => boolean;
|
|
365
365
|
declare function isFromReactMemberLoose(node: TSESTree.MemberExpression, memberName: string, name: string): boolean;
|
|
366
366
|
declare function isFromReactMemberStrict(node: TSESTree.MemberExpression, memberName: string, name: string, importSource: string, initialScope: Scope): boolean;
|
|
367
|
-
declare function isFromReactMember(memberName: string, name: string): (node: TSESTree.MemberExpression
|
|
367
|
+
declare function isFromReactMember(memberName: string, name: string): (context: RuleContext, node: TSESTree.MemberExpression) => boolean;
|
|
368
368
|
|
|
369
369
|
/**
|
|
370
370
|
* Check if an identifier is initialized from react
|
|
@@ -2398,17 +2398,17 @@ declare function isReactAPIWithName(name: string): ReturnType<typeof isFromReact
|
|
|
2398
2398
|
declare function isReactAPIWithName(name: string, member: string): ReturnType<typeof isFromReactMember>;
|
|
2399
2399
|
declare function isReactAPICallWithName(name: string): ReturnType<typeof isCallFromReact>;
|
|
2400
2400
|
declare function isReactAPICallWithName(name: string, member: string): ReturnType<typeof isCallFromReactMember>;
|
|
2401
|
-
declare const isChildrenCount: (
|
|
2402
|
-
declare const isChildrenForEach: (
|
|
2403
|
-
declare const isChildrenMap: (
|
|
2404
|
-
declare const isChildrenOnly: (
|
|
2405
|
-
declare const isChildrenToArray: (
|
|
2406
|
-
declare const isCloneElement: (node: Identifier | MemberExpression
|
|
2407
|
-
declare const isCreateContext: (node: Identifier | MemberExpression
|
|
2408
|
-
declare const isCreateElement: (node: Identifier | MemberExpression
|
|
2409
|
-
declare const isCreateRef: (node: Identifier | MemberExpression
|
|
2410
|
-
declare const isForwardRef: (node: Identifier | MemberExpression
|
|
2411
|
-
declare const isMemo: (node: Identifier | MemberExpression
|
|
2401
|
+
declare const isChildrenCount: (context: _eslint_react_shared.RuleContext, node: MemberExpression) => boolean;
|
|
2402
|
+
declare const isChildrenForEach: (context: _eslint_react_shared.RuleContext, node: MemberExpression) => boolean;
|
|
2403
|
+
declare const isChildrenMap: (context: _eslint_react_shared.RuleContext, node: MemberExpression) => boolean;
|
|
2404
|
+
declare const isChildrenOnly: (context: _eslint_react_shared.RuleContext, node: MemberExpression) => boolean;
|
|
2405
|
+
declare const isChildrenToArray: (context: _eslint_react_shared.RuleContext, node: MemberExpression) => boolean;
|
|
2406
|
+
declare const isCloneElement: (context: _eslint_react_shared.RuleContext, node: Identifier | MemberExpression) => boolean;
|
|
2407
|
+
declare const isCreateContext: (context: _eslint_react_shared.RuleContext, node: Identifier | MemberExpression) => boolean;
|
|
2408
|
+
declare const isCreateElement: (context: _eslint_react_shared.RuleContext, node: Identifier | MemberExpression) => boolean;
|
|
2409
|
+
declare const isCreateRef: (context: _eslint_react_shared.RuleContext, node: Identifier | MemberExpression) => boolean;
|
|
2410
|
+
declare const isForwardRef: (context: _eslint_react_shared.RuleContext, node: Identifier | MemberExpression) => boolean;
|
|
2411
|
+
declare const isMemo: (context: _eslint_react_shared.RuleContext, node: Identifier | MemberExpression) => boolean;
|
|
2412
2412
|
declare const isChildrenCountCall: isCallFromReactMember.ReturnType;
|
|
2413
2413
|
declare const isChildrenForEachCall: isCallFromReactMember.ReturnType;
|
|
2414
2414
|
declare const isChildrenMapCall: isCallFromReactMember.ReturnType;
|
package/dist/index.js
CHANGED
|
@@ -79,7 +79,7 @@ function isFromReactStrict(node, name, importSource, initialScope) {
|
|
|
79
79
|
return false;
|
|
80
80
|
}
|
|
81
81
|
function isFromReact(name) {
|
|
82
|
-
return (
|
|
82
|
+
return (context, node) => {
|
|
83
83
|
const { importSource = defaultImportSource, strictImportCheck = false } = shared.unsafeDecodeSettings(context.settings);
|
|
84
84
|
if (!strictImportCheck) return isFromReactLoose(node, name);
|
|
85
85
|
return isFromReactStrict(node, name, importSource, context.sourceCode.getScope(node));
|
|
@@ -108,7 +108,7 @@ function isFromReactMemberStrict(node, memberName, name, importSource, initialSc
|
|
|
108
108
|
return false;
|
|
109
109
|
}
|
|
110
110
|
function isFromReactMember(memberName, name) {
|
|
111
|
-
return (
|
|
111
|
+
return (context, node) => {
|
|
112
112
|
const { importSource = defaultImportSource, strictImportCheck = false } = shared.unsafeDecodeSettings(context.settings);
|
|
113
113
|
if (!strictImportCheck) return isFromReactMemberLoose(node, memberName, name);
|
|
114
114
|
return isFromReactMemberStrict(node, memberName, name, importSource, context.sourceCode.getScope(node));
|
|
@@ -117,17 +117,17 @@ function isFromReactMember(memberName, name) {
|
|
|
117
117
|
|
|
118
118
|
// src/utils/is-call-from-react.ts
|
|
119
119
|
function isCallFromReact(name) {
|
|
120
|
-
return eff.dual(2, (
|
|
120
|
+
return eff.dual(2, (context, node) => {
|
|
121
121
|
if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
122
122
|
if (!AST8__namespace.isOneOf([types.AST_NODE_TYPES.Identifier, types.AST_NODE_TYPES.MemberExpression])(node.callee)) return false;
|
|
123
|
-
return isFromReact(name)(node.callee
|
|
123
|
+
return isFromReact(name)(context, node.callee);
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
126
|
function isCallFromReactMember(pragmaMemberName, name) {
|
|
127
|
-
return eff.dual(2, (
|
|
127
|
+
return eff.dual(2, (context, node) => {
|
|
128
128
|
if (node.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
129
129
|
if (!AST8__namespace.is(types.AST_NODE_TYPES.MemberExpression)(node.callee)) return false;
|
|
130
|
-
return isFromReactMember(pragmaMemberName, name)(node.callee
|
|
130
|
+
return isFromReactMember(pragmaMemberName, name)(context, node.callee);
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
133
|
var DISPLAY_NAME_ASSIGNMENT_SELECTOR = [
|
|
@@ -197,7 +197,7 @@ function isReactHookCall(node) {
|
|
|
197
197
|
}
|
|
198
198
|
return false;
|
|
199
199
|
}
|
|
200
|
-
function isReactHookCallWithName(
|
|
200
|
+
function isReactHookCallWithName(context, node) {
|
|
201
201
|
if (node == null) return eff.constFalse;
|
|
202
202
|
const settings = shared.unsafeDecodeSettings(context.settings);
|
|
203
203
|
const importSource = settings.importSource ?? "react";
|
|
@@ -226,7 +226,7 @@ function isReactHookCallWithNameLoose(node) {
|
|
|
226
226
|
}
|
|
227
227
|
};
|
|
228
228
|
}
|
|
229
|
-
function isReactHookCallWithNameAlias(
|
|
229
|
+
function isReactHookCallWithNameAlias(context, name, alias) {
|
|
230
230
|
const settings = shared.unsafeDecodeSettings(context);
|
|
231
231
|
const importSource = settings.importSource ?? "react";
|
|
232
232
|
return (node) => {
|
|
@@ -368,22 +368,22 @@ var ERComponentFlag = {
|
|
|
368
368
|
ForwardRef: 1n << 3n,
|
|
369
369
|
Async: 1n << 4n
|
|
370
370
|
};
|
|
371
|
-
function isComponentWrapperCall(
|
|
371
|
+
function isComponentWrapperCall(context, node) {
|
|
372
372
|
if (node.type !== types.AST_NODE_TYPES.CallExpression) {
|
|
373
373
|
return false;
|
|
374
374
|
}
|
|
375
|
-
return isMemoCall(
|
|
375
|
+
return isMemoCall(context, node) || isForwardRefCall(context, node) || isReactHookCallWithNameLoose(node)("useCallback");
|
|
376
376
|
}
|
|
377
|
-
function getFunctionComponentIdentifier(
|
|
377
|
+
function getFunctionComponentIdentifier(context, node) {
|
|
378
378
|
const functionId = AST8__namespace.getFunctionIdentifier(node);
|
|
379
379
|
if (functionId != null) {
|
|
380
380
|
return functionId;
|
|
381
381
|
}
|
|
382
382
|
const { parent } = node;
|
|
383
|
-
if (parent.type === types.AST_NODE_TYPES.CallExpression && isComponentWrapperCall(
|
|
383
|
+
if (parent.type === types.AST_NODE_TYPES.CallExpression && isComponentWrapperCall(context, parent) && parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator && parent.parent.id.type === types.AST_NODE_TYPES.Identifier) {
|
|
384
384
|
return parent.parent.id;
|
|
385
385
|
}
|
|
386
|
-
if (parent.type === types.AST_NODE_TYPES.CallExpression && isComponentWrapperCall(
|
|
386
|
+
if (parent.type === types.AST_NODE_TYPES.CallExpression && isComponentWrapperCall(context, parent) && parent.parent.type === types.AST_NODE_TYPES.CallExpression && isComponentWrapperCall(context, parent.parent) && parent.parent.parent.type === types.AST_NODE_TYPES.VariableDeclarator && parent.parent.parent.id.type === types.AST_NODE_TYPES.Identifier) {
|
|
387
387
|
return parent.parent.parent.id;
|
|
388
388
|
}
|
|
389
389
|
return eff._;
|
|
@@ -396,23 +396,23 @@ function getComponentNameFromIdentifier(node) {
|
|
|
396
396
|
function isComponentName(name) {
|
|
397
397
|
return RE_COMPONENT_NAME.test(name);
|
|
398
398
|
}
|
|
399
|
-
function hasNoneOrValidComponentName(
|
|
400
|
-
const id = getFunctionComponentIdentifier(
|
|
399
|
+
function hasNoneOrValidComponentName(context, node) {
|
|
400
|
+
const id = getFunctionComponentIdentifier(context, node);
|
|
401
401
|
if (id == null) return true;
|
|
402
402
|
const name = Array.isArray(id) ? id.at(-1)?.name : id.name;
|
|
403
403
|
return name != null && isComponentName(name);
|
|
404
404
|
}
|
|
405
|
-
function isInsideCreateElementProps(
|
|
405
|
+
function isInsideCreateElementProps(context, node) {
|
|
406
406
|
const call = AST8__namespace.findParentNode(node, isCreateElementCall(context));
|
|
407
407
|
if (call == null) return false;
|
|
408
408
|
const prop = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.ObjectExpression));
|
|
409
409
|
if (prop == null) return false;
|
|
410
410
|
return prop === call.arguments[1];
|
|
411
411
|
}
|
|
412
|
-
function isChildrenOfCreateElement(
|
|
412
|
+
function isChildrenOfCreateElement(context, node) {
|
|
413
413
|
const parent = node.parent;
|
|
414
414
|
if (parent == null || parent.type !== types.AST_NODE_TYPES.CallExpression) return false;
|
|
415
|
-
if (!isCreateElementCall(
|
|
415
|
+
if (!isCreateElementCall(context, parent)) return false;
|
|
416
416
|
return parent.arguments.slice(2).some((arg) => arg === node);
|
|
417
417
|
}
|
|
418
418
|
function isClassComponent(node) {
|
|
@@ -476,8 +476,8 @@ function isInsideRenderMethod(node) {
|
|
|
476
476
|
}
|
|
477
477
|
|
|
478
478
|
// src/component/hierarchy.ts
|
|
479
|
-
function hasValidHierarchy(
|
|
480
|
-
if (isChildrenOfCreateElement(
|
|
479
|
+
function hasValidHierarchy(context, node, hint) {
|
|
480
|
+
if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) {
|
|
481
481
|
return false;
|
|
482
482
|
}
|
|
483
483
|
if (hint & ERComponentHint.SkipMapCallback && AST8__namespace.isMapCallLoose(node.parent)) {
|
|
@@ -554,10 +554,10 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
|
|
|
554
554
|
const entry = getCurrentEntry();
|
|
555
555
|
if (entry == null) return;
|
|
556
556
|
const { body } = entry.node;
|
|
557
|
-
const isComponent = hasNoneOrValidComponentName(entry.node
|
|
557
|
+
const isComponent = hasNoneOrValidComponentName(context, entry.node) && JSX3__namespace.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
558
558
|
if (!isComponent) return;
|
|
559
559
|
const initPath = AST8__namespace.getFunctionInitPath(entry.node);
|
|
560
|
-
const id = getFunctionComponentIdentifier(entry.node
|
|
560
|
+
const id = getFunctionComponentIdentifier(context, entry.node);
|
|
561
561
|
const name = getComponentNameFromIdentifier(id);
|
|
562
562
|
const key = shared.getId();
|
|
563
563
|
components.set(key, {
|
|
@@ -594,11 +594,11 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
|
|
|
594
594
|
"ReturnStatement[type]"(node) {
|
|
595
595
|
const entry = getCurrentEntry();
|
|
596
596
|
if (entry == null) return;
|
|
597
|
-
const isComponent = hasNoneOrValidComponentName(entry.node
|
|
597
|
+
const isComponent = hasNoneOrValidComponentName(context, entry.node) && JSX3__namespace.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
598
598
|
if (!isComponent) return;
|
|
599
599
|
entry.isComponent = true;
|
|
600
600
|
const initPath = AST8__namespace.getFunctionInitPath(entry.node);
|
|
601
|
-
const id = getFunctionComponentIdentifier(entry.node
|
|
601
|
+
const id = getFunctionComponentIdentifier(context, entry.node);
|
|
602
602
|
const name = getComponentNameFromIdentifier(id);
|
|
603
603
|
components.set(entry.key, {
|
|
604
604
|
id,
|
|
@@ -669,7 +669,7 @@ var ERPhaseRelevance = birecord__default.default({
|
|
|
669
669
|
setup: "cleanup"
|
|
670
670
|
});
|
|
671
671
|
var isInversePhase = eff.dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
|
|
672
|
-
function isRenderFunctionLoose(
|
|
672
|
+
function isRenderFunctionLoose(context, node) {
|
|
673
673
|
const { body, parent } = node;
|
|
674
674
|
if (AST8__namespace.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
675
675
|
return parent.type === types.AST_NODE_TYPES.JSXExpressionContainer && parent.parent.type === types.AST_NODE_TYPES.JSXAttribute && parent.parent.name.type === types.AST_NODE_TYPES.JSXIdentifier && parent.parent.name.name.startsWith("render");
|
|
@@ -682,11 +682,11 @@ function isRenderFunctionLoose(node, context) {
|
|
|
682
682
|
JSX3__namespace.JSXValueHint.SkipNullLiteral | JSX3__namespace.JSXValueHint.SkipUndefined | JSX3__namespace.JSXValueHint.StrictLogical | JSX3__namespace.JSXValueHint.StrictConditional
|
|
683
683
|
);
|
|
684
684
|
}
|
|
685
|
-
function isRenderPropLoose(
|
|
685
|
+
function isRenderPropLoose(context, node) {
|
|
686
686
|
if (node.name.type !== types.AST_NODE_TYPES.JSXIdentifier) {
|
|
687
687
|
return false;
|
|
688
688
|
}
|
|
689
|
-
return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && AST8__namespace.isFunction(node.value.expression) && isRenderFunctionLoose(node.value.expression
|
|
689
|
+
return node.name.name.startsWith("render") && node.value?.type === types.AST_NODE_TYPES.JSXExpressionContainer && AST8__namespace.isFunction(node.value.expression) && isRenderFunctionLoose(context, node.value.expression);
|
|
690
690
|
}
|
|
691
691
|
function isDirectValueOfRenderPropertyLoose(node) {
|
|
692
692
|
const matching = (node2) => {
|
package/dist/index.mjs
CHANGED
|
@@ -52,7 +52,7 @@ function isFromReactStrict(node, name, importSource, initialScope) {
|
|
|
52
52
|
return false;
|
|
53
53
|
}
|
|
54
54
|
function isFromReact(name) {
|
|
55
|
-
return (
|
|
55
|
+
return (context, node) => {
|
|
56
56
|
const { importSource = defaultImportSource, strictImportCheck = false } = unsafeDecodeSettings(context.settings);
|
|
57
57
|
if (!strictImportCheck) return isFromReactLoose(node, name);
|
|
58
58
|
return isFromReactStrict(node, name, importSource, context.sourceCode.getScope(node));
|
|
@@ -81,7 +81,7 @@ function isFromReactMemberStrict(node, memberName, name, importSource, initialSc
|
|
|
81
81
|
return false;
|
|
82
82
|
}
|
|
83
83
|
function isFromReactMember(memberName, name) {
|
|
84
|
-
return (
|
|
84
|
+
return (context, node) => {
|
|
85
85
|
const { importSource = defaultImportSource, strictImportCheck = false } = unsafeDecodeSettings(context.settings);
|
|
86
86
|
if (!strictImportCheck) return isFromReactMemberLoose(node, memberName, name);
|
|
87
87
|
return isFromReactMemberStrict(node, memberName, name, importSource, context.sourceCode.getScope(node));
|
|
@@ -90,17 +90,17 @@ function isFromReactMember(memberName, name) {
|
|
|
90
90
|
|
|
91
91
|
// src/utils/is-call-from-react.ts
|
|
92
92
|
function isCallFromReact(name) {
|
|
93
|
-
return dual(2, (
|
|
93
|
+
return dual(2, (context, node) => {
|
|
94
94
|
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
95
95
|
if (!AST8.isOneOf([AST_NODE_TYPES.Identifier, AST_NODE_TYPES.MemberExpression])(node.callee)) return false;
|
|
96
|
-
return isFromReact(name)(node.callee
|
|
96
|
+
return isFromReact(name)(context, node.callee);
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
function isCallFromReactMember(pragmaMemberName, name) {
|
|
100
|
-
return dual(2, (
|
|
100
|
+
return dual(2, (context, node) => {
|
|
101
101
|
if (node.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
102
102
|
if (!AST8.is(AST_NODE_TYPES.MemberExpression)(node.callee)) return false;
|
|
103
|
-
return isFromReactMember(pragmaMemberName, name)(node.callee
|
|
103
|
+
return isFromReactMember(pragmaMemberName, name)(context, node.callee);
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
106
|
var DISPLAY_NAME_ASSIGNMENT_SELECTOR = [
|
|
@@ -170,7 +170,7 @@ function isReactHookCall(node) {
|
|
|
170
170
|
}
|
|
171
171
|
return false;
|
|
172
172
|
}
|
|
173
|
-
function isReactHookCallWithName(
|
|
173
|
+
function isReactHookCallWithName(context, node) {
|
|
174
174
|
if (node == null) return constFalse;
|
|
175
175
|
const settings = unsafeDecodeSettings(context.settings);
|
|
176
176
|
const importSource = settings.importSource ?? "react";
|
|
@@ -199,7 +199,7 @@ function isReactHookCallWithNameLoose(node) {
|
|
|
199
199
|
}
|
|
200
200
|
};
|
|
201
201
|
}
|
|
202
|
-
function isReactHookCallWithNameAlias(
|
|
202
|
+
function isReactHookCallWithNameAlias(context, name, alias) {
|
|
203
203
|
const settings = unsafeDecodeSettings(context);
|
|
204
204
|
const importSource = settings.importSource ?? "react";
|
|
205
205
|
return (node) => {
|
|
@@ -341,22 +341,22 @@ var ERComponentFlag = {
|
|
|
341
341
|
ForwardRef: 1n << 3n,
|
|
342
342
|
Async: 1n << 4n
|
|
343
343
|
};
|
|
344
|
-
function isComponentWrapperCall(
|
|
344
|
+
function isComponentWrapperCall(context, node) {
|
|
345
345
|
if (node.type !== AST_NODE_TYPES.CallExpression) {
|
|
346
346
|
return false;
|
|
347
347
|
}
|
|
348
|
-
return isMemoCall(
|
|
348
|
+
return isMemoCall(context, node) || isForwardRefCall(context, node) || isReactHookCallWithNameLoose(node)("useCallback");
|
|
349
349
|
}
|
|
350
|
-
function getFunctionComponentIdentifier(
|
|
350
|
+
function getFunctionComponentIdentifier(context, node) {
|
|
351
351
|
const functionId = AST8.getFunctionIdentifier(node);
|
|
352
352
|
if (functionId != null) {
|
|
353
353
|
return functionId;
|
|
354
354
|
}
|
|
355
355
|
const { parent } = node;
|
|
356
|
-
if (parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCall(
|
|
356
|
+
if (parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCall(context, parent) && parent.parent.type === AST_NODE_TYPES.VariableDeclarator && parent.parent.id.type === AST_NODE_TYPES.Identifier) {
|
|
357
357
|
return parent.parent.id;
|
|
358
358
|
}
|
|
359
|
-
if (parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCall(
|
|
359
|
+
if (parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCall(context, parent) && parent.parent.type === AST_NODE_TYPES.CallExpression && isComponentWrapperCall(context, parent.parent) && parent.parent.parent.type === AST_NODE_TYPES.VariableDeclarator && parent.parent.parent.id.type === AST_NODE_TYPES.Identifier) {
|
|
360
360
|
return parent.parent.parent.id;
|
|
361
361
|
}
|
|
362
362
|
return _;
|
|
@@ -369,23 +369,23 @@ function getComponentNameFromIdentifier(node) {
|
|
|
369
369
|
function isComponentName(name) {
|
|
370
370
|
return RE_COMPONENT_NAME.test(name);
|
|
371
371
|
}
|
|
372
|
-
function hasNoneOrValidComponentName(
|
|
373
|
-
const id = getFunctionComponentIdentifier(
|
|
372
|
+
function hasNoneOrValidComponentName(context, node) {
|
|
373
|
+
const id = getFunctionComponentIdentifier(context, node);
|
|
374
374
|
if (id == null) return true;
|
|
375
375
|
const name = Array.isArray(id) ? id.at(-1)?.name : id.name;
|
|
376
376
|
return name != null && isComponentName(name);
|
|
377
377
|
}
|
|
378
|
-
function isInsideCreateElementProps(
|
|
378
|
+
function isInsideCreateElementProps(context, node) {
|
|
379
379
|
const call = AST8.findParentNode(node, isCreateElementCall(context));
|
|
380
380
|
if (call == null) return false;
|
|
381
381
|
const prop = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.ObjectExpression));
|
|
382
382
|
if (prop == null) return false;
|
|
383
383
|
return prop === call.arguments[1];
|
|
384
384
|
}
|
|
385
|
-
function isChildrenOfCreateElement(
|
|
385
|
+
function isChildrenOfCreateElement(context, node) {
|
|
386
386
|
const parent = node.parent;
|
|
387
387
|
if (parent == null || parent.type !== AST_NODE_TYPES.CallExpression) return false;
|
|
388
|
-
if (!isCreateElementCall(
|
|
388
|
+
if (!isCreateElementCall(context, parent)) return false;
|
|
389
389
|
return parent.arguments.slice(2).some((arg) => arg === node);
|
|
390
390
|
}
|
|
391
391
|
function isClassComponent(node) {
|
|
@@ -449,8 +449,8 @@ function isInsideRenderMethod(node) {
|
|
|
449
449
|
}
|
|
450
450
|
|
|
451
451
|
// src/component/hierarchy.ts
|
|
452
|
-
function hasValidHierarchy(
|
|
453
|
-
if (isChildrenOfCreateElement(
|
|
452
|
+
function hasValidHierarchy(context, node, hint) {
|
|
453
|
+
if (isChildrenOfCreateElement(context, node) || isFunctionOfRenderMethod(node)) {
|
|
454
454
|
return false;
|
|
455
455
|
}
|
|
456
456
|
if (hint & ERComponentHint.SkipMapCallback && AST8.isMapCallLoose(node.parent)) {
|
|
@@ -527,10 +527,10 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
|
|
|
527
527
|
const entry = getCurrentEntry();
|
|
528
528
|
if (entry == null) return;
|
|
529
529
|
const { body } = entry.node;
|
|
530
|
-
const isComponent = hasNoneOrValidComponentName(entry.node
|
|
530
|
+
const isComponent = hasNoneOrValidComponentName(context, entry.node) && JSX3.isJSXValue(body, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
531
531
|
if (!isComponent) return;
|
|
532
532
|
const initPath = AST8.getFunctionInitPath(entry.node);
|
|
533
|
-
const id = getFunctionComponentIdentifier(entry.node
|
|
533
|
+
const id = getFunctionComponentIdentifier(context, entry.node);
|
|
534
534
|
const name = getComponentNameFromIdentifier(id);
|
|
535
535
|
const key = getId();
|
|
536
536
|
components.set(key, {
|
|
@@ -567,11 +567,11 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options =
|
|
|
567
567
|
"ReturnStatement[type]"(node) {
|
|
568
568
|
const entry = getCurrentEntry();
|
|
569
569
|
if (entry == null) return;
|
|
570
|
-
const isComponent = hasNoneOrValidComponentName(entry.node
|
|
570
|
+
const isComponent = hasNoneOrValidComponentName(context, entry.node) && JSX3.isJSXValue(node.argument, jsxCtx, hint) && hasValidHierarchy(context, entry.node, hint);
|
|
571
571
|
if (!isComponent) return;
|
|
572
572
|
entry.isComponent = true;
|
|
573
573
|
const initPath = AST8.getFunctionInitPath(entry.node);
|
|
574
|
-
const id = getFunctionComponentIdentifier(entry.node
|
|
574
|
+
const id = getFunctionComponentIdentifier(context, entry.node);
|
|
575
575
|
const name = getComponentNameFromIdentifier(id);
|
|
576
576
|
components.set(entry.key, {
|
|
577
577
|
id,
|
|
@@ -642,7 +642,7 @@ var ERPhaseRelevance = birecord({
|
|
|
642
642
|
setup: "cleanup"
|
|
643
643
|
});
|
|
644
644
|
var isInversePhase = dual(2, (a, b) => ERPhaseRelevance.get(a) === b);
|
|
645
|
-
function isRenderFunctionLoose(
|
|
645
|
+
function isRenderFunctionLoose(context, node) {
|
|
646
646
|
const { body, parent } = node;
|
|
647
647
|
if (AST8.getFunctionIdentifier(node)?.name.startsWith("render")) {
|
|
648
648
|
return parent.type === AST_NODE_TYPES.JSXExpressionContainer && parent.parent.type === AST_NODE_TYPES.JSXAttribute && parent.parent.name.type === AST_NODE_TYPES.JSXIdentifier && parent.parent.name.name.startsWith("render");
|
|
@@ -655,11 +655,11 @@ function isRenderFunctionLoose(node, context) {
|
|
|
655
655
|
JSX3.JSXValueHint.SkipNullLiteral | JSX3.JSXValueHint.SkipUndefined | JSX3.JSXValueHint.StrictLogical | JSX3.JSXValueHint.StrictConditional
|
|
656
656
|
);
|
|
657
657
|
}
|
|
658
|
-
function isRenderPropLoose(
|
|
658
|
+
function isRenderPropLoose(context, node) {
|
|
659
659
|
if (node.name.type !== AST_NODE_TYPES.JSXIdentifier) {
|
|
660
660
|
return false;
|
|
661
661
|
}
|
|
662
|
-
return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer && AST8.isFunction(node.value.expression) && isRenderFunctionLoose(node.value.expression
|
|
662
|
+
return node.name.name.startsWith("render") && node.value?.type === AST_NODE_TYPES.JSXExpressionContainer && AST8.isFunction(node.value.expression) && isRenderFunctionLoose(context, node.value.expression);
|
|
663
663
|
}
|
|
664
664
|
function isDirectValueOfRenderPropertyLoose(node) {
|
|
665
665
|
const matching = (node2) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "1.28.0-next.
|
|
3
|
+
"version": "1.28.0-next.4",
|
|
4
4
|
"description": "ESLint React's ESLint utility module for static analysis of React core APIs and Patterns.",
|
|
5
5
|
"homepage": "https://github.com/Rel1cx/eslint-react",
|
|
6
6
|
"bugs": {
|
|
@@ -41,11 +41,11 @@
|
|
|
41
41
|
"@typescript-eslint/utils": "^8.25.0",
|
|
42
42
|
"birecord": "^0.1.1",
|
|
43
43
|
"ts-pattern": "^5.6.2",
|
|
44
|
-
"@eslint-react/ast": "1.28.0-next.
|
|
45
|
-
"@eslint-react/eff": "1.28.0-next.
|
|
46
|
-
"@eslint-react/
|
|
47
|
-
"@eslint-react/
|
|
48
|
-
"@eslint-react/
|
|
44
|
+
"@eslint-react/ast": "1.28.0-next.4",
|
|
45
|
+
"@eslint-react/eff": "1.28.0-next.4",
|
|
46
|
+
"@eslint-react/shared": "1.28.0-next.4",
|
|
47
|
+
"@eslint-react/var": "1.28.0-next.4",
|
|
48
|
+
"@eslint-react/jsx": "1.28.0-next.4"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"tsup": "^8.3.6",
|