Skip to content
NewBun 1.4.5 is out. Release notes
AphrodyBun

Linter · Rules

sort-vars

Require the variables of one declaration to be sorted

When one let, const or var declares several variables, alphabetical order makes a name quick to find in the list.

Only names in the same declaration are compared. Destructuring patterns are skipped. Capital letters sort before lowercase letters unless you set ignoreCase.

--fix sorts the names if every initializer is a literal such as 0 or "px". Other initializers can depend on the order they run in, so the declaration is left as is.

Configure

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"sort-vars" = "error" # or "warn"

Every option, set to its default:

bunfig.toml
[lint.rules]
"sort-vars" = ["error", {
  ignoreCase = false,
}]

Examples

Reported:

let width, height, depth;

Not reported:

let depth, height, width;

let total = 0;
let count = 0;

Options

OptionDefaultWhat it does
ignoreCasefalseIgnore case when comparing names.

By default Button sorts before app, so this is reported:

let app, Button, config;

With ignoreCase it isn't:

let app, Button, config;