# unnecessary-sort-comparator

Disallow comparators that reproduce the natural ordering

A comparator that only calls `left.compare(right)` selects the collection element's natural order.
Instead, you SHOULD omit the comparator and use the natural-order overload.

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

## Reported

```ds title="main.ds"
function order(values: int32[]): void {
    values.sort((left, right) => left.compare(right));
}
```

## Accepted

```ds title="main.ds"
function order(values: int32[]): void {
    values.sort();
}
```

## Prior art

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

[language/linter/src/rules/performance/unnecessary_sort_comparator.rs:10](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/performance/unnecessary_sort_comparator.rs#L10)
