sort-vars
Require the variables of one declaration to be sorted
fixable
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#
example.js2 problems
let width, heightVariables within the same declaration block should be sorted alphabetically., depthVariables within the same declaration block should be sorted alphabetically.;example.jsNo problems
let depth, height, width;
let total = 0;
let count = 0;Options#
| Option | Default | What it does |
|---|---|---|
ignoreCase | false | Ignore case when comparing names. |
By default Button sorts before app, so this is reported:
example.js1 problem
let app, ButtonVariables within the same declaration block should be sorted alphabetically., config;With ignoreCase it isn't:
example.jswith
{ "ignoreCase": true }No problemslet app, Button, config;