# require-array-sort-compare

Rule `typescript/require-array-sort-compare`. Require `Array#sort` and `Array#toSorted` calls to always provide a `compareFunction`

- Source: typescript
- Technologies: TypeScript
- Kind: correctness
- Needs type information: yes
- Autofix: no
- Reach: 53.5M weekly downloads of presets that enable it
- Trend: +177.1% last quarter
- Rank: #241 by reach, #4 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `@typescript-eslint/require-array-sort-compare` | no | no | package `@typescript-eslint/eslint-plugin` | [docs](https://typescript-eslint.io/rules/require-array-sort-compare) |
| Oxlint | `typescript/require-array-sort-compare` | yes | no | plugin `typescript`, category correctness | [docs](https://oxc.rs/docs/guide/usage/linter/rules/typescript/require-array-sort-compare.html) |
| Biome | `suspicious/useArraySortCompare` | no | no | group suspicious, since 2.3.5 | [docs](https://biomejs.dev/linter/rules/use-array-sort-compare/) |

## Code examples

### Incorrect: the rule reports this

```ts
const array: any[];
const stringArray: string[];

array.sort();

// String arrays should be sorted using `String#localeCompare`.
stringArray.sort();
```

### Correct: the rule accepts this

```ts
const array: any[];
const userDefinedType: { sort(): void };

array.sort((a, b) => a - b);
array.sort((a, b) => a.localeCompare(b));

userDefinedType.sort();
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import tseslint from "typescript-eslint";

export default [
  {
    plugins: { "@typescript-eslint": tseslint.plugin },
    rules: {
      "@typescript-eslint/require-array-sort-compare": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "typescript/require-array-sort-compare": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "suspicious": {
        "useArraySortCompare": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Oxlint default](https://lintradar.dev/presets/oxlint-default.md) | Oxlint | `oxlint` | 111 | 50.8M | +183.6% |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |
| [eslint-config-love](https://lintradar.dev/presets/love.md) | ESLint | `eslint-config-love` | 258 | 171.7K | +39.3% |

## Related rules

- [unicorn/require-array-sort-compare](https://lintradar.dev/rules/unicorn/require-array-sort-compare.md): Require a compare function when calling `Array#sort()` or `Array#toSorted()`.
- [typescript/no-unnecessary-parameter-property-assignment](https://lintradar.dev/rules/typescript/no-unnecessary-parameter-property-assignment.md): Disallow unnecessary assignment of constructor property parameter
- [typescript/no-useless-constructor](https://lintradar.dev/rules/typescript/no-useless-constructor.md): Disallow unnecessary constructors
- [typescript/consistent-type-assertions](https://lintradar.dev/rules/typescript/consistent-type-assertions.md): Enforce consistent usage of type assertions
- [typescript/no-non-null-assertion](https://lintradar.dev/rules/typescript/no-non-null-assertion.md): Disallow non-null assertions using the `!` postfix operator
- [typescript/no-unnecessary-type-assertion](https://lintradar.dev/rules/typescript/no-unnecessary-type-assertion.md): Disallow type assertions that do not change the type of an expression

---

Web page: https://lintradar.dev/rules/typescript/require-array-sort-compare. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
