@@ -43,16 +43,10 @@ export default createRule<[], MessageID>({
4343 const scope = context . sourceCode . getScope ( node ) ;
4444 const component = scope . block ;
4545 if ( ! AST . isFunction ( component ) ) return ;
46- const [ cb , deps ] = node . arguments ;
47- if ( ! deps ) {
48- context . report ( {
49- messageId : "noUnnecessaryUseCallback" ,
50- node,
51- } ) ;
52- return ;
53- }
46+ const [ arg0 , arg1 ] = node . arguments ;
47+ if ( ! arg0 || ! arg1 ) return ;
5448 const hasEmptyDeps = F . pipe (
55- match ( deps )
49+ match ( arg1 )
5650 . with ( { type : AST_NODE_TYPES . ArrayExpression } , O . some )
5751 . with ( { type : AST_NODE_TYPES . Identifier } , n => {
5852 return F . pipe (
@@ -65,15 +59,8 @@ export default createRule<[], MessageID>({
6559 O . exists ( x => x . elements . length === 0 ) ,
6660 ) ;
6761 if ( ! hasEmptyDeps ) return ;
68- if ( ! cb ) {
69- context . report ( {
70- messageId : "noUnnecessaryUseCallback" ,
71- node,
72- } ) ;
73- return ;
74- }
7562 const isReferencedToComponentScope = F . pipe (
76- match ( cb )
63+ match ( arg0 )
7764 . with ( { type : AST_NODE_TYPES . ArrowFunctionExpression } , n => {
7865 if ( n . body . type === AST_NODE_TYPES . ArrowFunctionExpression ) {
7966 return O . some ( n . body ) ;
@@ -93,11 +80,12 @@ export default createRule<[], MessageID>({
9380 O . map ( s => VAR . getChidScopes ( s ) . flatMap ( x => x . references ) ) ,
9481 O . exists ( refs => refs . some ( x => x . resolved ?. scope . block === component ) ) ,
9582 ) ;
96- if ( isReferencedToComponentScope ) return ;
97- context . report ( {
98- messageId : "noUnnecessaryUseCallback" ,
99- node,
100- } ) ;
83+ if ( ! isReferencedToComponentScope ) {
84+ context . report ( {
85+ messageId : "noUnnecessaryUseCallback" ,
86+ node,
87+ } ) ;
88+ }
10189 } ,
10290 } ;
10391 } ,
0 commit comments