no-useless-return
eslint
Safe autofix
eslint.config.js
export default [
{
rules: {
"no-useless-return": "error",
},
},
];const foo = function() { return; }
const bar = function() {
doSomething();
return;
}
const baz = function() {
if (condition) {
qux();
return;
} else {
quux();
}
}
const item = function() {
switch (bar) {
case 1:
doSomething();
default:
doSomethingElse();
return;
}
}const foo = function() { return 5; }
const bar = function() {
return doSomething();
}
const baz = function() {
if (condition) {
qux();
return;
} else {
quux();
}
qux();
}
const item = function() {
switch (bar) {
case 1:
doSomething();
return;
default:
doSomethingElse();
}
}
const func = function() {
for (const foo of bar) {
return;
}
}Examples from the ESLint documentation.
no-useless-return
eslint
export default [
{
rules: {
"no-useless-return": "error",
},
},
];no-useless-return
eslint plugin · pedantic
{
"rules": {
"no-useless-return": "error"
}
}complexity/noUselessReturn
complexity · since 2.3.15
{
"linter": {
"rules": {
"complexity": {
"noUselessReturn": "error"
}
}
}
}Disallow loops with a body that allows only one iteration
Require or disallow method and property shorthand syntax for object literals
Require using Error objects as Promise rejection reasons
Disallow specified global variables