@@ -34,33 +34,45 @@ export const rule = createRule({
34
34
defaultOptions : [ ] ,
35
35
36
36
create : detectTanstackQueryImports ( ( context , _ , helpers ) => {
37
+ const queryResultVariables = new Set < string > ( )
38
+
37
39
return {
38
40
CallExpression : ( node ) => {
39
41
if (
40
42
! ASTUtils . isIdentifierWithOneOfNames ( node . callee , queryHooks ) ||
41
- ! helpers . isTanstackQueryImport ( node . callee ) ||
42
- node . parent . type !== AST_NODE_TYPES . VariableDeclarator
43
+ node . parent . type !== AST_NODE_TYPES . VariableDeclarator ||
44
+ ! helpers . isTanstackQueryImport ( node . callee )
43
45
) {
44
46
return
45
47
}
46
48
47
49
const returnValue = node . parent . id
50
+
48
51
if (
49
52
node . callee . name !== 'useQueries' &&
50
53
node . callee . name !== 'useSuspenseQueries'
51
54
) {
52
55
if ( NoRestDestructuringUtils . isObjectRestDestructuring ( returnValue ) ) {
53
- context . report ( {
56
+ return context . report ( {
54
57
node : node . parent ,
55
58
messageId : 'objectRestDestructure' ,
56
59
} )
57
60
}
61
+
62
+ if ( returnValue . type === AST_NODE_TYPES . Identifier ) {
63
+ queryResultVariables . add ( returnValue . name )
64
+ }
65
+
58
66
return
59
67
}
60
68
61
69
if ( returnValue . type !== AST_NODE_TYPES . ArrayPattern ) {
70
+ if ( returnValue . type === AST_NODE_TYPES . Identifier ) {
71
+ queryResultVariables . add ( returnValue . name )
72
+ }
62
73
return
63
74
}
75
+
64
76
returnValue . elements . forEach ( ( queryResult ) => {
65
77
if ( queryResult === null ) {
66
78
return
@@ -73,6 +85,31 @@ export const rule = createRule({
73
85
}
74
86
} )
75
87
} ,
88
+
89
+ VariableDeclarator : ( node ) => {
90
+ if (
91
+ node . init ?. type === AST_NODE_TYPES . Identifier &&
92
+ queryResultVariables . has ( node . init . name ) &&
93
+ NoRestDestructuringUtils . isObjectRestDestructuring ( node . id )
94
+ ) {
95
+ context . report ( {
96
+ node,
97
+ messageId : 'objectRestDestructure' ,
98
+ } )
99
+ }
100
+ } ,
101
+
102
+ SpreadElement : ( node ) => {
103
+ if (
104
+ node . argument . type === AST_NODE_TYPES . Identifier &&
105
+ queryResultVariables . has ( node . argument . name )
106
+ ) {
107
+ context . report ( {
108
+ node,
109
+ messageId : 'objectRestDestructure' ,
110
+ } )
111
+ }
112
+ } ,
76
113
}
77
114
} ) ,
78
115
} )
0 commit comments