qwik icon indicating copy to clipboard operation
qwik copied to clipboard

style: enforce consistent import order

Open DustinJSilk opened this issue 2 years ago • 4 comments

What is it?

  • [X] Feature / enhancement
  • [ ] Bug
  • [ ] Docs / tests

Description

Add a prettier plugin to enforce consistent sort orders.

Use cases and why

    1. Less lines will change with each commit
    1. 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

DustinJSilk avatar Jan 12 '23 13:01 DustinJSilk

Review PR in StackBlitz Codeflow 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

DustinJSilk avatar Jan 12 '23 13:01 DustinJSilk

not against it, but scares me a bit haha

manucorporat avatar Jan 12 '23 14:01 manucorporat

Haha fair enough.

If it helps, the plugin just calls organizeImports from the TypeScript API.

@manucorporat

DustinJSilk avatar Jan 12 '23 16:01 DustinJSilk

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.

zanettin avatar Feb 16 '23 20:02 zanettin

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.

DustinJSilk avatar Feb 16 '23 20:02 DustinJSilk

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 👍 🙏

zanettin avatar Feb 16 '23 21:02 zanettin

Deploy Preview for qwik-insights failed.

Name Link
Latest commit d1e10dee062e806e10648e876b95d838a5eade5e
Latest deploy log https://app.netlify.com/sites/qwik-insights/deploys/649f2a87bd58830008254d57

netlify[bot] avatar Jun 30 '23 17:06 netlify[bot]

@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.

gioboa avatar Oct 10 '23 20:10 gioboa