no-else-return
eslint
Safe autofix
eslint.config.js
export default [
{
rules: {
"no-else-return": "error",
},
},
];function foo1() {
if (x) {
return y;
} else {
return z;
}
}
function foo2() {
if (x) {
return y;
} else {
const t = "foo";
}
}
function foo3() {
if (error) {
return 'It failed';
} else {
if (loading) {
return "It's still loading";
}
}
}
// Two warnings for nested occurrences
function foo4() {
if (x) {
if (y) {
return y;
} else {
// …function foo1() {
if (x) {
return y;
}
return z;
}
function foo2() {
if (x) {
return y;
}
const t = "foo";
}
function foo3() {
if (error) {
return 'It failed';
}
if (loading) {
return "It's still loading";
}
}
function foo4() {
if (x) {
if (y) {
return y;
}
// …Examples from the ESLint documentation.
no-else-return
eslint
export default [
{
rules: {
"no-else-return": "error",
},
},
];no-else-return
eslint plugin · pedantic
{
"rules": {
"no-else-return": "error"
}
}style/noUselessElse
style · since 1.3.0
{
"linter": {
"rules": {
"style": {
"noUselessElse": "error"
}
}
}
}Require or disallow assignment operator shorthand where possible
Require destructuring from arrays and/or objects
Disallow use of chained assignment expressions
Disallow if statements as the only statement in else blocks
Require or disallow named function expressions