style: enforce consistent import order
What is it?
- [X] Feature / enhancement
- [ ] Bug
- [ ] Docs / tests
Description
Add a prettier plugin to enforce consistent sort orders.
Use cases and why
-
- Less lines will change with each commit
-
- Avoid big changes when contributors have unexpected editor settings (like me)
Checklist:
- [x] My code follows the developer guidelines of this project
- [x] I have performed a self-review of my own code
- [ ] I have made corresponding changes to the documentation
- [ ] Added new tests to cover the fix / functionality
Run & review this pull request in StackBlitz Codeflow.
@manucorporat if this is something you'd like in, it would be a good idea to keep it up to date with the main branch before merging so that any new commits are also formatted
not against it, but scares me a bit haha
Haha fair enough.
If it helps, the plugin just calls organizeImports from the TypeScript API.
@manucorporat
I like this very much @DustinJSilk 🙏 makes things def. easier to find.
i just had a look at the performance of pnpm prettier.fix:
| # | current | with sort order fix | change |
|---|---|---|---|
| 1 | 14.5s |
23.2s |
+62% |
| 2 | 14.8s |
22.1s |
+67% |
| 3 | 14.7s |
22s |
+66% |
i thought there is smth similar for eslint (https://www.npmjs.com/package/eslint-plugin-simple-import-sort or https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/order.md) which may perform better?
@manucorporat would you like to have smth in this direction? my point is, that it make files more aligned and easier to find things in import heave files. that's why we use it internally on our repos.
The reason I chose this library was because it uses the official typescript sorting method rather than a custom implementation. I’d be fine to use something else with better performance if that’s a concern, though I’ve never felt the need to optimise prettier.
An alternative approach is to only sort imports on staged files with husky where performance is negligible, and ignore the import order during the GitHub workflow checks if that’s where the performance concern is.
The reason I chose this library was because it uses the official typescript sorting method rather than a custom implementation.
Totally see your point. Just wanted to talk about this quickly 👍
I’ve never felt the need to optimize prettier.
always depends on the code base size 🤣
An alternative approach is to only sort imports on staged files with husky where performance is negligible, and ignore the import order during the GitHub workflow checks if that’s where the performance concern is.
Sounds both good to me 👍 🙏
Deploy Preview for qwik-insights failed.
| Name | Link |
|---|---|
| Latest commit | d1e10dee062e806e10648e876b95d838a5eade5e |
| Latest deploy log | https://app.netlify.com/sites/qwik-insights/deploys/649f2a87bd58830008254d57 |
@DustinJSilk This PR has a ton of conflicts because it's very old. So I think the best thing to do is reopen a new fresh PR with this feature. I close this one. Thanks @DustinJSilk for your help.