Skip to content

Change how type import/export specifiers are sorted#125

Merged
lydell merged 4 commits intomainfrom
type
Jan 27, 2023
Merged

Change how type import/export specifiers are sorted#125
lydell merged 4 commits intomainfrom
type

Conversation

@lydell
Copy link
Copy Markdown
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