Rule: ordered-imports

Requires that import statements be alphabetized.

Enforce a consistent ordering for ES6 imports:

  • Named imports must be alphabetized (i.e. “import {A, B, C} from “foo”;”)
    • The exact ordering can be controlled by the named-imports-order option.
    • “longName as name” imports are ordered by “longName”.
  • Import sources must be alphabetized within groups, i.e.: import * as foo from “a”; import * as bar from “b”;
  • Groups of imports are delineated by blank lines. You can use these to group imports however you like, e.g. by first- vs. third-party or thematically.
Notes:
Has Fixer

Config

You may set the "import-sources-order" option to control the ordering of source imports (the "foo" in import {A, B, C} from "foo").

Possible values for "import-sources-order" are:

  • "case-insensitive': Correct order is "Bar", "baz", "Foo". (This is the default.)
  • "lowercase-first": Correct order is "baz", "Bar", "Foo".
  • "lowercase-last": Correct order is "Bar", "Foo", "baz".
  • "any": Allow any order.

You may set the "named-imports-order" option to control the ordering of named imports (the {A, B, C} in import {A, B, C} from "foo").

Possible values for "named-imports-order" are:

  • "case-insensitive': Correct order is {A, b, C}. (This is the default.)
  • "lowercase-first": Correct order is {b, A, C}.
  • "lowercase-last": Correct order is {A, C, b}.
  • "any": Allow any order.
Examples
"ordered-imports": true
"ordered-imports": [
  true,
  {
    "import-sources-order": "lowercase-last",
    "named-imports-order": "lowercase-first"
  }
]
Schema
{
  "type": "object",
  "properties": {
    "import-sources-order": {
      "type": "string",
      "enum": [
        "case-insensitive",
        "lowercase-first",
        "lowercase-last",
        "any"
      ]
    },
    "named-imports-order": {
      "type": "string",
      "enum": [
        "case-insensitive",
        "lowercase-first",
        "lowercase-last",
        "any"
      ]
    }
  },
  "additionalProperties": false
}