Skip to content

Enhancement: [prefer-literal-enum-member] Allow nested bitwise when using the allowBitwiseExpressions option #9166

@yeonjuan

Description

@yeonjuan

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/play/#ts=5.2.2&showAST=es&fileType=.tsx&code=MYewdgzgLgBApmArgWxgNQIYBsCWATDKHcAMSwwHMIYBvAKBhgDlw4YBeGABgBo6GYAJTgBHRDgBOcQSBCxOARhgAeZdz6NhYyXAAiksBmRtFKtQo1DR4qQCEMEBEZMwlqmACZLWm3ACiAB5QhsYcrmYwAMze1joAKhIYOLhgFADKcAAOGIlQIBJhbmoALHwCAIJYWCAA7jJyhREArJaV1TX6EiEuRTAAbK1VtfaO3Y3uAOyD7YHBzuNqABzTtQlJKelZOYT5CzAAnCs1TBgAbjgUhMRgewq8FUM1AOrJeMA5eLcW-IwA9ABU-xgAAVCAALGDIRDQGAAIzYGBgp2w%2BBgeB0wDyEgAnjAJLJYP9fgJ6vIrNopKSYAAfGBtWpU2n0mprZI4VIZbK5fJlP6AkHgyHQ2DwmCIjCwiAgLCIKBsIkVSXS2UuHw6Rl0x4a5mdMZMx4jJyhfUzIJ6zXtVkbTnbLE0i21E7nS5EcC8mAAoGgqAQ5AYXGiqTkIinNi7CVSmVymAKzRwYM4UMAeQk5SVUZczO1j118xNwwcRrY%2BZqs3NzKt7M2XJ2BRLTouVzdPw9-O9vv9MHAWADCJgADNkkWY8TGIaxpw1XZC%2BXHmXnHwAL5AA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Y6RAM0Wlsfy8AhvHpNYAW1oTEEgEa90YANqRe0APbRIAGkyQR8DQHcAQpXzHKyRAFEAHhxTJKGpqgz44iAL4BdcDAfEB8gA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Description

As #9114 merged, it is allowed to use enum self-members in bitwise operations when the allowBitwiseExpressions option. However, if bit operations are used nested, a lint error occurs.
I think the rule should also allow when using nested bitwise operations if this option is set.

Fail

const OUT = 1 << 0,;
enum Foo {
   Bar = 1 << 1,
   Baz = OUT | Foo.Bar
}

Pass

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,
}

Additional Info

The pass example was found in the typescript repository.

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulelocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy