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

fix(eslint-plugin): [prefer-literal-enum-member] allow using member it self on allowBitwiseExpressions #9114

Merged
merged 2 commits into from
May 28, 2024

Conversation

yeonjuan
Copy link
Contributor

PR Checklist

Overview

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @yeonjuan!

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.

Copy link

netlify bot commented May 18, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 3e6eb13
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/6650670fbad47500084d3bfd
😎 Deploy Preview https://deploy-preview-9114--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: 97 (🟢 up 5 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.

@yeonjuan yeonjuan marked this pull request as ready for review May 18, 2024 06:06
@yeonjuan
Copy link
Contributor Author

@Josh-Cena
Copy link
Member

Have you seen this pattern in the wild?

We allow bitwise because they are "literals in effect": people read 1 << 3 as naturally as 0b1000 or 8, but the nested bitwise you have there seems like any other computation in terms of complexity.

@yeonjuan
Copy link
Contributor Author

yeonjuan commented May 18, 2024

Hi, @Josh-Cena, When dealing with color values, it's sometimes useful to nest bitwise. But I can't think of any practical examples on the initial values of an enum. Maybe it's because I haven't used bitwise much.

const redValue = hexColor >> 16 & 0xff

Personally, I think that allowing only one bitwise operator is a bit under-supported. But I also think it's a good idea to handle it when real use cases are reported.

@yeonjuan
Copy link
Contributor Author

yeonjuan commented May 18, 2024

@Josh-Cena oh, In the typescript repo, I found an use case of multiple bit operators in an enum initializer.

https://github.com/microsoft/TypeScript/blob/79a851426c514a12a75b342e8dd2460ee6615f73/src/harness/vpathUtil.ts#L36-L63

const enum ValidationFlags {
    None = 0,

    RequireRoot = 1 << 0,
    RequireDirname = 1 << 1,
    RequireBasename = 1 << 2,
    RequireExtname = 1 << 3,
    RequireTrailingSeparator = 1 << 4,

    AllowRoot = 1 << 5,
    AllowDirname = 1 << 6,
    AllowBasename = 1 << 7,
    AllowExtname = 1 << 8,
    AllowTrailingSeparator = 1 << 9,
    AllowNavigation = 1 << 10,
    AllowWildcard = 1 << 11,

    /** Path must be a valid directory root */
    Root = RequireRoot | AllowRoot | AllowTrailingSeparator,

    /** Path must be a absolute */
    Absolute = RequireRoot | AllowRoot | AllowDirname | AllowBasename | AllowExtname | AllowTrailingSeparator | AllowNavigation,

    /** Path may be relative or absolute */
    RelativeOrAbsolute = AllowRoot | AllowDirname | AllowBasename | AllowExtname | AllowTrailingSeparator | AllowNavigation,

    /** Path may only be a filename */
    Basename = RequireBasename | AllowExtname,
}

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.

LGTM, thanks! 🚀

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval One team member has approved this PR; a second should be enough to merge it label May 24, 2024
@bradzacher bradzacher added the bug Something isn't working label May 28, 2024
@bradzacher bradzacher merged commit 880cf78 into typescript-eslint:main May 28, 2024
59 of 60 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 10, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 approval One team member has approved this PR; a second should be enough to merge it bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: [prefer-literal-enum-member] allowBitwiseExpressions with self-referential enums does not disable error
4 participants