Skip to content

Commit

Permalink
refactor(valid-expect-in-promise): adjust conditions to dedent code
Browse files Browse the repository at this point in the history
  • Loading branch information
G-Rath committed Oct 2, 2021
1 parent bc86bab commit f794b0d
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions src/rules/valid-expect-in-promise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,32 +217,32 @@ export default createRule<unknown[], MessageIds>({
return;
}

if (isPromiseChainCall(node)) {
if (chains.shift()) {
const topNode = findStartingStatementInTestBody(node);

if (!topNode) {
return;
}

if (
topNode.type === AST_NODE_TYPES.VariableDeclaration &&
isVariableAwaitedOrReturned(topNode)
) {
return;
}

if (
topNode.type === AST_NODE_TYPES.ReturnStatement ||
(topNode.type === AST_NODE_TYPES.ExpressionStatement &&
topNode.expression.type === AST_NODE_TYPES.AwaitExpression)
) {
return;
}

reportReturnRequired(context, topNode);
}
if (!isPromiseChainCall(node) || !chains.shift()) {
return;
}

const topNode = findStartingStatementInTestBody(node);

if (!topNode) {
return;
}

if (
topNode.type === AST_NODE_TYPES.VariableDeclaration &&
isVariableAwaitedOrReturned(topNode)
) {
return;
}

if (
topNode.type === AST_NODE_TYPES.ReturnStatement ||
(topNode.type === AST_NODE_TYPES.ExpressionStatement &&
topNode.expression.type === AST_NODE_TYPES.AwaitExpression)
) {
return;
}

reportReturnRequired(context, topNode);
},
};
},
Expand Down

0 comments on commit f794b0d

Please sign in to comment.