no-lonely-if
What it does
Section titled “What it does”Reports an if that is the only statement of an else block (else { if (b) { ... } }), also when that if has its own else. An else block with other statements, and an if inside an else if, are not reported.
Why it matters
Section titled “Why it matters”else { if (b) ... } is the same as else if (b) ... and has one more level of nesting and braces for the reader to follow.
To fix, write else if.
Example
Section titled “Example”if (a) { b(); } else { if (c) { d(); } }if (a) { b(); } else { if (c) { d(); } e(); }if (a) { b(); } else if (c) { d(); }...Configuration
Section titled “Configuration”js: lint: rules: no-lonely-if: warn # off (default), warn, errorSuppress one line with sudsy-disable-next-line no-lonely-if in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| eslint | no-lonely-if |
full |