Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bug: [no-unsafe-enum-comparison] does not work with bit masks #6909

Closed as not planned
Labels
bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginwontfixThis will not be worked on
@mrazauskas

Description

@mrazauskas

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 havesearched for related issues and found none that matched my issue.
  • I haveread the FAQ and my problem is not listed.

Playground Link

https://typescript-eslint.io/play/#ts=5.0.3&sourceType=module&code=KYDwDg9gTgLgBAYwgOwM72MgrgWzgFQE8xgAxAGwEMBzVOAbwCg44BBZQuAXjgEY4APALgAGADTM4AVWQBrZBADuybn0HDeElgGUYUAJbJqq-kLgAmLXAByuAEbAoJ9XADMVgEIQI5YJRU8psIALIwAvoyMoJCwcABmWMgIMPoocAAWlKhEJBQ0ABSoEFhQCMAAXATEZFS0YnAwlFDUwDCVOTU0qACUDJJQrSUqhcWlwHAAZA1NLTC9XAvTza0A3OFAA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUFvcgAQBcBPABxQGNoBLEggWhXioDsCB6ZgeztmeQEMAZogbNYAWzrlO4kv2rJOzdFETRonaJHBgAviF1A&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA

Repro Code

exportconstenumTypeFlags{Any=1<<0,Unknown=1<<1,String=1<<2,Number=1<<3,Boolean=1<<4}exportfunctionhasTypeFlag(source:TypeFlags,target:TypeFlags){return(source&target)===target;}

ESLint Config

module.exports={"rules":{"@typescript-eslint/no-unsafe-enum-comparison":"error"}}

tsconfig

{"compilerOptions": {"strictNullChecks":true  }}

Expected Result

TypeScript compiler is using bit mask pattern internally. It is rare, but useful thing. A bitwise operator is used in comparison, but otherwise enum is compared with itself. Should this be allowed or at least have a config option, perhaps? What do you think?


Also possible to rework the code. It felt more readable with===, but could be like this too:

exportfunctionhasTypeFlag(source:TypeFlags,target:TypeFlags){returnBoolean(source&target);}

Actual Result

Good idea to add theno-unsafe-enum-comparison. As you can see in reproduction, currently it does not work with bit mask pattern. Might be it was simply overlooked use case.

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp