Skip to content

Change how type import/export specifiers are sorted #125

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 27, 2023
Merged

Change how type import/export specifiers are sorted #125

merged 4 commits into from
Jan 27, 2023

Conversation

lydell
Copy link
Owner

@lydell lydell commented Jan 27, 2023

Closes #124.

Before – type specifiers come first:

import { type B, a } from "a";
export { type B, a } from "a";

After – all specifiers are sorted alphabetically, regardless of type:

import { a, type B } from "a";
export { a, type B } from "a";

Motivation:

You might import a class for a type annotation using:

import {
  type MyClass,
  coolFunction,
} from "example";

Later, you also start instantiating that class in the same file (new MyClass()), so you remove type.

Previously, this resulted in a messy diff due to the class moving:

 import {
-  type MyClass,
   coolFunction,
+  MyClass,
 } from "example";

Now it results in just the type keyword being removed:

 import {
-   type MyClass,
+   MyClass,
   coolFunction,
 } from "example";

This is consistent with https://github.com/lydell/eslint-plugin-simple-import-sort#why-sort-on-from

@lydell lydell changed the title Change how type imports are sorted Change how type import/export specifies are sorted Jan 27, 2023
@lydell lydell changed the title Change how type import/export specifies are sorted Change how type import/export specifiers are sorted Jan 27, 2023
@lydell lydell merged commit 3ef8f5a into main Jan 27, 2023
@lydell lydell deleted the type branch January 27, 2023 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sorting of "type FooX" and "Foo" imports disagrees with typescript, dprint
1 participant