-
Notifications
You must be signed in to change notification settings - Fork 135
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
Control the separation of import groups as mentioned in #36 #42
base: main
Are you sure you want to change the base?
Control the separation of import groups as mentioned in #36 #42
Conversation
Hi @ayusharma, any feedback highly appreciated. Is there any chance that this PR gets accepted or should I use a fork? |
Hi @atombrenner, I really appreciate your efforts here. Sorry, We do not agree with this approach, This plugin's idea is to keep the separation between only third and local imports. Please proceed with your fork. I do not think this implementation fulfil the general idea. |
I'll re-open this PR due to the fact that it can help a lot of people and solve lot's of issues. |
This PR gives more flexibility and does not break previous behaviours. (unless you put empty lines) |
Any chance we can get this merged soon 🙏 |
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 <[email protected]>
For those who need this, it has been released in a fork, https://github.com/IanVS/prettier-plugin-sort-imports/releases/tag/v3.4.0. |
You can use regex for grouping specific libraries like => |
It's clear there's a fair amount of support for this one, any ideas on ETA? |
Add the possibility to control the separation of import groups as mentioned in #36
Motivation: You want to move "React imports" always to the top and only add a separator between node_modules imports and local imports.
should be formatted as
You can do this by specifying empty strings in
importOrder
in .prettierrc: