# no-cond-assign

Disallow assignment in conditions

An assignment expression used as a condition tests the assigned value after mutating its target, which can be mistaken for an equality comparison.
Instead, you SHOULD move the assignment before the condition or use a binding condition when the assigned value is intentionally tested.

- Category: suspicious
- Level: warning
- Fix: none
- Scope: module

## Reported

```ds title="main.ds"
function select(next: boolean): boolean {
    let active = false;
    if ((active = next)) {
        return active;
    }
    return false;
}
```

## Accepted

```ds title="main.ds"
function select(next: boolean): boolean {
    let active = next;
    if (active) {
        return active;
    }
    return false;
}
```

## Prior art

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

[language/linter/src/rules/suspicious/no_cond_assign.rs:7](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/suspicious/no_cond_assign.rs#L7)
