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

Switch to eslint-based import sorting #188

Merged
merged 2 commits into from
Nov 7, 2023
Merged

Switch to eslint-based import sorting #188

merged 2 commits into from
Nov 7, 2023

Conversation

ejizba
Copy link
Contributor

@ejizba ejizba commented Nov 6, 2023

Related to this discussion, I wanted to switch off of VS Code's organize imports feature and onto an eslint-based one. I split this PR into two commits for easier review: one to configure eslint and one to auto-fix the repo based on the new config.

Background (feel free to ignore if not interested)

I believe VS Code is using a built-in feature of TypeScript's language service that sorts imports (not an eslint rule). I can't find the feature documented by TypeScript, but it was announced here.

Turns out there are a ton of ways to do this 😅. These are the options I considered:

  1. eslint's built-in sort-imports rule: very basic features with no auto-fix
  2. prettier-plugin-organize-imports: uses the TypeScript language service and explicitly mentions it should be the same as VS Code's feature. Not a super popular package, though
  3. eslint-plugin-import: Lots of different rules and options, some of which support auto-fix
  4. eslint-plugin-simple-import-sort: A more opinionated package that prioritizes auto-fix

I liked option 4 the best. "auto-fix" is a priority for me on this and they knocked it out of the park. I followed their example config and made one tweak to remove whitespace between groups.

@ejizba ejizba requested a review from castrodd November 6, 2023 23:32
Copy link
Member

@castrodd castrodd left a comment

Choose a reason for hiding this comment

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

Looks great!

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