@@ -36,21 +36,22 @@ export function isReactHookCall(node: TSESTree.Node | _) {
3636export function isReactHookCallWithName ( node : TSESTree . CallExpression | _ , context : RuleContext ) {
3737 if ( node == null ) return returnFalse ;
3838 const settings = unsafeDecodeSettings ( context . settings ) ;
39+ const importSource = settings . importSource ?? "react" ;
40+ const initialScope = context . sourceCode . getScope ( node ) ;
3941 return ( name : string ) => {
40- const initialScope = context . sourceCode . getScope ( node ) ;
4142 switch ( true ) {
4243 case node . callee . type === T . Identifier
4344 && node . callee . name === name :
4445 // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
4546 return ! settings . strictImportCheck
46- || isInitializedFromReact ( name , initialScope , settings . importSource ) ;
47+ || isInitializedFromReact ( name , importSource , initialScope ) ;
4748 case node . callee . type === T . MemberExpression
4849 && node . callee . property . type === T . Identifier
4950 && node . callee . property . name === name
5051 && "name" in node . callee . object :
5152 // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
5253 return ! settings . strictImportCheck
53- || isInitializedFromReact ( node . callee . object . name , initialScope , settings . importSource ) ;
54+ || isInitializedFromReact ( node . callee . object . name , importSource , initialScope ) ;
5455 default :
5556 return false ;
5657 }
@@ -73,21 +74,22 @@ export function isReactHookCallWithNameLoose(node: TSESTree.CallExpression | _)
7374
7475export function isReactHookCallWithNameAlias ( name : string , context : RuleContext , alias : string [ ] ) {
7576 const settings = unsafeDecodeSettings ( context ) ;
77+ const importSource = settings . importSource ?? "react" ;
7678 return ( node : TSESTree . CallExpression ) => {
7779 const initialScope = context . sourceCode . getScope ( node ) ;
7880 switch ( true ) {
7981 case node . callee . type === T . Identifier
8082 && node . callee . name === name :
8183 // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
8284 return ! settings . strictImportCheck
83- || isInitializedFromReact ( name , initialScope , settings . importSource ) ;
85+ || isInitializedFromReact ( name , importSource , initialScope ) ;
8486 case node . callee . type === T . MemberExpression
8587 && node . callee . property . type === T . Identifier
8688 && node . callee . property . name === name
8789 && "name" in node . callee . object :
8890 // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
8991 return ! settings . strictImportCheck
90- || isInitializedFromReact ( node . callee . object . name , initialScope , settings . importSource ) ;
92+ || isInitializedFromReact ( node . callee . object . name , importSource , initialScope ) ;
9193 default :
9294 return alias . some ( isReactHookCallWithNameLoose ( node ) ) ;
9395 }
0 commit comments