close

sort-vars

Unreleased

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