-
-
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?
[New] order
: allow controlling intragroup spacing of type-only imports via newlines-between-types
#3127
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3127 +/- ##
==========================================
- Coverage 95.62% 95.10% -0.53%
==========================================
Files 83 83
Lines 3636 3656 +20
Branches 1284 1304 +20
==========================================
Hits 3477 3477
- Misses 159 179 +20 ☔ 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
…oup sorting of type-only imports Closes import-js#2912 Closes import-js#2347 Closes import-js#2441 Subsumes import-js#2615
0f3d9a5
to
4016f3e
Compare
…tTypesGroup" in rule schema
5003898
to
3d3b98b
Compare
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.