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

Custom import order separation #12

Merged
merged 8 commits into from
May 17, 2022
Merged

Conversation

IanVS
Copy link
Owner

@IanVS IanVS commented May 12, 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.

@IanVS IanVS requested a review from blutorange May 12, 2022 15:57
Base automatically changed from sort-builtins-to-top to main May 12, 2022 16:09
@IanVS IanVS force-pushed the custom-import-order-separation branch from fc4db3c to 2fe5b78 Compare May 12, 2022 16:13
Copy link
Collaborator

@fbartho fbartho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your example test cases look great, and your documentation changes look like a good fit.

I see that the tests are executed in CI, so I don't have any objections to this PR :)

*/
export const adjustCommentsOnSortedNodes = (
nodes: ImportDeclaration[],
finalNodes: ImportOrLine[],
) => {
// maintain a copy of the nodes to extract comments from
// We will mutate a copy of the finalNodes, and extract comments from the original
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great clarification

@IanVS
Copy link
Owner Author

IanVS commented May 17, 2022

@blutorange I'm going to merge this, but let me know if you want any changes and I can make them in a follow-up.

IanVS and others added 8 commits May 16, 2022 20:06
`getSortedNodesByImportOrder` includes a check for `importOrderSeparation`,
and adds newlines when it's true, so we should include that in our tests.
# Conflicts:
#	.prettierrc
#	src/utils/get-sorted-nodes.ts
But the last snapshot is wrong, will fix in next commit
Mutating the original nodes causes strange effects, as seen in the snapshot
@IanVS IanVS force-pushed the custom-import-order-separation branch from 2fe5b78 to b601cd8 Compare May 17, 2022 00:09
@IanVS IanVS merged commit b9dac83 into main May 17, 2022
@IanVS IanVS deleted the custom-import-order-separation branch May 17, 2022 00:14
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 this pull request may close these issues.

[Feature] Allow manual configuration of line breaks
2 participants