Skip to content

Feature: sort imports from the same module by "import type" #593

@IlyaSemenov

Description

@IlyaSemenov

What rule do you want to change?

sort-imports

Describe the problem

With alphabetic imports sorting, I would like to be able to enforce strict order between type- and value- imports from the same module.

Code example

For example, with this setup:

"perfectionist/sort-imports": ["error", {
  groups: [
    ["builtin", "builtin-type"],
    ["external", "external-type"],
    ["internal", "internal-type"],
    ["parent", "parent-type"],
    ["sibling", "sibling-type", "index", "index-type"],
    "unknown",
  ],
  newlinesBetween: "always",
  order: "asc",
  type: "alphabetical",
}],

this is valid code:

import { antfu } from "@antfu/eslint-config"
import type { Awaitable } from "@antfu/eslint-config"
import annotation from "eslint-plugin-annotation"

and this is too:

import type { Awaitable } from "@antfu/eslint-config"
import { antfu } from "@antfu/eslint-config"
import annotation from "eslint-plugin-annotation"

I would like to be able to enforce either of the above (configurable — either put type imports first, or second, or do not sort — by default, as it works now).

Additional comments

No response

Validations

  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions