eslint-plugin-no-else-if
v1.0.0
Published
ESLint rule to disallow any `else if` branches
Maintainers
Readme
eslint-plugin-no-else-if
ESLint plugin that forbids any else if branches. Use it if you want conditionals written as top-level if statements or other control structures.
Installation
npm install --save-dev eslint eslint-plugin-no-else-ifUsage
Add the plugin and rule to your ESLint config:
{
"plugins": ["no-else-if"],
"rules": {
"no-else-if/no-else-if": "error"
}
}Rule: no-else-if/no-else-if
- What it does: Reports any
IfStatementused as thealternatebranch of anotherif(i.e., anelse if). - Why: Encourages flatter branching using separate
ifstatements,switch, or other patterns. - Options: None.
- Fixer: Not provided; refactoring can change control flow.
Incorrect
if (conditionA) {
doA();
} else if (conditionB) {
doB(); // reported
}Correct
if (conditionA) {
doA();
}
if (conditionB) {
doB();
}