# 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.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

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

Every option, set to its default:

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

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
let width, height, depth;
```

Not reported:

{/* good */}
```js
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:

{/* bad */}
```js
let app, Button, config;
```

With `ignoreCase` it isn't:

{/* good {"options": [{"ignoreCase": true}]} */}
```js
let app, Button, config;
```
