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

Add @ianvs/prettier-plugin-sort-imports #3029

Closed
wants to merge 5 commits into from

Conversation

jasikpark
Copy link
Contributor

Changes

  • Adds @ianvs/prettier-plugin-sort-imports
  • Formats the code w/ it + it will be formatted in ci via pnpm run format
  • This plugin respects side effect imports unlike organize-imports-cli & I've had success w/ it. It's a fork of a trivago version that did not respect side effect imports.

continuing #3013

cc @FredKSchott @IanVS

Testing

Docs

@changeset-bot
Copy link

changeset-bot bot commented Apr 7, 2022

⚠️ No Changeset found

Latest commit: 0a41422

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pkg: create-astro Related to the `create-astro` package (scope) pkg: example Related to an example package (scope) pkg: lit Related to Lit (scope) pkg: preact Related to Preact (scope) pkg: react Related to React (scope) pkg: vue Related to Vue (scope) feat: markdown Related to Markdown (scope) pkg: integration Related to any renderer integration (scope) test labels Apr 7, 2022
@jasikpark
Copy link
Contributor Author

The cool thing is that it works w/ prettier-plugin-astro as well -- since the frontmatter uses the typescript parser 👀

@github-actions github-actions bot removed pkg: preact Related to Preact (scope) pkg: vue Related to Vue (scope) labels Apr 7, 2022
@jasikpark jasikpark requested a review from matthewp April 7, 2022 21:12
@natemoo-re
Copy link
Member

Nice! Can we also add 0a41422 to .git-blame-ignore-revs?

@jasikpark
Copy link
Contributor Author

Sure! I was planning on doing that in a different PR, since I assume this will be squash merged & that git revision will no longer be accurate?

@jasikpark
Copy link
Contributor Author

What do you think is the best course @natemoo-re

a. Merge this PR sans git revision hash and create a second PR that is based on the squash commit of this PR
b. Rebase this branch so that it's pretty and can be merged via a regular merge as 3 different commits

@FredKSchott
Copy link
Member

So what I mainly wanted to get out of #3013 was auto-removing unused imports, including TS types. Does this do that? Can you test to confirm? I can't tell based on the diff, since it adds more lines than it removes.

I actually care about sort order much less than that. fwiw, if you read my comment in #3013, the side-effect imports issue will solve itself in the next TypeScript patch, where you can just place it above the others in its own group, which VSCode will respect.

As long as this PR can auto-remove unused TS type imports AND unused named exports, then I'm pretty happy either way. Conceptually I like the idea of relying on TypeScript directly vs. a fork of an ESLint plugin, but I also wasn't super impressed with that TS CLI, so... 🤷

@IanVS
Copy link
Contributor

IanVS commented Apr 8, 2022

No, the prettier plugin does not remove imports or exports, and I wouldn't want to add that functionality to it either, as it is out-of-scope for its purpose and personally I would not want that behavior. Since it sounds like that's what you're looking for, I'd recommend closing this PR and waiting for the typescript tool.

@jasikpark
Copy link
Contributor Author

So this isn't an eslint plugin, it's a prettier plugin, so it runs with every pnpm run format; It doesn't do auto import removal, though from what I understand about typescript that can be a bit iffy.

I'd use organize-imports-cli if auto-removing imports is your primary aim rather than sorting imports.

@jasikpark
Copy link
Contributor Author

I was working off your title 😅

@FredKSchott
Copy link
Member

So this isn't an eslint plugin, it's a prettier plugin, so it runs with every pnpm run format

my mistake! I misstyped

It doesn't do auto import removal, though from what I understand about typescript that can be a bit iffy.

It's always worked for me over 4+ years (through VSCode), but if you can point to anything that would be good reason to hold off I'd love to see it.

But yea, removing unused imports and consistently formatting the remaining imports are the two things that I wanted to tackle. If everyone is good for waiting a few more days, then that original PR should be good to reopen to tackle both (and I can reword it to be more clear).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: markdown Related to Markdown (scope) pkg: astro Related to the core `astro` package (scope) pkg: create-astro Related to the `create-astro` package (scope) pkg: example Related to an example package (scope) pkg: integration Related to any renderer integration (scope) pkg: lit Related to Lit (scope) pkg: react Related to React (scope)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants