@@ -32,8 +32,10 @@ function isAntonymMatcher(matcherNode, matcherArguments) {
3232}
3333
3434function usesToBeOrToEqualWithNull ( matcherNode , matcherArguments ) {
35- return ( matcherNode . name === "toBe" || matcherNode . name === "toEqual" ) &&
36- matcherArguments [ 0 ] . value === null ;
35+ return (
36+ ( matcherNode . name === "toBe" || matcherNode . name === "toEqual" ) &&
37+ matcherArguments [ 0 ] . value === null
38+ ) ;
3739}
3840
3941function usesToHaveLengthZero ( matcherNode , matcherArguments ) {
@@ -71,7 +73,7 @@ export const create = (context) => {
7173 if ( ! queryNode || ( ! queryNode . name && ! queryNode . property ) ) return ;
7274
7375 // toHaveLength() is only invalid with 0 or 1
74- if ( matcherNode . name === "toHaveLength" ) {
76+ if ( matcherNode . name === "toHaveLength" && matcherArguments . length ) {
7577 const lengthValue = getLengthValue ( matcherArguments ) ;
7678 // isNotToHaveLengthZero represents .not.toHaveLength(0) which is a valid use of toHaveLength
7779 const isNotToHaveLengthZero =
@@ -89,7 +91,10 @@ export const create = (context) => {
8991
9092 // toBe() or toEqual() are only invalid with null
9193 if ( matcherNode . name === "toBe" || matcherNode . name === "toEqual" ) {
92- if ( ! usesToBeOrToEqualWithNull ( matcherNode , matcherArguments ) ) {
94+ if (
95+ ! matcherArguments . length ||
96+ ! usesToBeOrToEqualWithNull ( matcherNode , matcherArguments )
97+ ) {
9398 return ;
9499 }
95100 }
@@ -146,6 +151,10 @@ export const create = (context) => {
146151 [ `CallExpression[callee.object.object.callee.name='expect'][callee.object.property.name='not'][callee.property.name=${ alternativeMatchers } ], CallExpression[callee.object.callee.name='expect'][callee.object.property.name='not'][callee.object.arguments.0.argument.callee.name=${ alternativeMatchers } ]` ] (
147152 node
148153 ) {
154+ if ( ! node . callee . object . object . arguments . length ) {
155+ return ;
156+ }
157+
149158 const arg = node . callee . object . object . arguments [ 0 ] ;
150159 const queryNode =
151160 arg . type === "AwaitExpression" ? arg . argument . callee : arg . callee ;
0 commit comments