Skip to content

Always separate out <TYPES> into separate line, but keep adjacent to identical value imports #248

@vincerubinetti

Description

@vincerubinetti

Preamble:

First off, thanks for this plugin. It's saved me so much sanity, and I've found you to be very open-minded maintainers (which sadly many are not), especially for a plugin striving to be opinionated. I remember you being flexible with the CSS at bottom/top discussion despite its possible footguns with sideeffects, and I've gotten lots of use out of the feature.

Finally following up on this and creating an issue to gauge how many other users also want this.

I do want this, but even I am not sure it can/should be implemented.

I got tired of AI-auto-imports mixing and matching type-import styles, found that @typescript-eslint/consistent-type-imports considers it a wont-fix and just recommends import/consistent-type-specifier-style, looked towards this package, and discovered I had already tread this exact path a few years ago 😅 I could install the eslint import package, but it's heavy for just one rule, plus the config of this package is way more flexible and easy.


Related:

#147 (comment)
#185 (comment)
#107

The goal would be to turn something like this:

import { valueA, type TypeA, type TypeB } from "package-a";
import { valueB, type TypeC, type TypeD } from "package-b";

into this:

import { valueA } from "package-a";
import type { TypeA, TypeB } from "package-a";
import { valueB } from "package-b";
import type { TypeC, TypeD } from "package-b";

without having to manually specify something like this (which is what makes this tricky):

[
  "package-a",
  "<TYPES>package-a",
  "package-b"
  "<TYPES>package-b",
]

In more detail, here's my importOrder, which tries to order things into my own categories of high-level to low-level, loosely: framework/platform-level 3rd party → other 3rd-party → my functions → local imports

[
  "^react",
  "^@[a-zA-Z]",
  "^[a-zA-Z]",
  "^@/",
  "^/",
  "^./",
  "^../"
]

If I duplicate each of these with a <TYPES> version, that does what it's designed to do, but it doesn't for example keep the type imports within one of those categories adjacent to each other.

That is, you get:

import Analysis from "@/api";
import Badge from "@/components/Badge";
import type { AnalysisType } from "@/api";
import type { BadgeType } from "@/components/Badge";

instead of:

import Analysis from "@/api";
import type { AnalysisType } from "@/api";
import Badge from "@/components/Badge";
import type { BadgeType } from "@/components/Badge";

To be honest, I can't think of how this could be elegantly integrated into the current API. But maybe someone else can.

For now, I've taken to just doing this:

[
  "<TYPES>^react",
  "<TYPES>^@[a-zA-Z]",
  "<TYPES>^[a-zA-Z]",
  "<TYPES>^@/",
  "<TYPES>^/",
  "<TYPES>^./",
  "<TYPES>^../",
  "^react",
  "^@[a-zA-Z]",
  "^[a-zA-Z]",
  "^@/",
  "^/",
  "^./",
  "^../"
]

Not ideal, but I view it as better than mixing and matching type and value imports on the same line, or worse yet inconsistently doing mixed/separated styles.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions