# sort-vars

Rule `eslint/sort-vars`. Require variables within the same declaration block to be sorted

- Source: eslint
- Technologies: JavaScript
- Kind: suspicious
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 2.1M weekly downloads of presets that enable it
- Trend: +151.7% last quarter
- Rank: #1515 by reach, #19 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sort-vars` | no | safe | package `eslint` | [docs](https://eslint.org/docs/latest/rules/sort-vars) |
| Oxlint | `sort-vars` | no | safe | plugin `eslint`, category pedantic | [docs](https://oxc.rs/docs/guide/usage/linter/rules/eslint/sort-vars.html) |

## Code examples

### Incorrect: the rule reports this

```js
let b, a;

let c, D, e;

let f, F;
```

```js
let c, d, a, b;
```

```js
let c, d, a, e;
```

### Correct: the rule accepts this

```js
let a, b, c, d;

let _a = 10;
let _b = 20;

let E, e;

let G, f, h;
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sort-vars": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "sort-vars": "error"
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |

## Related rules

- [eslint/no-inline-comments](https://lintradar.dev/rules/eslint/no-inline-comments.md): Disallow inline comments after code
- [eslint/no-duplicate-imports](https://lintradar.dev/rules/eslint/no-duplicate-imports.md): Disallow duplicate module imports
- [eslint/id-match](https://lintradar.dev/rules/eslint/id-match.md): Require identifiers to match a specified regular expression
- [eslint/id-denylist](https://lintradar.dev/rules/eslint/id-denylist.md): Disallow specified identifiers
- [eslint/func-style](https://lintradar.dev/rules/eslint/func-style.md): Enforce the consistent use of either `function` declarations or expressions assigned to variables
- [eslint/require-await](https://lintradar.dev/rules/eslint/require-await.md): Disallow async functions which have no `await` expression

---

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