useCollapsedIf
Este conteúdo não está disponível em sua língua ainda.
Diagnostic Category: lint/nursery/useCollapsedIf
Since: v1.9.4
Sources:
- Same as:
unicorn/no-lonely-if
- Same as:
collapsible_if
Enforce using single if
instead of nested if
clauses.
If an if (b)
statement is the only statement in an if (a)
block, it is often clearer to use an if (a && b)
form.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:1:17 lint/nursery/useCollapsedIf FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This if statement can be collapsed into another if statement.
> 1 │ if (condition) {
│
> 2 │ if (anotherCondition) {
> 3 │ // …
> 4 │ }
│ ^
5 │ }
6 │
ℹ Safe fix: Use collapsed if instead.
1 │ - if·(condition)·{
2 │ - ····if·(anotherCondition)·{
1 │ + if·(condition·&&·anotherCondition)·{
3 2 │ // …
4 │ - ····}
5 │ - }
3 │ + ····}
6 4 │
code-block.js:1:17 lint/nursery/useCollapsedIf ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ This if statement can be collapsed into another if statement.
> 1 │ if (condition) {
│
> 2 │ // Comment
> 3 │ if (anotherCondition) {
> 4 │ // …
> 5 │ }
│ ^
6 │ }
7 │