-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
import/order
: treat type
imports like regular imports?
#2070
Comments
I think the way you'd do that is add |
That won't work in this case: import type { Dictionary } from 'lodash';
import { isEmpty } from 'lodash';
import { something } from './relative';
import type { TestType } from './relative'; With 2.22.1 the above code will pass, but with 2.23.0 it will fail. |
That has "type A, value A, value B, type B", so I'd expect that to fail regardless of how you configure it - ie, it should be "type A, value A, type B, value B", or "type A, type B, value A, value B", or the reverse of either. |
After 2.23.0 with this example
is throwing an error
Wouldn't it be ok since the alphabetical sorting is right? update: forgot to mention I'm using the rule with the airbnb config, so there's not special treatment of the type group
|
@ljharb v2.22.1 was not enforcing any order for value and type imports, they were treated identically. v2.23 introduced this breaking change which sorts type imports separately from value imports. Currently, the imports are sorted like this: import { isEmpty } from 'lodash';
import { something } from './relative';
import type { TestType } from './relative';
import type { Dictionary } from 'lodash'; ... which is also not right according to your own expectation. Since this is a minor version update, it would have been nice to leave the old behavior unchanged. It is a bit late for that now, but it would still be nice to have to ability to sort type and value imports together - either "type A, value A, value B, type B" or "type A, value A, type B, value B". |
@alumni yes, I agree with that. We'll need to restore that default behavior, and only differentiate type imports via an option. |
For the version where types are mixed within groups, it would be nice if ^ was actually enforced. We have a bunch of
and it would be great to have a more strict ordering if the library is going to start being type-import aware. For reference, @typescript-eslint/consistent-type-imports extracts type imports and places them directly above their corresponding regular imports (though it has no on-going opinion after the initial extraction). |
Ideal for me:
This reverts the old behavior for people with old configs, but allows newer configs to leverage the coolness of a |
2.23 brought a number of breaking changes, including: - import/order `type` sorting: import-js/eslint-plugin-import#2070 - `import/no-extraneous-dependencies`: import-js/eslint-plugin-import#2065
I got the same issue when upgrading from 2.22.1 to 2.23.2, our CI failed https://github.com/kulshekhar/ts-jest/runs/2598048887?check_suite_focus=true |
Thanks @ljharb for restoring the behaviour! Is there going to be a release soon? |
How can we treat type imports like a regular import (i.e. the behavior before v2.23.0)? I would expect the following import order to be fine:
... but the first line gets highlighted:
Also, eslint is now running forever, so I can't automatically fix this.
Rule config:
The text was updated successfully, but these errors were encountered: