-
-
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
[New] order
: allow intragroup sorting of type-only imports via sortTypesGroup
#3104
base: main
Are you sure you want to change the base?
[New] order
: allow intragroup sorting of type-only imports via sortTypesGroup
#3104
Conversation
Co-authored-by: 7nik <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3104 +/- ##
==========================================
- Coverage 95.08% 94.81% -0.27%
==========================================
Files 83 83
Lines 3618 3626 +8
Branches 1276 1279 +3
==========================================
- Hits 3440 3438 -2
- Misses 178 188 +10 ☔ View full report in Codecov by Sentry. |
c5a0944
to
2cf2a68
Compare
This is doing a lot, and is a bit of a long diff. It seems like there's 4 separate PRs to be had here:
I definitely would prefer to see 3 of those peeled off into separate PRs, so that each thing can be easily reviewed separately. Thanks! (also, could you please add parens to ensure proper precedence is conveyed when there's a combination of && and ||?) |
order
: enable advanced spacing and sorting of type-only imports
Gotcha, I'll slice it up this weekend.
I thought I ran my modifications through Prettier, but I probably missed a few blocks. I'll take a look |
I think prettier removes those parens, which is one of its many flaws :-) |
For the record, I definitely would like this feature. As evidenced by the fact that I tried to use it per the docs on |
@Xunnamius any progress? i'd love to get this merged for the next release. |
@ljharb Sorry, something I'm working on is, of course, taking longer than I anticipated. I hope to wrap up today or tomorrow. This PR is up next 😊 |
87f4735
to
997b5b2
Compare
…`, `consolidateIslands`) to allow intragroup sorting of type-only imports Closes import-js#2912 Closes import-js#2347 Closes import-js#2441 Subsumes import-js#2615
997b5b2
to
0c179cd
Compare
order
: enable advanced spacing and sorting of type-only importsorder
: enable intragroup sorting of type-only imports
deeca5a
to
10219e2
Compare
10219e2
to
752f00d
Compare
f603878
to
feefba8
Compare
order
: enable intragroup sorting of type-only importsorder
: add options (sortTypesGroup
, newlines-between-types
, consolidateIslands
) to allow intragroup sorting of type-only imports
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR adds 3 options but only seems to be adding 1 to the schema. Should the schema be amended, or should 2 of the options be removed so they can land in different PRs?
feefba8
to
5b0e075
Compare
@ljharb Hmm, no this PR should still only contain the changes relevant to EDIT: I see some complaints from codecov, I'll check 'em out |
If that’s the case then my bad :-) |
order
: add options (sortTypesGroup
, newlines-between-types
, consolidateIslands
) to allow intragroup sorting of type-only importsorder
: add option sortTypesGroup
to allow intragroup sorting of type-only imports
order
: add option sortTypesGroup
to allow intragroup sorting of type-only importsorder
: allow intragroup sorting of type-only imports via sortTypesGroup
Resolves #2615
Resolves #2441
Resolves #2347
Resolves #2172
Related #2912
First, thanks for making eslint-plugin-import! It has saved me a lot of time and headache.
This PR implements in
import/order
: a new option enabling intragroup sorting of type-only imports to match intergroup sorting of normal imports.A demo package containing this feature is temporarily available for easy testing:
Allow intragroup sorting of type-only imports
This is implemented via
sortTypesAmongThemselves
. The proposed documentation corresponding to this new feature can be previewed here.Example
Given this code (which is already correctly ordered):
And the following settings, the rule check will fail:
With
--fix
yielding:This is currently the technically correct behavior, but the wrong outcome in my opinion.
However, with the following settings, the rule check will succeed instead:
{ "groups": ["type", "builtin", "parent", "sibling", "index"], "alphabetize": { "order": "asc" }, + "sortTypesAmongThemselves": true }
Of course, achieving the reverse order (type-only imports after normal imports) is possible by moving
"type"
to the end ofgroups
:{ + "groups": ["builtin", "parent", "sibling", "index", "type"], "alphabetize": { "order": "asc" }, "sortTypesAmongThemselves": true }
It was only after implementing this feature, when I started reviewing the issues literature, that I saw #2441, which lead me to eslint-plugin-perfectionist (neat) and its implementation of "builtin-type," "external-type," etc. I much prefer this PR's implementation, which takes a similar approach to this comment. I don't see how allowing type-only builtin/external/etc imports to be sorted in a different order than non-type builtin/external/etc imports makes things less confusing. And that's before we consider custom
pathGroups
.Instead, the goal of
sortTypesAmongThemselves
is to allow the "type" group to be sorted among itself in a backward-compatible way without the added complexity (and potential inconsistency) of adding regexp or "*-type" groups togroups
. I'm already writing too much configuration. I just want to flick a switch 😅.Additionally, the code that makes
sortTypesAmongThemselves
work could be extended to make something like #2912 work too (perhaps through another option), though that use case is not of interest to me currently.