-
-
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 controlling intragroup spacing of type-only imports via newlines-between-types
#3127
base: main
Are you sure you want to change the base?
Conversation
…oup sorting of type-only imports Closes import-js#2912 Closes import-js#2347 Closes import-js#2441 Subsumes import-js#2615
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3127 +/- ##
==========================================
- Coverage 95.59% 92.12% -3.47%
==========================================
Files 83 83
Lines 3629 3656 +27
Branches 1282 1304 +22
==========================================
- Hits 3469 3368 -101
- Misses 160 288 +128 ☔ View full report in Codecov by Sentry. |
eba9746
to
8256230
Compare
8256230
to
3d64add
Compare
Like with the other PR, codecov is reporting patch coverage at 100% with no uncovered lines. When I look at "indirect changes" I'm seeing the same |
2f2ea6d
to
0f3d9a5
Compare
|
||
> \[!NOTE] | ||
> | ||
> This setting is only meaningful when [`sortTypesGroup`][7] is enabled. |
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.
should we use the schema to ensure that this option can't be set to true
unless sortTypesGroup
is also set to true?
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.
Sounds like a good idea to me. I was not aware that was a thing for eslint plugins :)
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.
it often requires a bit of gymnastics, but it's usually worth it for the DX.
Depends on #3104
This PR implements in
import/order
: a new option analogous tonewlines-between
but specifically for controlling newlines between type-only imports.A demo package containing this feature is temporarily available for easy testing:
Allow controlling intragroup spacing of type-only imports
This is implemented via
newlines-between-types
. The proposed documentation corresponding to this new feature can be previewed here.Example
Given this code:
And the following settings, the rule check will fail:
With
--fix
yielding:However, with the following settings, the rule check will succeed instead:
{ "groups": ["type", "builtin", "parent", "sibling", "index"], "sortTypesAmongThemselves": true, "newlines-between": "always", + "newlines-between-types": "ignore" }
sortTypesAmongThemselves
allows sorting type-only and normal imports separately. By default,newlines-between
will govern all newlines between import statements like normal.I generally want my type-only imports to be sorted for ease of reference but never have newlines between them (save space) while I want my normal imports (which I tend to visually peruse more often) to be aesthetically pleasing, grouped, and sorted.
newlines-between
is too coarse-grained for this, so this PR introducesnewlines-between-types
, a setting identical tonewlines-between
except it only applies to type-only imports, and only whensortTypesAmongThemselves
is enabled (i.e. it is backward-compatible).When
newlines-between
andnewlines-between-types
conflict,newlines-between-types
takes precedence for type-only imports. For normal imports,newlines-between-types
is ignored entirely.One issue that might warrant further discussion is which setting governs the newline separating type-only imports from normal imports. Right now, I have it so
newlines-between-types
controls this space, but perhaps it should be its own setting.