@@ -47,6 +47,7 @@ export function useNoDirectSetStateInUseEffect<Ctx extends RuleContext>(
4747 const { onViolation, useEffectKind } = options ;
4848 const settings = getSettingsFromContext ( context ) ;
4949 const additionalHooks = settings . additionalHooks ;
50+ const getText = ( n : TSESTree . Node ) => context . sourceCode . getText ( n ) ;
5051 const isUseEffectLikeCall = ER . isReactHookCallWithNameAlias ( context , useEffectKind , additionalHooks [ useEffectKind ] ) ;
5152 const isUseStateCall = ER . isReactHookCallWithNameAlias ( context , "useState" , additionalHooks . useState ) ;
5253 const isUseMemoCall = ER . isReactHookCallWithNameAlias ( context , "useMemo" , additionalHooks . useMemo ) ;
@@ -80,6 +81,13 @@ export function useNoDirectSetStateInUseEffect<Ctx extends RuleContext>(
8081 && isUseEffectLikeCall ( node . parent ) ;
8182 }
8283
84+ function getCallName ( node : TSESTree . Node ) {
85+ if ( node . type === T . CallExpression ) {
86+ return AST . toString ( node . callee , getText ) ;
87+ }
88+ return AST . toString ( node , getText ) ;
89+ }
90+
8391 function getCallKind ( node : TSESTree . CallExpression ) {
8492 return match < TSESTree . CallExpression , CallKind > ( node )
8593 . when ( isUseStateCall , ( ) => "useState" )
@@ -221,15 +229,15 @@ export function useNoDirectSetStateInUseEffect<Ctx extends RuleContext>(
221229 const setStateCalls = getSetStateCalls ( name , context . sourceCode . getScope ( callee ) ) ;
222230 for ( const setStateCall of setStateCalls ) {
223231 onViolation ( context , setStateCall , {
224- name : AST . toString ( setStateCall , ( n ) => context . sourceCode . getText ( n ) ) ,
232+ name : getCallName ( setStateCall ) ,
225233 } ) ;
226234 }
227235 }
228236 for ( const id of setupFunctionIdentifiers ) {
229237 const setStateCalls = getSetStateCalls ( id . name , context . sourceCode . getScope ( id ) ) ;
230238 for ( const setStateCall of setStateCalls ) {
231239 onViolation ( context , setStateCall , {
232- name : AST . toString ( setStateCall , ( n ) => context . sourceCode . getText ( n ) ) ,
240+ name : getCallName ( setStateCall ) ,
233241 } ) ;
234242 }
235243 }
0 commit comments