@@ -12,8 +12,6 @@ export const RULE_NAME = 'no-node-access';
12
12
export type MessageIds = 'noNodeAccess' ;
13
13
export type Options = [ { allowContainerFirstChild : boolean } ] ;
14
14
15
- const userEventInstanceNames = new Set < string > ( ) ;
16
-
17
15
export default createTestingLibraryRule < Options , MessageIds > ( {
18
16
name : RULE_NAME ,
19
17
meta : {
@@ -52,6 +50,8 @@ export default createTestingLibraryRule<Options, MessageIds>({
52
50
] ,
53
51
54
52
create ( context , [ { allowContainerFirstChild = false } ] , helpers ) {
53
+ const userEventInstanceNames = new Set < string > ( ) ;
54
+
55
55
function showErrorForNodeAccess ( node : TSESTree . MemberExpression ) {
56
56
// This rule is so aggressive that can cause tons of false positives outside test files when Aggressive Reporting
57
57
// is enabled. Because of that, this rule will skip this mechanism and report only if some Testing Library package
@@ -144,6 +144,26 @@ export default createTestingLibraryRule<Options, MessageIds>({
144
144
userEventInstanceNames . add ( id . name ) ;
145
145
}
146
146
} ,
147
+ AssignmentExpression ( node : TSESTree . AssignmentExpression ) {
148
+ if (
149
+ ASTUtils . isIdentifier ( node . left ) &&
150
+ isCallExpression ( node . right ) &&
151
+ isMemberExpression ( node . right . callee ) &&
152
+ ASTUtils . isIdentifier ( node . right . callee . object )
153
+ ) {
154
+ const testingLibraryFn = resolveToTestingLibraryFn (
155
+ node . right ,
156
+ context
157
+ ) ;
158
+ if (
159
+ node . right . callee . object . name === testingLibraryFn ?. local &&
160
+ ASTUtils . isIdentifier ( node . right . callee . property ) &&
161
+ node . right . callee . property . name === 'setup'
162
+ ) {
163
+ userEventInstanceNames . add ( node . left . name ) ;
164
+ }
165
+ }
166
+ } ,
147
167
'ExpressionStatement MemberExpression' : showErrorForNodeAccess ,
148
168
'VariableDeclarator MemberExpression' : showErrorForNodeAccess ,
149
169
} ;
0 commit comments