Add ESLint rule to sort type imports #3090
mikeybinns
started this conversation in
Proposals
Replies: 1 comment 1 reply
-
You could use {
// ...other config
"rules": {
"import/order": [
"error",
{
"alphabetize": {
"order": "asc"
},
"groups": ["type", "builtin", "external", "internal", "parent", ["sibling", "index"]],
"newlines-between": "always",
"pathGroups": [],
"pathGroupsExcludedImportTypes": []
}
]
},
} The above will lint and format your documents like so: import type { LoaderFunction } from "@remix-run/node"
import fs from "fs"
import path from "path"
import { useState } from "react"
import { AnyComponent } from "@package-from-monorepo/ui"
import { OtherComponent } from "../parent-module"
import { ExtraComponent } from "./sibling-module" |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The current ESLint rules require separate type imports, but it just puts them in the middle of all the imports.
I think it makes sense to group type imports together, and move them to the top.
Example:
This:
would become:
instead of this:
I can't see any existing rule for this, so one will need to be created.Edit: This rule DOES exist (thanks @elkevinwolf), see below.This could also be combined with ESLint
sort-imports
to alphabetise the order of imports, and then move types, so you end up with alphabetised type imports and alphabetised normal imports.Beta Was this translation helpful? Give feedback.
All reactions