Bug: `no-else-after-return` does not allow `else if`'s by default like ESLint's `no-else-return` does
See original GitHub issueIssue type
Bug
Version
v1.10.0
Overview
The no-else-after-return
rule seems to, by default, be issuing warnings when else if
’s are used after return
statements.
The documentation for no-else-after-return
states that it “Works like no-else-return from eslint”, and (at least for the current version of ESLint) the default behaviour of no-else-return
allows return
statements after else if
’s.
Current behaviour
When no-else-after-return: true
is specified, the following code causes an unnecessary else after return
warning to appear for me:
const val = Math.random();
if (val > 0.5) {
return 1;
} else if (val < 0.5) {
return -1;
}
return 0;
Expected behaviour
When no-else-after-return: true
is specified, the above code should not issue a warning.
If no-else-after-return: [true, { "allowElseIf": false }]
was specified, then the above code should issue a warning.
Additional context
I use this rule as part of tslint-config-airbnb, which added no-else-after-return
to their ruleset in v5.4.1
.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:6 (4 by maintainers)
Top GitHub Comments
I don’t understand why you don’t want to use
no-unnecessary-else
, but that’s none of my business.I actually wanted to deprecate and eventually remove
no-else-after-return
because it contained a lot of duplicated and slightly modified code to handle only return statements as control flow end. The rule also had quite a few bugs that never got fixed. Fortunately I have refactored my control flow analysis and can reuse it for this rule. There’s no more duplicate code and correct control flow analysis.TL:DR
I’m going to update the rule and also add the requested option.
But there’s one thing I don’t understand: ESLint’s docs state that the following code is invalid even if
allowElseIf
is enabled. Why?The new option is published in v1.13.0