@@ -27,57 +27,60 @@ function isAntonymMatcher(matcherNode, matcherArguments) {
27
27
) ;
28
28
}
29
29
30
- function check (
31
- context ,
32
- { queryNode, matcherNode, matcherArguments, negatedMatcher, expect }
33
- ) {
34
- if ( ! queryNode || ( ! queryNode . name && ! queryNode . property ) ) return ;
35
- // toHaveLength() is only invalid with 0 or 1
36
- if ( matcherNode . name === "toHaveLength" && matcherArguments [ 0 ] . value > 1 ) {
37
- return ;
38
- }
30
+ export const create = ( context ) => {
31
+ const alternativeMatchers = / ( t o H a v e L e n g t h | t o B e D e f i n e d | t o B e N u l l ) / ;
32
+ function check ( {
33
+ queryNode,
34
+ matcherNode,
35
+ matcherArguments,
36
+ negatedMatcher,
37
+ expect,
38
+ } ) {
39
+ if ( ! queryNode || ( ! queryNode . name && ! queryNode . property ) ) return ;
40
+ // toHaveLength() is only invalid with 0 or 1
41
+ if ( matcherNode . name === "toHaveLength" && matcherArguments [ 0 ] . value > 1 ) {
42
+ return ;
43
+ }
44
+
45
+ const query = queryNode . name || queryNode . property . name ;
46
+
47
+ if ( queries . includes ( query ) ) {
48
+ context . report ( {
49
+ node : matcherNode ,
50
+ messageId : "use-document" ,
51
+ loc : matcherNode . loc ,
52
+ fix ( fixer ) {
53
+ const operations = [ ] ;
39
54
40
- const query = queryNode . name || queryNode . property . name ;
41
-
42
- if ( queries . includes ( query ) ) {
43
- context . report ( {
44
- node : matcherNode ,
45
- messageId : "use-document" ,
46
- loc : matcherNode . loc ,
47
- fix ( fixer ) {
48
- const operations = [ ] ;
49
-
50
- // Remove any arguments in the matcher
51
- for ( const argument of Array . from ( matcherArguments ) ) {
52
- operations . push ( fixer . remove ( argument ) ) ;
53
- }
54
- // Flip the .not if necessary
55
- if ( isAntonymMatcher ( matcherNode , matcherArguments ) ) {
56
- if ( negatedMatcher ) {
57
- operations . push (
58
- fixer . replaceTextRange (
59
- [ expect . range [ 1 ] , matcherNode . range [ 1 ] ] ,
60
- ".toBeInTheDocument"
61
- )
62
- ) ;
63
-
64
- return operations ;
65
- } else {
66
- operations . push ( fixer . insertTextBefore ( matcherNode , "not." ) ) ;
55
+ // Remove any arguments in the matcher
56
+ for ( const argument of Array . from ( matcherArguments ) ) {
57
+ operations . push ( fixer . remove ( argument ) ) ;
58
+ }
59
+ // Flip the .not if necessary
60
+ if ( isAntonymMatcher ( matcherNode , matcherArguments ) ) {
61
+ if ( negatedMatcher ) {
62
+ operations . push (
63
+ fixer . replaceTextRange (
64
+ [ expect . range [ 1 ] , matcherNode . range [ 1 ] ] ,
65
+ ".toBeInTheDocument"
66
+ )
67
+ ) ;
68
+
69
+ return operations ;
70
+ } else {
71
+ operations . push ( fixer . insertTextBefore ( matcherNode , "not." ) ) ;
72
+ }
67
73
}
68
- }
69
74
70
- // Replace the actual matcher
71
- operations . push ( fixer . replaceText ( matcherNode , "toBeInTheDocument" ) ) ;
75
+ // Replace the actual matcher
76
+ operations . push ( fixer . replaceText ( matcherNode , "toBeInTheDocument" ) ) ;
72
77
73
- return operations ;
74
- } ,
75
- } ) ;
78
+ return operations ;
79
+ } ,
80
+ } ) ;
81
+ }
76
82
}
77
- }
78
83
79
- export const create = ( context ) => {
80
- const alternativeMatchers = / ( t o H a v e L e n g t h | t o B e D e f i n e d | t o B e N u l l ) / ;
81
84
function getQueryNodeFromAssignment ( identifierName ) {
82
85
const variable = context . getScope ( ) . set . get ( identifierName ) ;
83
86
const init = variable . defs [ 0 ] . node . init ;
@@ -119,7 +122,7 @@ export const create = (context) => {
119
122
const matcherArguments = node . arguments ;
120
123
121
124
const expect = node . callee . object . object ;
122
- check ( context , {
125
+ check ( {
123
126
negatedMatcher : true ,
124
127
queryNode,
125
128
matcherNode,
@@ -141,7 +144,7 @@ export const create = (context) => {
141
144
142
145
const expect = node . object . object ;
143
146
144
- check ( context , {
147
+ check ( {
145
148
negatedMatcher : true ,
146
149
queryNode,
147
150
matcherNode,
@@ -160,7 +163,7 @@ export const create = (context) => {
160
163
161
164
const matcherArguments = node . parent . arguments ;
162
165
163
- check ( context , {
166
+ check ( {
164
167
negatedMatcher : false ,
165
168
queryNode,
166
169
matcherNode,
@@ -178,7 +181,7 @@ export const create = (context) => {
178
181
const matcherNode = node . callee . property ;
179
182
const matcherArguments = node . arguments ;
180
183
181
- check ( context , {
184
+ check ( {
182
185
negatedMatcher : false ,
183
186
queryNode,
184
187
matcherNode,
0 commit comments