# misrefactored-assign-op

Disallow compound assignments that repeat the assigned place

A compound assignment already reads its target, so repeating that target in the assigned operation applies it twice.
Instead, you SHOULD retain only the other operand on the right-hand side.

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

## Reported

```ds title="main.ds"
function add(value: int32, amount: int32): int32 {
    let result = value;
    result += result + amount;
    return result;
}
```

## Accepted

```ds title="main.ds"
function add(value: int32, amount: int32): int32 {
    let result = value;
    result += amount;
    return result;
}
```

## Prior art

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

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