# prefer-unary-negation

Prefer unary negation over multiplying or dividing by -1

Multiplying or dividing a builtin numeric value by negative one performs the same operation as unary negation.
Instead, you SHOULD negate the value directly.

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

## Reported

```ds title="main.ds"
function negate(value: int32): int32 {
    return value * -1;
}
```

## Accepted

```ds title="main.ds"
function negate(value: int32): int32 {
    return -value;
}
```

## Prior art

- [Clippy · neg_multiply](https://rust-lang.github.io/rust-clippy/master/index.html#neg_multiply)
- [eslint-plugin-unicorn · prefer-unary-minus](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-unary-minus.md)

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