no-lonely-if
eslint
Safe autofix
eslint.config.js
export default [
{
rules: {
"no-lonely-if": "error",
},
},
];if (condition) {
// ...
} else {
if (anotherCondition) {
// ...
}
}
if (condition) {
// ...
} else {
if (anotherCondition) {
// ...
} else {
// ...
}
}if (condition) {
// ...
} else if (anotherCondition) {
// ...
}
if (condition) {
// ...
} else if (anotherCondition) {
// ...
} else {
// ...
}
if (condition) {
// ...
} else {
if (anotherCondition) {
// ...
}
doSomething();
}Examples from the ESLint documentation.
no-lonely-if
eslint
export default [
{
rules: {
"no-lonely-if": "error",
},
},
];no-lonely-if
eslint plugin · pedantic
{
"rules": {
"no-lonely-if": "error"
}
}style/useCollapsedElseIf
style · since 1.1.0
{
"linter": {
"rules": {
"style": {
"useCollapsedElseIf": "error"
}
}
}
}Disallow if statements as the only statement in if blocks without else.
Disallow use of chained assignment expressions
Require braces around arrow function bodies
Require or disallow assignment operator shorthand where possible
Disallow returning values from Promise executor functions