File tree Expand file tree Collapse file tree 2 files changed +10
-11
lines changed
Expand file tree Collapse file tree 2 files changed +10
-11
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
171170export const findPropUsedToResetAllState = (
You can’t perform that action at this time.
0 commit comments