# no-collapsible-if

Prefer one condition over nested if statements without alternatives

Nested `if` statements without `else` branches require both conditions before running the same body.
Instead, you SHOULD join the conditions with `&&` in one `if` statement.

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

## Reported

```ds title="main.ds"
declare function run(): void;

function runWhen(ready: boolean, enabled: boolean): void {
    if (ready) {
        if (enabled) {
            run();
        }
    }
}
```

## Accepted

```ds title="main.ds"
declare function run(): void;

function runWhen(ready: boolean, enabled: boolean): void {
    if (ready && enabled) {
        run();
    }
}
```

## Prior art

- [Clippy · collapsible_if](https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if)

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