File tree Expand file tree Collapse file tree 2 files changed +9
-21
lines changed Expand file tree Collapse file tree 2 files changed +9
-21
lines changed Original file line number Diff line number Diff line change 1- import { createRule , isExpectCallWithParent } from './tsUtils' ;
1+ import { createRule , isExpectCall , parseExpectCall } from './tsUtils' ;
22
33export default createRule ( {
44 name : __filename ,
@@ -12,26 +12,26 @@ export default createRule({
1212 useToStrictEqual : 'Use toStrictEqual() instead' ,
1313 } ,
1414 fixable : 'code' ,
15- schema : [ ] ,
1615 type : 'suggestion' ,
16+ schema : [ ] ,
1717 } ,
1818 defaultOptions : [ ] ,
1919 create ( context ) {
2020 return {
2121 CallExpression ( node ) {
22- if ( ! isExpectCallWithParent ( node ) ) {
22+ if ( ! isExpectCall ( node ) ) {
2323 return ;
2424 }
2525
26- const methodNode = node . parent . property ;
26+ const { matcher } = parseExpectCall ( node ) ;
2727
28- if ( methodNode && methodNode . name === 'toEqual' ) {
28+ if ( matcher && matcher . name === 'toEqual' ) {
2929 context . report ( {
30- fix ( fixer ) {
31- return [ fixer . replaceText ( methodNode , 'toStrictEqual' ) ] ;
32- } ,
30+ fix : fixer => [
31+ fixer . replaceText ( matcher . node . property , 'toStrictEqual' ) ,
32+ ] ,
3333 messageId : 'useToStrictEqual' ,
34- node : methodNode ,
34+ node : matcher . node . property ,
3535 } ) ;
3636 }
3737 } ,
Original file line number Diff line number Diff line change @@ -308,18 +308,6 @@ export const isExpectCall = (node: TSESTree.Node): node is ExpectCall =>
308308 isSupportedAccessor ( node . callee , 'expect' ) &&
309309 node . parent !== undefined ;
310310
311- interface JestExpectCallWithParent extends JestExpectCallExpression {
312- parent : JestExpectCallMemberExpression ;
313- }
314-
315- export const isExpectCallWithParent = (
316- node : TSESTree . Node ,
317- ) : node is JestExpectCallWithParent =>
318- isExpectCall ( node ) &&
319- node . parent !== undefined &&
320- node . parent . type === AST_NODE_TYPES . MemberExpression &&
321- node . parent . property . type === AST_NODE_TYPES . Identifier ;
322-
323311interface ParsedExpectMember <
324312 Name extends ExpectPropertyName = ExpectPropertyName ,
325313 Node extends ExpectMember < Name > = ExpectMember < Name >
You can’t perform that action at this time.
0 commit comments