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

Move import sorting over to prettier #50618

Merged
merged 3 commits into from
Jan 2, 2025
Merged

Conversation

ryanclark
Copy link
Contributor

This removes eslint-plugin-import and moves import sorting over to prettier instead.

Copy link
Contributor

@kiosion kiosion left a comment

Choose a reason for hiding this comment

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

lgtm!

@public-teleport-github-review-bot public-teleport-github-review-bot bot removed the request for review from kimlisa December 30, 2024 18:05
@ryanclark ryanclark added no-changelog Indicates that a PR does not require a changelog entry backport/branch/v15 backport/branch/v16 backport/branch/v17 labels Dec 31, 2024
@ryanclark ryanclark force-pushed the ryan/prettier-imports branch from b70ca08 to d1f62e2 Compare December 31, 2024 09:57
Copy link
Member

@ravicious ravicious left a comment

Choose a reason for hiding this comment

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

The Prettier plugin makes more opinionated choices than the ESLint plugin which ultimately makes the configuration much simpler (it has mostly to do with how types are sorted).

Copy link
Member

@ravicious ravicious Dec 31, 2024

Choose a reason for hiding this comment

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

I added a commit with a bunch of proposed changes, let me know what you think.

  • A clear split of our own packages between app packages and "library" packages. Taken from tsconfig.json to minimize the amount of places that need to be updated when something changes. gen-proto-ts is treated as a library package. @gravitational/* imports are grouped together with those without that prefix.
  • Node builtins go at the top. No strong opinion on this, it's just something we've been following in teleterm where we have the biggest amount of Node code. I guess it makes it easier to see that the code in the file is Node-only?

Copy link
Member

Choose a reason for hiding this comment

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

On my machine, adding the sort plugin makes pnpm prettier-check go from ~17-20s to ~27s. The ESLint plugin made pnpm eslint slower by ~0-3s. I guess it's not necessarily an issue in the grand scheme of things, I just wanted us to be aware of this.

Copy link
Member

Choose a reason for hiding this comment

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

I also see in the readme of this plugin that it "combines type and value imports (if importOrderTypeScriptVersion is set to "4.5.0" or higher)". @kiosion I think you had some opinions on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, yeah. Not sure if it's still the case, would need to look into it again, but I remember there being some issues in the past regarding combined type/code imports and proper tree-shaking of unused imports... aside from that it's a stylistic preference (I find having all type-related imports grouped together is much more readable).

Copy link
Member

@ravicious ravicious Jan 2, 2025

Choose a reason for hiding this comment

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

FWIW, it should be possible to separate type imports from regular imports with this plugin, but we'd need to add a regex for each import group to avoid grouping all type imports. Grouping regular imports but not grouping type imports feels a bit off to me.

<TYPES> - Not active by default, this allows you to group all type-imports, or target them with a regex (<TYPES>^[.] targets imports of types from local files).

But the way the plugin does it right now is fine for me.

@zmb3
Copy link
Collaborator

zmb3 commented Dec 31, 2024

LGTM, let's resolve the conflicts and get it merged.

Do we plan to backport this to avoid merge conflicts with backports?

@ryanclark ryanclark force-pushed the ryan/prettier-imports branch from d8c9f55 to 50f8c68 Compare January 2, 2025 13:27
@ryanclark ryanclark enabled auto-merge January 2, 2025 13:31
@ryanclark
Copy link
Contributor Author

LGTM, let's resolve the conflicts and get it merged.

Do we plan to backport this to avoid merge conflicts with backports?

Yeah

@ryanclark ryanclark added this pull request to the merge queue Jan 2, 2025
Merged via the queue into master with commit d6fa030 Jan 2, 2025
43 checks passed
@ryanclark ryanclark deleted the ryan/prettier-imports branch January 2, 2025 13:50
@public-teleport-github-review-bot

@ryanclark See the table below for backport results.

Branch Result
branch/v15 Failed
branch/v16 Failed
branch/v17 Failed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants