Skip to content

Commit a7b0213

Browse files
committed
Convert isDirectCall to recursive for consistency
1 parent 08ca488 commit a7b0213

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

src/rule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export const rule = {
7575
// Don't analyze HOC prop callbacks -- we don't have control over them to lift state or logic
7676
!isHOCProp(ref.resolved)),
7777
)
78-
.filter((ref) => isDirectCall(ref))
78+
.filter((ref) => isDirectCall(ref.identifier))
7979
.forEach((ref) => {
8080
const callExpr = getCallExpr(ref);
8181

src/util/react.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,18 +154,17 @@ export const getUseStateNode = (context, ref) => {
154154
// Also returns false for IIFEs, which technically could cause a false negative.
155155
// But IIFEs in effects are typically used to call async functions, implying it retrieves external state.
156156
// So, not a big deal.
157-
export const isDirectCall = (ref) => {
158-
let node = ref.identifier;
159-
160-
while (
161-
node &&
162-
node.type !== "ArrowFunctionExpression" &&
163-
node.type !== "FunctionExpression"
157+
export const isDirectCall = (node) => {
158+
if (!node) {
159+
return false;
160+
} else if (
161+
node.type === "ArrowFunctionExpression" ||
162+
node.type === "FunctionExpression"
164163
) {
165-
node = node.parent;
164+
return isUseEffect(node.parent);
165+
} else {
166+
return isDirectCall(node.parent);
166167
}
167-
168-
return node && isUseEffect(node.parent);
169168
};
170169

171170
export const findPropUsedToResetAllState = (

0 commit comments

Comments
 (0)