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

Commit

Permalink
Modified the logic and error message
Browse files Browse the repository at this point in the history
  • Loading branch information
debsmita1 committed Feb 24, 2019
1 parent be2f8b4 commit f36d420
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
10 changes: 2 additions & 8 deletions src/rules/unnecessaryElseRule.ts
Expand Up @@ -42,7 +42,7 @@ export class Rule extends Lint.Rules.AbstractRule {
/* tslint:disable:object-literal-sort-keys */

public static FAILURE_STRING(name: string): string {
return `The preceding \`if\` block ends with a \`${name}\` statement. This \`else\` block is unnecessary.`;
return `The preceding \`if\` block ends with a \`${name}\` statement. This \`else\` is unnecessary.`;
}

public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
Expand Down Expand Up @@ -72,14 +72,8 @@ function walk(ctx: Lint.WalkContext<void>): void {
const elseKeyword = getPositionOfElseKeyword(node, ts.SyntaxKind.ElseKeyword);
ctx.addFailureAtNode(elseKeyword, Rule.FAILURE_STRING(jumpStatement));
}
ts.forEachChild(node.expression, cb);
ts.forEachChild(node.thenStatement, cb);
if (node.elseStatement !== undefined) {
ts.forEachChild(node.elseStatement, cb);
}
} else {
return ts.forEachChild(node, cb);
}
return ts.forEachChild(node, cb);
});
}

Expand Down
8 changes: 4 additions & 4 deletions test/rules/unnecessary-else/test.ts.lint
Expand Up @@ -252,7 +252,7 @@ const testNoJump = (a) => {
}
}

[return]: The preceding `if` block ends with a `return` statement. This `else` block is unnecessary.
[throw]: The preceding `if` block ends with a `throw` statement. This `else` block is unnecessary.
[break]: The preceding `if` block ends with a `break` statement. This `else` block is unnecessary.
[continue]: The preceding `if` block ends with a `continue` statement. This `else` block is unnecessary.
[return]: The preceding `if` block ends with a `return` statement. This `else` is unnecessary.
[throw]: The preceding `if` block ends with a `throw` statement. This `else` is unnecessary.
[break]: The preceding `if` block ends with a `break` statement. This `else` is unnecessary.
[continue]: The preceding `if` block ends with a `continue` statement. This `else` is unnecessary.
3 changes: 1 addition & 2 deletions test/rules/unnecessary-else/tslint.json
Expand Up @@ -2,5 +2,4 @@
"rules": {
"unnecessary-else": true
}
}

}

0 comments on commit f36d420

Please sign in to comment.