Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Bug: no-unsafe-enum-comparison - False positives with bit shifts #7067

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

Closed
4 tasks done
Zamiell opened this issue May 26, 2023 · 0 comments · Fixed by #7074
Closed
4 tasks done

Bug: no-unsafe-enum-comparison - False positives with bit shifts #7067

Zamiell opened this issue May 26, 2023 · 0 comments · Fixed by #7074
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@Zamiell
Copy link
Contributor

Zamiell commented May 26, 2023

Before You File a Bug Report Please Confirm You Have Done The Following...

  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have searched for related issues and found none that matched my issue.
  • I have read the FAQ and my problem is not listed.

Repro Code

enum Foo {
  Bar,
}

const myBitShift = 1 << Foo.Bar

This gives the following error:

The two values in this comparison do not have a shared enum type.

The error message says that we are doing a "comparison", but this is false. We are not doing a comparison at all, we are doing a bit shift.

Thus, I propose that the << operator and the >> operator are exempt from being examined by this rule, and I assume that this was just an oversight when the rule was originally implemented. (Well, I was actually the person to originally implement it, but I guess this behavior got lost in translation somewhere.)


Playground

https://typescript-eslint.io/play/#ts=5.0.4&sourceType=module&code=KYOwrgtgBAYg9nKBvAsAKClAQgQwE4A06AvuugMZwgDOALlBAJ5YCWtAygBYsBm9AvFACMUADyjYCAHS486IA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1tieQEMAZonpNYAW1pkOY4nyrIOTdFETRoHaJHBgAviB1A&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA

ESLint Config

I am using the recommend configs, i.e.:

  extends: [
    // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/recommended.ts
    "plugin:@typescript-eslint/recommended",

    // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/recommended-requiring-type-checking.ts
    "plugin:@typescript-eslint/recommended-requiring-type-checking",

    // https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/strict.ts
    "plugin:@typescript-eslint/strict",
  ],
@Zamiell Zamiell added bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look labels May 26, 2023
@JoshuaKGoldberg JoshuaKGoldberg added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels May 28, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepting prs Go ahead, send a pull request that resolves this issue bug Something isn't working package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
2 participants