sindresorhus/eslint-plugin-unicorn
Rule proposal: `no-useless-else`
Geschlossen
#987 geöffnet am 02.01.2021
help wantednew rule
Repository-Metriken
- Stars
- (5.022 Sterne)
- PR-Merge-Metriken
- (Durchschn. Merge 1T 16h) (399 gemergte PRs in 30 T)
Beschreibung
If the body of if contains one of these keywords, the else is moot:
throwbreakcontinuereturn
This slightly overlaps with https://eslint.org/docs/rules/no-else-return
This was inspired by https://github.com/eslint/eslint/issues/13067.
This could be auto-fixed, but we should take care to properly move any comments.
Fail
if (foo) {
throw new Error();
} else {
console.log('🦄');
}
Pass
if (foo) {
throw new Error();
}
console.log('🦄');