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

Rule suggestion: unnecessary-else #4429

Closed
JoshuaKGoldberg opened this issue Jan 2, 2019 · 2 comments · Fixed by #4502
Closed

Rule suggestion: unnecessary-else #4429

JoshuaKGoldberg opened this issue Jan 2, 2019 · 2 comments · Fixed by #4502

Comments

@JoshuaKGoldberg
Copy link
Contributor

JoshuaKGoldberg commented Jan 2, 2019

Rule Suggestion

Is your rule for a general problem or is it specific to your development style?

General problem

What does your suggested rule do?

If an if block contains a return, throw, continue or break statement, the else block becomes unnecessary. Its contents can be placed outside of the block.

List several examples where your rule could be used

Instead of:

if (foo) {
    throw new Error();
} else {
    // ...
}

Prefer:

if (foo) {
    throw new Error();
}

// ...

See https://github.com/ajafff/tslint-consistent-codestyle/blob/master/docs/no-unnecessary-else.md

Additional context

Spinning off of #2040: moving some rules of tslint-consistent-codestyle to tslint core.
Note that as ajafff mentioned, copied code without substantial changes needs to retain the original license.

@debsmita1
Copy link
Contributor

debsmita1 commented Jan 14, 2019

I am working on this at the moment. Do let me know if there is something that I should keep in mind. :)

@debsmita1
Copy link
Contributor

@JoshuaKGoldberg Could you kindly review this PR and tell me where am I going wrong ? :)

@adidahiya adidahiya added this to the 5.14.0 milestone Mar 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants