Skip to content

Commit b39aad5

Browse files
G-RathSimenB
authored andcommitted
chore(prefer-strict-equal): use parseExpectCall (#388)
1 parent 4ca5889 commit b39aad5

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

src/rules/prefer-strict-equal.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createRule, isExpectCallWithParent } from './tsUtils';
1+
import { createRule, isExpectCall, parseExpectCall } from './tsUtils';
22

33
export 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
},

src/rules/tsUtils.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff 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-
323311
interface ParsedExpectMember<
324312
Name extends ExpectPropertyName = ExpectPropertyName,
325313
Node extends ExpectMember<Name> = ExpectMember<Name>

0 commit comments

Comments
 (0)