Skip to content

Commit a4f66f6

Browse files
authored
refactor: simplify or remove a couple of conditions (#927)
1 parent d4cdab8 commit a4f66f6

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

src/rules/no-large-snapshots.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export default createRule<[RuleOptions], MessageId>({
122122

123123
const { matcher } = parseExpectCall(node);
124124

125-
if (matcher?.node.parent?.type !== AST_NODE_TYPES.CallExpression) {
125+
if (matcher?.node.parent.type !== AST_NODE_TYPES.CallExpression) {
126126
return;
127127
}
128128

src/rules/utils.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ const reparseAsMatcher = (
418418
* If this matcher isn't called, this will be `null`.
419419
*/
420420
arguments:
421-
parsedMember.node.parent &&
422421
parsedMember.node.parent.type === AST_NODE_TYPES.CallExpression
423422
? parsedMember.node.parent.arguments
424423
: null,
@@ -453,11 +452,9 @@ const reparseMemberAsModifier = (
453452
);
454453
}
455454

456-
const negation =
457-
parsedMember.node.parent &&
458-
isExpectMember(parsedMember.node.parent, ModifierName.not)
459-
? parsedMember.node.parent
460-
: undefined;
455+
const negation = isExpectMember(parsedMember.node.parent, ModifierName.not)
456+
? parsedMember.node.parent
457+
: undefined;
461458

462459
return {
463460
...parsedMember,
@@ -506,7 +503,7 @@ export const parseExpectCall = <ExpectNode extends ExpectCall>(
506503

507504
const memberNode = modifier.negation || modifier.node;
508505

509-
if (!memberNode.parent || !isExpectMember(memberNode.parent)) {
506+
if (!isExpectMember(memberNode.parent)) {
510507
return expectation;
511508
}
512509

src/rules/valid-expect.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ const getPromiseCallExpressionNode = (node: TSESTree.Node) => {
3535

3636
if (
3737
node.type === AST_NODE_TYPES.CallExpression &&
38-
node.callee &&
3938
node.callee.type === AST_NODE_TYPES.MemberExpression &&
4039
isSupportedAccessor(node.callee.object) &&
4140
getAccessorValue(node.callee.object) === 'Promise' &&
@@ -48,21 +47,19 @@ const getPromiseCallExpressionNode = (node: TSESTree.Node) => {
4847
};
4948

5049
const findPromiseCallExpressionNode = (node: TSESTree.Node) =>
51-
node.parent &&
52-
node.parent.parent &&
50+
node.parent?.parent &&
5351
[AST_NODE_TYPES.CallExpression, AST_NODE_TYPES.ArrayExpression].includes(
5452
node.parent.type,
5553
)
5654
? getPromiseCallExpressionNode(node.parent)
5755
: null;
5856

5957
const getParentIfThenified = (node: TSESTree.Node): TSESTree.Node => {
60-
const grandParentNode = node.parent && node.parent.parent;
58+
const grandParentNode = node.parent?.parent;
6159

6260
if (
6361
grandParentNode &&
6462
grandParentNode.type === AST_NODE_TYPES.CallExpression &&
65-
grandParentNode.callee &&
6663
isExpectMember(grandParentNode.callee) &&
6764
['then', 'catch'].includes(
6865
getAccessorValue(grandParentNode.callee.property),

0 commit comments

Comments
 (0)