unicorn/no-lonely-if Pedantic
What it does
Disallow if
statements as the only statement in if
blocks without else
.
Why is this bad?
It can be confusing to have an if
statement without an else
clause as the only statement in an if
block.
Example
Examples of incorrect code for this rule:
javascript
if (foo) {
if (bar) {
}
}
if (foo) if (bar) baz();
Examples of correct code for this rule:
javascript
if (foo && bar) {
}
if (foo && bar) baz();
How to use
To enable this rule in the CLI or using the config file, you can use:
bash
oxlint --deny unicorn/no-lonely-if
json
{
"rules": {
"unicorn/no-lonely-if": "error"
}
}