Skip to content

chore: use named import for util #7669

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

Merged
merged 7 commits into from
Oct 11, 2023

Conversation

antfu
Copy link
Contributor

@antfu antfu commented Sep 18, 2023

PR Checklist

(sorry for sending this PR without an issue, as I consider it a straightforward refactor)

Overview

Currently, we are mixing the usage for * as util and named import in different rules (and even both in the same file).

I think named import is a generally better syntax as it enables tree-shaking, improves overall consistency, and would help https://github.com/eslint-stylistic/eslint-stylistic to migrate away those formatting rules (we want tree-shaking to avoid bundling all utils again).

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @antfu!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

@netlify
Copy link

netlify bot commented Sep 18, 2023

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 05b5cab
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/65265ff2969e2c000765c7c0
😎 Deploy Preview https://deploy-preview-7669--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 96 (no change from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

@antfu antfu changed the title refactor: use named export for util chore(refactor): use named export for util Sep 18, 2023
@antfu antfu changed the title chore(refactor): use named export for util chore: use named export for util Sep 18, 2023
@antfu antfu changed the title chore: use named export for util chore: use named import for util Sep 18, 2023
@antfu antfu force-pushed the refactor/util-export branch from 3fd5bdd to 41d8b51 Compare September 18, 2023 10:33
@antfu
Copy link
Contributor Author

antfu commented Sep 18, 2023

The failing tests seem to be inherited from the main bench.

@JoshuaKGoldberg
Copy link
Member

as it enables tree-shaking

We never use dynamic lookups, so shouldn't bundlers be able to tree shake them? This feels like an issue with bundlers not supporting a very reasonable style IMO.

@antfu
Copy link
Contributor Author

antfu commented Sep 18, 2023

Well, to my surprise, rollup does tree-shake well (but I guess you need to be careful not reference the object entirely, it's not a concern with the current codebase).

Then, I think the issue would fall into mainly consistency/preferences. In that case, I don't have strong opinions over which.

@Josh-Cena
Copy link
Member

I prefer named imports. The name util by itself doesn't add much info.

@JoshuaKGoldberg
Copy link
Member

@typescript-eslint/triage-team I'm up for merging this as-is (so, moving to named imports), for consistency's sake and because tree shaking can be complex sometimes even when everything is configured well. Any objections?

Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Approving knowing that we might have to clean some stuff up after merging from main.

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label Oct 10, 2023
JamesHenry
JamesHenry previously approved these changes Oct 10, 2023
@JamesHenry
Copy link
Member

Thanks @antfu!

Josh-Cena
Josh-Cena previously approved these changes Oct 10, 2023
type,
ts.TypeFlags.Undefined,
);
const typeIncludesNull = util.isTypeFlagSet(
const typeIncludesNull = tsutils.isTypeFlagSet(
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg Oct 10, 2023

Choose a reason for hiding this comment

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

Aha! A behavior change. Might be from a merge. I'll fix.

Confusingly, the two isTypeFlagSet functions aren't the same.

@JoshuaKGoldberg JoshuaKGoldberg dismissed stale reviews from Josh-Cena, JamesHenry, and themself via d683758 October 10, 2023 21:04
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

I got through one util.isTypeFlagSet -> tsutils.isTypeFlagSet swap, but it looks like there are still a few more. Requesting changes on fixing that up please. Once yarn lint passes I think we'll be good to go!

@JoshuaKGoldberg JoshuaKGoldberg added awaiting response Issues waiting for a reply from the OP or another party and removed 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labels Oct 10, 2023
@antfu
Copy link
Contributor Author

antfu commented Oct 11, 2023

Should be good now :)

@JoshuaKGoldberg JoshuaKGoldberg merged commit afee34c into typescript-eslint:main Oct 11, 2023
@JoshuaKGoldberg JoshuaKGoldberg removed the awaiting response Issues waiting for a reply from the OP or another party label Oct 11, 2023
@JoshuaKGoldberg
Copy link
Member

Thanks!

@antfu antfu deleted the refactor/util-export branch October 11, 2023 11:35
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants