unicorn/no-useless-else
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-useless-else": "error",
},
},
];function run() {
if (foo) {
return;
} else {
bar();
}
}if (foo) {
throw new Error();
} else if (bar) {
baz();
}function run() {
if (foo) {
return;
}
bar();
}if (foo) {
throw new Error();
}
if (bar) {
baz();
}Examples from the ESLint documentation.
unicorn/no-useless-else
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/no-useless-else": "error",
},
},
];Oxlint does not have this rule.
Biome does not have this rule.
Require assignment operator shorthand where possible.
Disallow known values that JSON serialization cannot represent faithfully.
Prefer AbortSignal.any() over manually forwarding abort events between signals.
Disallow parameters that receive the same value at every call.
Prefer AbortSignal.timeout() over manually aborting an AbortController with setTimeout().