For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt, and this page is available as Markdown at https://rslint.rs/rules/eslint/sort-vars.md.
close

sort-vars

Added in v0.8.2

Configuration

rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'sort-vars': 'error',
    },
  },
]);

Rule Details

This rule requires identifier variables within the same declaration block to be sorted alphabetically. Destructuring declarations are ignored. By default, ordering is case-sensitive.

Examples of incorrect code for this rule:

let b, a;
let c, D, e;

Examples of correct code for this rule:

let a, b, c;
let G, f, h;
let { b, a } = value;

With { "ignoreCase": true }, names are compared without case sensitivity:

{ "sort-vars": ["error", { "ignoreCase": true }] }
let a, A;
let c, D, e;

The rule can automatically reorder declarations when every participating initializer is a literal. It reports without a fix when reordering might change evaluation order.

Original Documentation