import/order: "type" group is not enough
Currently, the rule offers the following groups: "builtin", "external", "internal", "unknown", "parent", "sibling", "index", "object", "type"
To me, having single "type" group for all type imports is not enough.
I can import types from "builtin" modules, from "external" module and so on.
So, it would be logical to have type counterpart for each group, i.e.: "build" -> "built-type" "external" -> "external-type" and so on
That's a combinatorial explosion of categories, unfortunately.
I can see some kind of object form of each category that includes types: true - and then, any types not already swept up by another category would be in "type".
I came to mention a similar thing however I think customizing the type imports might be a bit too much.
Type imports are really their own thing, while every other import group is based on the import source, the Type imports are all categorized based on the import type keyword. I feel like sorting types among themselves with the same ordering that is applied to the rest of the categories would probably be an ideal solution to keep things looking consistent, otherwise internal types which use relative imports will usually be placed above external types, even if you have external types listed first.
That's what it does currently, ftr.
It sorts based on the order of the import groups? That's not what I'm seeing.
These are my settings for the rule:
"import/order": [
"warn",
{
"groups": [
"builtin",
"external",
"internal",
"parent",
"sibling",
"object",
"type"
],
"newlines-between": "never",
"alphabetize": {
"order": "asc",
"caseInsensitive": false
}
}
],
And this is how its sorting my types on a run of eslint --fix:
import { Box } from "@chakra-ui/layout";
import React from "react";
import type { Size, SizeProps } from "../types";
import type { SystemStyleObject } from "@chakra-ui/system";
import type { ReactElement } from "react";
import type {
ContainerProps,
GroupBase,
IndicatorsContainerProps,
ValueContainerProps,
} from "react-select";
I would expect the type import from "../types" to go to the bottom:
import { Box } from "@chakra-ui/layout";
import React from "react";
import type { SystemStyleObject } from "@chakra-ui/system";
import type { ReactElement } from "react";
import type {
ContainerProps,
GroupBase,
IndicatorsContainerProps,
ValueContainerProps,
} from "react-select";
import type { Size, SizeProps } from "../types";
That's what it should do, then :-) a PR with failing test cases is appreciated.
It looks like type imports get sorted in reverse order of groups. E.g. I get this:
import type { Paginator } from "../../utils/NMApi";
import type NM from "../../utils/NMTypes";
import type { Actors } from "../TradeWindow.svelte";
import type { Writable } from "svelte/store";
import { onDestroy, createEventDispatcher, getContext } from "svelte";
import { writable } from "svelte/store";
import NMApi from "../../utils/NMApi";
import tip from "../actions/tip";
import Avatar from "../elements/Avatar.svelte";
import Button from "../elements/Button.svelte";
import Icon from "../elements/Icon.svelte";
import FiltersMenu from "./FiltersMenu.svelte";
import PrintDetails from "./PrintDetails.svelte";
with the following rule options
"import/order": [
"error",
{
groups: [
"type",
"builtin",
"external",
"internal",
"parent",
"sibling",
"index",
"object",
],
alphabetize: {
order: "asc",
caseInsensitive: true,
},
warnOnUnassignedImports: false,
},
],
@7nik would you be able to make a PR with a failing test case?
add test cases to https://github.com/import-js/eslint-plugin-import/blob/main/tests/src/rules/order.js ? can try in a few days
Yep, thanks! Much obliged; I can much more easily add a fix onto a failing PR :-)