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

chore: add prettier plugin to sort imports #238

Merged
merged 7 commits into from
May 8, 2024

Conversation

DNR500
Copy link
Contributor

@DNR500 DNR500 commented Apr 17, 2024

Jira: LF-7839

Applies sorting using prettier - which means that if anyone runs prettier on save will get instant sorting of imports

I have ended up adding the format command to the pre-commit hook script execution so that even if anyone commits without first running prettier imports should be sorted to the correct order - this will impact the speed of the pre-commit validation.

I explored two plugin options on this PR the first one was trying to use @trivago/prettier-plugin-sort-imports. The second was @ianvs/prettier-plugin-sort-imports

@trivago/prettier-plugin-sort-imports matched the alphabetic that matches what VSCode currently does but it also moves around "side effect" - this isn't a good thing and in some circumstances can actually break things.

So I moved to using @ianvs/prettier-plugin-sort-imports instead. This doesn't move the side effect imports and is therefore a little bit safer. Its sorting of named variables tends to case insensitive thought and not match the VSCode way of doing things - I wonder if as we are using prettier and this would be consistent across all IDE's anyway that this would be less important?

Last prettier plugin I tried was prettier-plugin-organize-imports - this one doesn't take into account side effects but I think its the closest to the vscode formatting. Seem to do the minimal changes with some packages remaining unchanged by running the format command.

I've retained the code changes for each plugin as commits on this branch so that changes that each prettier plugin can be looked at and compared in terms of output. Probably good to have a discussion to decide if we are happy to use prettier-plugin-organize-imports.

Copy link
Member

@chybisov chybisov left a comment

Choose a reason for hiding this comment

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

LFG 🚀

@DNR500
Copy link
Contributor Author

DNR500 commented May 8, 2024

Updated the yarn lock file this should be good to merge

@chybisov chybisov merged commit 6a0a244 into main May 8, 2024
1 check passed
@chybisov chybisov deleted the sort-imports-with-prettier branch May 8, 2024 15:46
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.

2 participants