@eslint-react/core 1.24.0-next.1 → 1.24.0-next.3
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 +12 -8
- package/dist/index.d.ts +12 -8
- package/dist/index.js +38 -42
- package/dist/index.mjs +38 -42
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -11,8 +11,8 @@ import { Scope } from '@typescript-eslint/scope-manager';
|
|
|
11
11
|
import { SyntaxKind } from 'typescript';
|
|
12
12
|
|
|
13
13
|
interface ERSemanticNode {
|
|
14
|
-
_: string;
|
|
15
14
|
id: _ | TSESTree.Identifier | TSESTree.Identifier[];
|
|
15
|
+
key: string;
|
|
16
16
|
kind: string;
|
|
17
17
|
name: _ | string;
|
|
18
18
|
node: TSESTree.Node;
|
|
@@ -79,7 +79,11 @@ interface ERClassComponent extends ERSemanticNode {
|
|
|
79
79
|
}
|
|
80
80
|
type ERComponent = ERClassComponent | ERFunctionComponent;
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
interface ComponentCollectorOptions {
|
|
83
|
+
collectDisplayName?: boolean;
|
|
84
|
+
collectHookCalls?: boolean;
|
|
85
|
+
}
|
|
86
|
+
declare function useComponentCollector(context: RuleContext, hint?: bigint, options?: ComponentCollectorOptions): {
|
|
83
87
|
readonly ctx: {
|
|
84
88
|
readonly getAllComponents: (node: TSESTree.Program) => Map<string, ERFunctionComponent>;
|
|
85
89
|
readonly getCurrentEntries: () => {
|
|
@@ -96,6 +100,11 @@ declare function useComponentCollector(context: RuleContext, hint?: bigint): {
|
|
|
96
100
|
} | undefined;
|
|
97
101
|
};
|
|
98
102
|
readonly listeners: {
|
|
103
|
+
readonly "ReturnStatement[type]": (node: TSESTree.ReturnStatement) => void;
|
|
104
|
+
readonly "CallExpression[type]:exit"?: (node: TSESTree.CallExpression) => void;
|
|
105
|
+
readonly "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']"?: (node: TSESTree.AssignmentExpression & {
|
|
106
|
+
left: TSESTree.MemberExpression;
|
|
107
|
+
}) => void;
|
|
99
108
|
readonly ":function[type]": (node: AST.TSESTreeFunction) => void;
|
|
100
109
|
readonly ":function[type]:exit": () => {
|
|
101
110
|
key: string;
|
|
@@ -104,11 +113,6 @@ declare function useComponentCollector(context: RuleContext, hint?: bigint): {
|
|
|
104
113
|
isComponent: boolean;
|
|
105
114
|
} | undefined;
|
|
106
115
|
readonly "ArrowFunctionExpression[type][body.type!='BlockStatement']": () => void;
|
|
107
|
-
readonly "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']": (node: TSESTree.AssignmentExpression & {
|
|
108
|
-
left: TSESTree.MemberExpression;
|
|
109
|
-
}) => void;
|
|
110
|
-
readonly "CallExpression[type]:exit": (node: TSESTree.CallExpression) => void;
|
|
111
|
-
readonly "ReturnStatement[type]": (node: TSESTree.ReturnStatement) => void;
|
|
112
116
|
};
|
|
113
117
|
};
|
|
114
118
|
|
|
@@ -2575,4 +2579,4 @@ declare const isMemoCall: {
|
|
|
2575
2579
|
(node: Node, context: _eslint_react_types.RuleContext): node is CallExpression;
|
|
2576
2580
|
};
|
|
2577
2581
|
|
|
2578
|
-
export { DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementNameAndRepresentName, getFunctionComponentIdentifier, getId, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
|
2582
|
+
export { type ComponentCollectorOptions, DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementNameAndRepresentName, getFunctionComponentIdentifier, getId, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/dist/index.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ import { Scope } from '@typescript-eslint/scope-manager';
|
|
|
11
11
|
import { SyntaxKind } from 'typescript';
|
|
12
12
|
|
|
13
13
|
interface ERSemanticNode {
|
|
14
|
-
_: string;
|
|
15
14
|
id: _ | TSESTree.Identifier | TSESTree.Identifier[];
|
|
15
|
+
key: string;
|
|
16
16
|
kind: string;
|
|
17
17
|
name: _ | string;
|
|
18
18
|
node: TSESTree.Node;
|
|
@@ -79,7 +79,11 @@ interface ERClassComponent extends ERSemanticNode {
|
|
|
79
79
|
}
|
|
80
80
|
type ERComponent = ERClassComponent | ERFunctionComponent;
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
interface ComponentCollectorOptions {
|
|
83
|
+
collectDisplayName?: boolean;
|
|
84
|
+
collectHookCalls?: boolean;
|
|
85
|
+
}
|
|
86
|
+
declare function useComponentCollector(context: RuleContext, hint?: bigint, options?: ComponentCollectorOptions): {
|
|
83
87
|
readonly ctx: {
|
|
84
88
|
readonly getAllComponents: (node: TSESTree.Program) => Map<string, ERFunctionComponent>;
|
|
85
89
|
readonly getCurrentEntries: () => {
|
|
@@ -96,6 +100,11 @@ declare function useComponentCollector(context: RuleContext, hint?: bigint): {
|
|
|
96
100
|
} | undefined;
|
|
97
101
|
};
|
|
98
102
|
readonly listeners: {
|
|
103
|
+
readonly "ReturnStatement[type]": (node: TSESTree.ReturnStatement) => void;
|
|
104
|
+
readonly "CallExpression[type]:exit"?: (node: TSESTree.CallExpression) => void;
|
|
105
|
+
readonly "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']"?: (node: TSESTree.AssignmentExpression & {
|
|
106
|
+
left: TSESTree.MemberExpression;
|
|
107
|
+
}) => void;
|
|
99
108
|
readonly ":function[type]": (node: AST.TSESTreeFunction) => void;
|
|
100
109
|
readonly ":function[type]:exit": () => {
|
|
101
110
|
key: string;
|
|
@@ -104,11 +113,6 @@ declare function useComponentCollector(context: RuleContext, hint?: bigint): {
|
|
|
104
113
|
isComponent: boolean;
|
|
105
114
|
} | undefined;
|
|
106
115
|
readonly "ArrowFunctionExpression[type][body.type!='BlockStatement']": () => void;
|
|
107
|
-
readonly "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']": (node: TSESTree.AssignmentExpression & {
|
|
108
|
-
left: TSESTree.MemberExpression;
|
|
109
|
-
}) => void;
|
|
110
|
-
readonly "CallExpression[type]:exit": (node: TSESTree.CallExpression) => void;
|
|
111
|
-
readonly "ReturnStatement[type]": (node: TSESTree.ReturnStatement) => void;
|
|
112
116
|
};
|
|
113
117
|
};
|
|
114
118
|
|
|
@@ -2575,4 +2579,4 @@ declare const isMemoCall: {
|
|
|
2575
2579
|
(node: Node, context: _eslint_react_types.RuleContext): node is CallExpression;
|
|
2576
2580
|
};
|
|
2577
2581
|
|
|
2578
|
-
export { DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementNameAndRepresentName, getFunctionComponentIdentifier, getId, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
|
2582
|
+
export { type ComponentCollectorOptions, DEFAULT_COMPONENT_HINT, type ERClassComponent, ERClassComponentFlag, type ERComponent, ERComponentHint, type ERComponentKind, type EREffectKind, type EREffectMethodKind, type EREffectPhaseKind, type ERFunctionComponent, ERFunctionComponentFlag, type ERHook, type ERHookKind, type ERLifecycleMethodKind, type ERLifecyclePhaseKind, type ERPhaseKind, ERPhaseRelevance, type ERSemanticEntry, type ERSemanticNode, type ERStateKind, RE_COMPONENT_NAME, RE_HOOK_NAME, getComponentNameFromIdentifier, getElementNameAndRepresentName, getFunctionComponentIdentifier, getId, hasNoneOrValidComponentName, isCallFromReact, isCallFromReactMember, isChildrenCount, isChildrenCountCall, isChildrenForEach, isChildrenForEachCall, isChildrenMap, isChildrenMapCall, isChildrenOfCreateElement, isChildrenOnly, isChildrenOnlyCall, isChildrenToArray, isChildrenToArrayCall, isClassComponent, isCleanupFunction, isCloneElement, isCloneElementCall, isComponentDidMount, isComponentDidMountFunction, isComponentName, isComponentWillUnmount, isComponentWillUnmountFunction, isCreateContext, isCreateContextCall, isCreateElement, isCreateElementCall, isCreateRef, isCreateRefCall, isDeclaredInRenderPropLoose, isDirectValueOfRenderPropertyLoose, isForwardRef, isForwardRefCall, isFromReact, isFromReactMember, isFunctionOfRenderMethod, isInitializedFromReact, isInsideCreateElementProps, isInsideReactHook, isInsideRenderMethod, isInversePhase, isMemo, isMemoCall, isPureComponent, isReactAPICallWithName, isReactAPIWithName, isReactHook, isReactHookCall, isReactHookCallWithName, isReactHookCallWithNameAlias, isReactHookCallWithNameLoose, isReactHookName, isRenderFunctionLoose, isRenderMethodLike, isRenderPropLoose, isSetupFunction, isThisSetState, isUseCallbackCall, isUseContextCall, isUseDebugValueCall, isUseDeferredValueCall, isUseEffectCall, isUseEffectCallLoose, isUseIdCall, isUseImperativeHandleCall, isUseInsertionEffectCall, isUseLayoutEffectCall, isUseMemoCall, isUseReducerCall, isUseRefCall, isUseStateCall, isUseSyncExternalStoreCall, isUseTransitionCall, useComponentCollector, useComponentCollectorLegacy, useHookCollector };
|
package/dist/index.js
CHANGED
|
@@ -164,9 +164,9 @@ var isMemoCall = isReactAPICallWithName("memo");
|
|
|
164
164
|
|
|
165
165
|
// src/element/hierarchy.ts
|
|
166
166
|
function isInsideCreateElementProps(node, context) {
|
|
167
|
-
const call = AST8__namespace.
|
|
167
|
+
const call = AST8__namespace.findParentNode(node, isCreateElementCall(context));
|
|
168
168
|
if (call == null) return false;
|
|
169
|
-
const prop = AST8__namespace.
|
|
169
|
+
const prop = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.ObjectExpression));
|
|
170
170
|
if (prop == null) return false;
|
|
171
171
|
return prop === call.arguments[1];
|
|
172
172
|
}
|
|
@@ -276,7 +276,7 @@ var isUseTransitionCall = eff.flip(isReactHookCallWithName)("useTransition");
|
|
|
276
276
|
|
|
277
277
|
// src/hook/hierarchy.ts
|
|
278
278
|
function isInsideReactHook(node) {
|
|
279
|
-
return isReactHook(AST8__namespace.
|
|
279
|
+
return isReactHook(AST8__namespace.findParentNode(node, AST8__namespace.isFunction));
|
|
280
280
|
}
|
|
281
281
|
function useHookCollector() {
|
|
282
282
|
const hooks = /* @__PURE__ */ new Map();
|
|
@@ -288,8 +288,8 @@ function useHookCollector() {
|
|
|
288
288
|
const key = getId();
|
|
289
289
|
fEntries.push({ key, node });
|
|
290
290
|
hooks.set(key, {
|
|
291
|
-
_: key,
|
|
292
291
|
id: id2,
|
|
292
|
+
key,
|
|
293
293
|
kind: "function",
|
|
294
294
|
name,
|
|
295
295
|
node,
|
|
@@ -328,13 +328,7 @@ function useHookCollector() {
|
|
|
328
328
|
if (hook == null) {
|
|
329
329
|
return;
|
|
330
330
|
}
|
|
331
|
-
|
|
332
|
-
...hook,
|
|
333
|
-
hookCalls: [
|
|
334
|
-
...hook.hookCalls,
|
|
335
|
-
node
|
|
336
|
-
]
|
|
337
|
-
});
|
|
331
|
+
hook.hookCalls.push(node);
|
|
338
332
|
}
|
|
339
333
|
};
|
|
340
334
|
return { ctx, listeners };
|
|
@@ -481,15 +475,17 @@ function hasValidHierarchy(node, context, hint) {
|
|
|
481
475
|
}
|
|
482
476
|
function getComponentFlag(initPath) {
|
|
483
477
|
let flag = ERFunctionComponentFlag.None;
|
|
484
|
-
if (initPath != null && AST8__namespace.hasCallInFunctionInitPath("memo"
|
|
478
|
+
if (initPath != null && AST8__namespace.hasCallInFunctionInitPath("memo", initPath)) {
|
|
485
479
|
flag |= ERFunctionComponentFlag.Memo;
|
|
486
480
|
}
|
|
487
|
-
if (initPath != null && AST8__namespace.hasCallInFunctionInitPath("forwardRef"
|
|
481
|
+
if (initPath != null && AST8__namespace.hasCallInFunctionInitPath("forwardRef", initPath)) {
|
|
488
482
|
flag |= ERFunctionComponentFlag.ForwardRef;
|
|
489
483
|
}
|
|
490
484
|
return flag;
|
|
491
485
|
}
|
|
492
|
-
|
|
486
|
+
var displayNameAssignmentSelector = "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']";
|
|
487
|
+
function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options = {}) {
|
|
488
|
+
const { collectDisplayName = false, collectHookCalls = false } = options;
|
|
493
489
|
const jsxCtx = { getScope: (node) => context.sourceCode.getScope(node) };
|
|
494
490
|
const components = /* @__PURE__ */ new Map();
|
|
495
491
|
const functionEntries = [];
|
|
@@ -540,8 +536,8 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
540
536
|
const name = getComponentNameFromIdentifier(id2);
|
|
541
537
|
const key = getId();
|
|
542
538
|
components.set(key, {
|
|
543
|
-
_: key,
|
|
544
539
|
id: id2,
|
|
540
|
+
key,
|
|
545
541
|
kind: "function",
|
|
546
542
|
name,
|
|
547
543
|
node: entry.node,
|
|
@@ -552,29 +548,29 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
552
548
|
initPath
|
|
553
549
|
});
|
|
554
550
|
},
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
displayName: right
|
|
565
|
-
});
|
|
566
|
-
},
|
|
567
|
-
"CallExpression[type]:exit"(node) {
|
|
568
|
-
if (!isReactHookCall(node)) {
|
|
569
|
-
return;
|
|
551
|
+
...collectDisplayName ? {
|
|
552
|
+
[displayNameAssignmentSelector](node) {
|
|
553
|
+
const { left, right } = node;
|
|
554
|
+
const componentName = left.object.type === types.AST_NODE_TYPES.Identifier ? left.object.name : eff._;
|
|
555
|
+
const component = [...components.values()].findLast(({ name }) => name != null && name === componentName);
|
|
556
|
+
if (component == null) {
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
component.displayName = right;
|
|
570
560
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
561
|
+
} : {},
|
|
562
|
+
...collectHookCalls ? {
|
|
563
|
+
"CallExpression[type]:exit"(node) {
|
|
564
|
+
if (!isReactHookCall(node)) {
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
const entry = getCurrentEntry();
|
|
568
|
+
if (entry == null) {
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
entry.hookCalls.push(node);
|
|
574
572
|
}
|
|
575
|
-
|
|
576
|
-
functionEntries.push({ ...entry, hookCalls: [...entry.hookCalls, node] });
|
|
577
|
-
},
|
|
573
|
+
} : {},
|
|
578
574
|
"ReturnStatement[type]"(node) {
|
|
579
575
|
const entry = getCurrentEntry();
|
|
580
576
|
if (entry == null) {
|
|
@@ -590,8 +586,8 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
590
586
|
const id2 = getFunctionComponentIdentifier(entry.node, context);
|
|
591
587
|
const name = getComponentNameFromIdentifier(id2);
|
|
592
588
|
components.set(entry.key, {
|
|
593
|
-
_: entry.key,
|
|
594
589
|
id: id2,
|
|
590
|
+
key: entry.key,
|
|
595
591
|
kind: "function",
|
|
596
592
|
name,
|
|
597
593
|
node: entry.node,
|
|
@@ -623,8 +619,8 @@ function useComponentCollectorLegacy() {
|
|
|
623
619
|
components.set(
|
|
624
620
|
key,
|
|
625
621
|
{
|
|
626
|
-
_: key,
|
|
627
622
|
id: id2,
|
|
623
|
+
key,
|
|
628
624
|
kind: "class",
|
|
629
625
|
name: id2?.name,
|
|
630
626
|
node,
|
|
@@ -648,9 +644,9 @@ function isSetupFunction(node) {
|
|
|
648
644
|
return node.parent?.type === types.AST_NODE_TYPES.CallExpression && node.parent.callee !== node && node.parent.callee.type === types.AST_NODE_TYPES.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent);
|
|
649
645
|
}
|
|
650
646
|
function isCleanupFunction(node) {
|
|
651
|
-
const nearReturn = AST8__namespace.
|
|
652
|
-
const nearFunction = AST8__namespace.
|
|
653
|
-
const nearFunctionOfReturn = AST8__namespace.
|
|
647
|
+
const nearReturn = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.ReturnStatement));
|
|
648
|
+
const nearFunction = AST8__namespace.findParentNode(node, AST8__namespace.isFunction);
|
|
649
|
+
const nearFunctionOfReturn = AST8__namespace.findParentNode(nearReturn, AST8__namespace.isFunction);
|
|
654
650
|
return nearFunction === nearFunctionOfReturn && isSetupFunction(nearFunction);
|
|
655
651
|
}
|
|
656
652
|
function isComponentDidMount(node) {
|
|
@@ -680,7 +676,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
680
676
|
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
681
677
|
return true;
|
|
682
678
|
}
|
|
683
|
-
const parent = AST8__namespace.
|
|
679
|
+
const parent = AST8__namespace.findParentNode(node, AST8__namespace.is(types.AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
684
680
|
if (parent?.type !== types.AST_NODE_TYPES.JSXAttribute) {
|
|
685
681
|
return false;
|
|
686
682
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -140,9 +140,9 @@ var isMemoCall = isReactAPICallWithName("memo");
|
|
|
140
140
|
|
|
141
141
|
// src/element/hierarchy.ts
|
|
142
142
|
function isInsideCreateElementProps(node, context) {
|
|
143
|
-
const call = AST8.
|
|
143
|
+
const call = AST8.findParentNode(node, isCreateElementCall(context));
|
|
144
144
|
if (call == null) return false;
|
|
145
|
-
const prop = AST8.
|
|
145
|
+
const prop = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.ObjectExpression));
|
|
146
146
|
if (prop == null) return false;
|
|
147
147
|
return prop === call.arguments[1];
|
|
148
148
|
}
|
|
@@ -252,7 +252,7 @@ var isUseTransitionCall = flip(isReactHookCallWithName)("useTransition");
|
|
|
252
252
|
|
|
253
253
|
// src/hook/hierarchy.ts
|
|
254
254
|
function isInsideReactHook(node) {
|
|
255
|
-
return isReactHook(AST8.
|
|
255
|
+
return isReactHook(AST8.findParentNode(node, AST8.isFunction));
|
|
256
256
|
}
|
|
257
257
|
function useHookCollector() {
|
|
258
258
|
const hooks = /* @__PURE__ */ new Map();
|
|
@@ -264,8 +264,8 @@ function useHookCollector() {
|
|
|
264
264
|
const key = getId();
|
|
265
265
|
fEntries.push({ key, node });
|
|
266
266
|
hooks.set(key, {
|
|
267
|
-
_: key,
|
|
268
267
|
id: id2,
|
|
268
|
+
key,
|
|
269
269
|
kind: "function",
|
|
270
270
|
name,
|
|
271
271
|
node,
|
|
@@ -304,13 +304,7 @@ function useHookCollector() {
|
|
|
304
304
|
if (hook == null) {
|
|
305
305
|
return;
|
|
306
306
|
}
|
|
307
|
-
|
|
308
|
-
...hook,
|
|
309
|
-
hookCalls: [
|
|
310
|
-
...hook.hookCalls,
|
|
311
|
-
node
|
|
312
|
-
]
|
|
313
|
-
});
|
|
307
|
+
hook.hookCalls.push(node);
|
|
314
308
|
}
|
|
315
309
|
};
|
|
316
310
|
return { ctx, listeners };
|
|
@@ -457,15 +451,17 @@ function hasValidHierarchy(node, context, hint) {
|
|
|
457
451
|
}
|
|
458
452
|
function getComponentFlag(initPath) {
|
|
459
453
|
let flag = ERFunctionComponentFlag.None;
|
|
460
|
-
if (initPath != null && AST8.hasCallInFunctionInitPath("memo"
|
|
454
|
+
if (initPath != null && AST8.hasCallInFunctionInitPath("memo", initPath)) {
|
|
461
455
|
flag |= ERFunctionComponentFlag.Memo;
|
|
462
456
|
}
|
|
463
|
-
if (initPath != null && AST8.hasCallInFunctionInitPath("forwardRef"
|
|
457
|
+
if (initPath != null && AST8.hasCallInFunctionInitPath("forwardRef", initPath)) {
|
|
464
458
|
flag |= ERFunctionComponentFlag.ForwardRef;
|
|
465
459
|
}
|
|
466
460
|
return flag;
|
|
467
461
|
}
|
|
468
|
-
|
|
462
|
+
var displayNameAssignmentSelector = "AssignmentExpression[type][operator='='][left.type='MemberExpression'][left.property.name='displayName']";
|
|
463
|
+
function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT, options = {}) {
|
|
464
|
+
const { collectDisplayName = false, collectHookCalls = false } = options;
|
|
469
465
|
const jsxCtx = { getScope: (node) => context.sourceCode.getScope(node) };
|
|
470
466
|
const components = /* @__PURE__ */ new Map();
|
|
471
467
|
const functionEntries = [];
|
|
@@ -516,8 +512,8 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
516
512
|
const name = getComponentNameFromIdentifier(id2);
|
|
517
513
|
const key = getId();
|
|
518
514
|
components.set(key, {
|
|
519
|
-
_: key,
|
|
520
515
|
id: id2,
|
|
516
|
+
key,
|
|
521
517
|
kind: "function",
|
|
522
518
|
name,
|
|
523
519
|
node: entry.node,
|
|
@@ -528,29 +524,29 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
528
524
|
initPath
|
|
529
525
|
});
|
|
530
526
|
},
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
displayName: right
|
|
541
|
-
});
|
|
542
|
-
},
|
|
543
|
-
"CallExpression[type]:exit"(node) {
|
|
544
|
-
if (!isReactHookCall(node)) {
|
|
545
|
-
return;
|
|
527
|
+
...collectDisplayName ? {
|
|
528
|
+
[displayNameAssignmentSelector](node) {
|
|
529
|
+
const { left, right } = node;
|
|
530
|
+
const componentName = left.object.type === AST_NODE_TYPES.Identifier ? left.object.name : _;
|
|
531
|
+
const component = [...components.values()].findLast(({ name }) => name != null && name === componentName);
|
|
532
|
+
if (component == null) {
|
|
533
|
+
return;
|
|
534
|
+
}
|
|
535
|
+
component.displayName = right;
|
|
546
536
|
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
537
|
+
} : {},
|
|
538
|
+
...collectHookCalls ? {
|
|
539
|
+
"CallExpression[type]:exit"(node) {
|
|
540
|
+
if (!isReactHookCall(node)) {
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
const entry = getCurrentEntry();
|
|
544
|
+
if (entry == null) {
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
entry.hookCalls.push(node);
|
|
550
548
|
}
|
|
551
|
-
|
|
552
|
-
functionEntries.push({ ...entry, hookCalls: [...entry.hookCalls, node] });
|
|
553
|
-
},
|
|
549
|
+
} : {},
|
|
554
550
|
"ReturnStatement[type]"(node) {
|
|
555
551
|
const entry = getCurrentEntry();
|
|
556
552
|
if (entry == null) {
|
|
@@ -566,8 +562,8 @@ function useComponentCollector(context, hint = DEFAULT_COMPONENT_HINT) {
|
|
|
566
562
|
const id2 = getFunctionComponentIdentifier(entry.node, context);
|
|
567
563
|
const name = getComponentNameFromIdentifier(id2);
|
|
568
564
|
components.set(entry.key, {
|
|
569
|
-
_: entry.key,
|
|
570
565
|
id: id2,
|
|
566
|
+
key: entry.key,
|
|
571
567
|
kind: "function",
|
|
572
568
|
name,
|
|
573
569
|
node: entry.node,
|
|
@@ -599,8 +595,8 @@ function useComponentCollectorLegacy() {
|
|
|
599
595
|
components.set(
|
|
600
596
|
key,
|
|
601
597
|
{
|
|
602
|
-
_: key,
|
|
603
598
|
id: id2,
|
|
599
|
+
key,
|
|
604
600
|
kind: "class",
|
|
605
601
|
name: id2?.name,
|
|
606
602
|
node,
|
|
@@ -624,9 +620,9 @@ function isSetupFunction(node) {
|
|
|
624
620
|
return node.parent?.type === AST_NODE_TYPES.CallExpression && node.parent.callee !== node && node.parent.callee.type === AST_NODE_TYPES.Identifier && node.parent.arguments.at(0) === node && isUseEffectCallLoose(node.parent);
|
|
625
621
|
}
|
|
626
622
|
function isCleanupFunction(node) {
|
|
627
|
-
const nearReturn = AST8.
|
|
628
|
-
const nearFunction = AST8.
|
|
629
|
-
const nearFunctionOfReturn = AST8.
|
|
623
|
+
const nearReturn = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.ReturnStatement));
|
|
624
|
+
const nearFunction = AST8.findParentNode(node, AST8.isFunction);
|
|
625
|
+
const nearFunctionOfReturn = AST8.findParentNode(nearReturn, AST8.isFunction);
|
|
630
626
|
return nearFunction === nearFunctionOfReturn && isSetupFunction(nearFunction);
|
|
631
627
|
}
|
|
632
628
|
function isComponentDidMount(node) {
|
|
@@ -656,7 +652,7 @@ function isDeclaredInRenderPropLoose(node) {
|
|
|
656
652
|
if (isDirectValueOfRenderPropertyLoose(node)) {
|
|
657
653
|
return true;
|
|
658
654
|
}
|
|
659
|
-
const parent = AST8.
|
|
655
|
+
const parent = AST8.findParentNode(node, AST8.is(AST_NODE_TYPES.JSXExpressionContainer))?.parent;
|
|
660
656
|
if (parent?.type !== AST_NODE_TYPES.JSXAttribute) {
|
|
661
657
|
return false;
|
|
662
658
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eslint-react/core",
|
|
3
|
-
"version": "1.24.0-next.
|
|
3
|
+
"version": "1.24.0-next.3",
|
|
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": {
|
|
@@ -38,12 +38,12 @@
|
|
|
38
38
|
"@typescript-eslint/types": "^8.19.1",
|
|
39
39
|
"@typescript-eslint/utils": "^8.19.1",
|
|
40
40
|
"ts-pattern": "^5.6.0",
|
|
41
|
-
"@eslint-react/ast": "1.24.0-next.
|
|
42
|
-
"@eslint-react/jsx": "1.24.0-next.
|
|
43
|
-
"@eslint-react/
|
|
44
|
-
"@eslint-react/
|
|
45
|
-
"@eslint-react/
|
|
46
|
-
"@eslint-react/
|
|
41
|
+
"@eslint-react/ast": "1.24.0-next.3",
|
|
42
|
+
"@eslint-react/jsx": "1.24.0-next.3",
|
|
43
|
+
"@eslint-react/shared": "1.24.0-next.3",
|
|
44
|
+
"@eslint-react/eff": "1.24.0-next.3",
|
|
45
|
+
"@eslint-react/types": "1.24.0-next.3",
|
|
46
|
+
"@eslint-react/var": "1.24.0-next.3"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"tsup": "^8.3.5",
|