Skip to content

eslint/sort-imports Style ​

🛠️ An auto-fix is available for this rule for some violations.

What it does ​

This rule checks all import declarations and verifies that all imports are first sorted by the used member syntax and then alphabetically by the first member or alias name.

When declaring multiple imports, a sorted list of import declarations make it easier for developers to read the code and find necessary imports later.

Why is this bad? ​

Examples ​

Examples of incorrect code for this rule:

javascript
import { a, b, c } from "foo.js";

import e from "bar.js";
import d from "foo.js";

Configuration ​

This rule accepts a configuration object with the following properties:

allowSeparatedGroups ​

type: boolean

default: false

When true, the rule allows import groups separated by blank lines to be treated independently.

ignoreCase ​

type: boolean

default: false

When true, the rule ignores case-sensitivity when sorting import names.

ignoreDeclarationSort ​

type: boolean

default: false

When true, the rule ignores the sorting of import declarations (the order of import statements).

ignoreMemberSort ​

type: boolean

default: false

When true, the rule ignores the sorting of import members within a single import declaration.

memberSyntaxSortOrder ​

type: array

Specifies the sort order of different import syntaxes.

memberSyntaxSortOrder[n] ​

type: "none" | "all" | "multiple" | "single"

How to use ​

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny sort-imports
json
{
  "rules": {
    "sort-imports": "error"
  }
}

References ​

Released under the MIT License.