@@ -22,8 +22,6 @@ export const RULE_NAME = 'no-node-access';
22
22
export type MessageIds = 'noNodeAccess' ;
23
23
export type Options = [ { allowContainerFirstChild : boolean } ] ;
24
24
25
- const userEventInstanceNames = new Set < string > ( ) ;
26
-
27
25
export default createTestingLibraryRule < Options , MessageIds > ( {
28
26
name : RULE_NAME ,
29
27
meta : {
@@ -62,6 +60,8 @@ export default createTestingLibraryRule<Options, MessageIds>({
62
60
] ,
63
61
64
62
create ( context , [ { allowContainerFirstChild = false } ] , helpers ) {
63
+ const userEventInstanceNames = new Set < string > ( ) ;
64
+
65
65
function showErrorForNodeAccess ( node : TSESTree . MemberExpression ) {
66
66
// This rule is so aggressive that can cause tons of false positives outside test files when Aggressive Reporting
67
67
// is enabled. Because of that, this rule will skip this mechanism and report only if some Testing Library package
@@ -169,6 +169,26 @@ export default createTestingLibraryRule<Options, MessageIds>({
169
169
userEventInstanceNames . add ( id . name ) ;
170
170
}
171
171
} ,
172
+ AssignmentExpression ( node : TSESTree . AssignmentExpression ) {
173
+ if (
174
+ ASTUtils . isIdentifier ( node . left ) &&
175
+ isCallExpression ( node . right ) &&
176
+ isMemberExpression ( node . right . callee ) &&
177
+ ASTUtils . isIdentifier ( node . right . callee . object )
178
+ ) {
179
+ const testingLibraryFn = resolveToTestingLibraryFn (
180
+ node . right ,
181
+ context
182
+ ) ;
183
+ if (
184
+ node . right . callee . object . name === testingLibraryFn ?. local &&
185
+ ASTUtils . isIdentifier ( node . right . callee . property ) &&
186
+ node . right . callee . property . name === 'setup'
187
+ ) {
188
+ userEventInstanceNames . add ( node . left . name ) ;
189
+ }
190
+ }
191
+ } ,
172
192
'ExpressionStatement MemberExpression' : showErrorForNodeAccess ,
173
193
'VariableDeclarator MemberExpression' : showErrorForNodeAccess ,
174
194
} ;
0 commit comments