Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
[unnecessary-else] Simplified if condition
Browse files Browse the repository at this point in the history
  • Loading branch information
timocov committed Mar 24, 2019
1 parent 88397d9 commit 674296a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/rules/unnecessaryElseRule.ts
Expand Up @@ -79,11 +79,13 @@ function walk(ctx: Lint.WalkContext<Options>): void {
? getJumpStatement(getLastStatement(node.thenStatement))
: getJumpStatement(node.thenStatement);

if (jumpStatement !== undefined && node.elseStatement !== undefined) {
if (!utils.isIfStatement(node.elseStatement) || !ctx.options.allowElseIf) {
const elseKeyword = getPositionOfElseKeyword(node, ts.SyntaxKind.ElseKeyword);
ctx.addFailureAtNode(elseKeyword, Rule.FAILURE_STRING(jumpStatement));
}
if (
jumpStatement !== undefined &&
node.elseStatement !== undefined &&
(!utils.isIfStatement(node.elseStatement) || !ctx.options.allowElseIf)
) {
const elseKeyword = getPositionOfElseKeyword(node, ts.SyntaxKind.ElseKeyword);
ctx.addFailureAtNode(elseKeyword, Rule.FAILURE_STRING(jumpStatement));
}
}
return ts.forEachChild(node, cb);
Expand Down

0 comments on commit 674296a

Please sign in to comment.