@@ -30,31 +30,10 @@ const isNullEqualityMatcher = (
3030) : matcher is ParsedEqualityMatcherCall < MaybeTypeCast < TSESTree . NullLiteral > > =>
3131 isNullLiteral ( getFirstArgument ( matcher ) ) ;
3232
33- interface UndefinedIdentifier extends TSESTree . Identifier {
34- name : 'undefined' ;
35- }
36-
37- /**
38- * Checks if the given `ParsedEqualityMatcherCall` is a call to one of the equality matchers,
39- * with a `undefined` identifier as the sole argument.
40- */
41- const isUndefinedEqualityMatcher = (
42- matcher : ParsedEqualityMatcherCall ,
43- ) : matcher is ParsedEqualityMatcherCall < UndefinedIdentifier > =>
44- isIdentifier ( getFirstArgument ( matcher ) , 'undefined' ) ;
45-
46- interface NaNIdentifier extends TSESTree . Identifier {
47- name : 'NaN' ;
48- }
49-
50- /**
51- * Checks if the given `ParsedEqualityMatcherCall` is a call to one of the equality matchers,
52- * with a `NaN` identifier as the sole argument.
53- */
54- const isNaNEqualityMatcher = (
33+ const isFirstArgumentIdentifier = (
5534 matcher : ParsedEqualityMatcherCall ,
56- ) : matcher is ParsedEqualityMatcherCall < NaNIdentifier > =>
57- isIdentifier ( getFirstArgument ( matcher ) , 'NaN' ) ;
35+ name : string ,
36+ ) => isIdentifier ( getFirstArgument ( matcher ) , name ) ;
5837
5938const isPrimitiveLiteral = ( matcher : ParsedEqualityMatcherCall ) =>
6039 getFirstArgument ( matcher ) . type === AST_NODE_TYPES . Literal ;
@@ -140,8 +119,7 @@ export default createRule({
140119 }
141120
142121 if (
143- modifier &&
144- ( modifier . name === ModifierName . not || modifier . negation ) &&
122+ ( modifier ?. name === ModifierName . not || modifier ?. negation ) &&
145123 [ 'toBeUndefined' , 'toBeDefined' ] . includes ( matcher . name )
146124 ) {
147125 reportPreferToBe (
@@ -164,10 +142,9 @@ export default createRule({
164142 return ;
165143 }
166144
167- if ( isUndefinedEqualityMatcher ( matcher ) ) {
145+ if ( isFirstArgumentIdentifier ( matcher , 'undefined' ) ) {
168146 const name =
169- modifier &&
170- ( modifier . name === ModifierName . not || modifier . negation )
147+ modifier ?. name === ModifierName . not || modifier ?. negation
171148 ? 'Defined'
172149 : 'Undefined' ;
173150
@@ -176,15 +153,15 @@ export default createRule({
176153 return ;
177154 }
178155
179- if ( isNaNEqualityMatcher ( matcher ) ) {
156+ if ( isFirstArgumentIdentifier ( matcher , 'NaN' ) ) {
180157 reportPreferToBe ( context , 'NaN' , matcher ) ;
181158
182159 return ;
183160 }
184161
185162 if (
186163 isPrimitiveLiteral ( matcher ) &&
187- ! isParsedEqualityMatcherCall ( matcher , EqualityMatcher . toBe )
164+ matcher . name !== EqualityMatcher . toBe
188165 ) {
189166 reportPreferToBe ( context , '' , matcher ) ;
190167 }
0 commit comments