Skip to content
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

[Feature] Allow manual configuration of line breaks #11

Closed
IanVS opened this issue May 11, 2022 · 1 comment · Fixed by #12
Closed

[Feature] Allow manual configuration of line breaks #11

IanVS opened this issue May 11, 2022 · 1 comment · Fixed by #12

Comments

@IanVS
Copy link
Owner

IanVS commented May 11, 2022

Is your feature request related to a problem?
See trivago/prettier-plugin-sort-imports#36

Describe the solution you'd like
I think the solution in trivago/prettier-plugin-sort-imports#42 is pretty smart. It does not require a new option, but gives some flexibility for folks who want to specify new lines between specific groups.

Describe alternatives you've considered
We could wait until the upstream project merges this, but it seems a little unlikely at this point.

@blutorange, what do you think of this approach?

@IanVS IanVS assigned IanVS and unassigned IanVS May 11, 2022
@blutorange
Copy link
Collaborator

So if I understand this correctly, importOrderSeparation: true already allows import groups to be separated, but this suggestion allows people to separate some, but not all import groups? Tbh I personally don't understand why people want so much control over how imports are sorted, but this solution does look like a good extension of an existing mechanism.

@IanVS IanVS closed this as completed in #12 May 17, 2022
IanVS added a commit that referenced this issue May 17, 2022
Closes #11

This is an adaptation of trivago/prettier-plugin-sort-imports#42 from @atombrenner.  I wasn't able to use most of the commits from the original branch, because our approach is different in this project, but I did pull in his commit with tests.  

The other change I needed to make here was to modify the cloned nodes in `adjustCommentsOnSortedNodes`, rather than mutating the original, which was leading to some strange bugs in the tests.  

* Add test for "local" groups, include newlines in tests

`getSortedNodesByImportOrder` includes a check for `importOrderSeparation`,
and adds newlines when it's true, so we should include that in our tests.

* Add support for custom import group separators

* add tests

* Update snapshots

But the last snapshot is wrong, will fix in next commit

* Copy nodes when adjusting comments

Mutating the original nodes causes strange effects, as seen in the snapshot

* Avoid duplicate newlines

* minor: Remove unused variables

* Update README

Co-authored-by: Christian Rodemeyer <christian.rodemeyer@sz.de>
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 a pull request may close this issue.

2 participants