# no-lonely-if

Disallow an if statement as the only statement in an else block

`else { if (condition) ... }` has the same control flow as `else if (condition) ...` when the block contains no other statements.
Instead, you SHOULD flatten the nested `if` into the existing conditional chain.

- Category: style
- Level: warning
- Fix: automatic
- Scope: module

## Reported

```ds title="main.ds"
function classify(value: int32): string {
    if (value > 0) {
        return "positive";
    } else {
        if (value < 0) {
            return "negative";
        }
    }
    return "zero";
}
```

## Accepted

```ds title="main.ds"
function classify(value: int32): string {
    if (value > 0) {
        return "positive";
    } else if (value < 0) {
        return "negative";
    }
    return "zero";
}
```

## Prior art

- [ESLint · no-lonely-if](https://eslint.org/docs/latest/rules/no-lonely-if)

[language/linter/src/rules/style/no_lonely_if.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/style/no_lonely_if.rs#L8)
