Skip to content

Commit

Permalink
refactor: simplify or remove a couple of conditions (#927)
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath authored Oct 9, 2021
1 parent d4cdab8 commit a4f66f6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/rules/no-large-snapshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default createRule<[RuleOptions], MessageId>({

const { matcher } = parseExpectCall(node);

if (matcher?.node.parent?.type !== AST_NODE_TYPES.CallExpression) {
if (matcher?.node.parent.type !== AST_NODE_TYPES.CallExpression) {
return;
}

Expand Down
11 changes: 4 additions & 7 deletions src/rules/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ const reparseAsMatcher = (
* If this matcher isn't called, this will be `null`.
*/
arguments:
parsedMember.node.parent &&
parsedMember.node.parent.type === AST_NODE_TYPES.CallExpression
? parsedMember.node.parent.arguments
: null,
Expand Down Expand Up @@ -453,11 +452,9 @@ const reparseMemberAsModifier = (
);
}

const negation =
parsedMember.node.parent &&
isExpectMember(parsedMember.node.parent, ModifierName.not)
? parsedMember.node.parent
: undefined;
const negation = isExpectMember(parsedMember.node.parent, ModifierName.not)
? parsedMember.node.parent
: undefined;

return {
...parsedMember,
Expand Down Expand Up @@ -506,7 +503,7 @@ export const parseExpectCall = <ExpectNode extends ExpectCall>(

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

if (!memberNode.parent || !isExpectMember(memberNode.parent)) {
if (!isExpectMember(memberNode.parent)) {
return expectation;
}

Expand Down
7 changes: 2 additions & 5 deletions src/rules/valid-expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const getPromiseCallExpressionNode = (node: TSESTree.Node) => {

if (
node.type === AST_NODE_TYPES.CallExpression &&
node.callee &&
node.callee.type === AST_NODE_TYPES.MemberExpression &&
isSupportedAccessor(node.callee.object) &&
getAccessorValue(node.callee.object) === 'Promise' &&
Expand All @@ -48,21 +47,19 @@ const getPromiseCallExpressionNode = (node: TSESTree.Node) => {
};

const findPromiseCallExpressionNode = (node: TSESTree.Node) =>
node.parent &&
node.parent.parent &&
node.parent?.parent &&
[AST_NODE_TYPES.CallExpression, AST_NODE_TYPES.ArrayExpression].includes(
node.parent.type,
)
? getPromiseCallExpressionNode(node.parent)
: null;

const getParentIfThenified = (node: TSESTree.Node): TSESTree.Node => {
const grandParentNode = node.parent && node.parent.parent;
const grandParentNode = node.parent?.parent;

if (
grandParentNode &&
grandParentNode.type === AST_NODE_TYPES.CallExpression &&
grandParentNode.callee &&
isExpectMember(grandParentNode.callee) &&
['then', 'catch'].includes(
getAccessorValue(grandParentNode.callee.property),
Expand Down

0 comments on commit a4f66f6

Please sign in to comment.