-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed as not planned
Labels
bugSomething isn't workingSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-pluginwontfixThis will not be worked onThis will not be worked on
Description
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.
Playground Link
Repro Code
export const enum TypeFlags {
Any = 1 << 0,
Unknown = 1 << 1,
String = 1 << 2,
Number = 1 << 3,
Boolean = 1 << 4
}
export function hasTypeFlag(source: TypeFlags, target: TypeFlags) {
return (source & target) === target;
}
ESLint Config
module.exports = {
"rules": {
"@typescript-eslint/no-unsafe-enum-comparison": "error"
}
}
tsconfig
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:
export function hasTypeFlag(source: TypeFlags, target: TypeFlags) {
return Boolean(source & target);
}
Actual Result
Good idea to add the no-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
Labels
bugSomething isn't workingSomething isn't workingpackage: eslint-pluginIssues related to @typescript-eslint/eslint-pluginIssues related to @typescript-eslint/eslint-pluginwontfixThis will not be worked onThis will not be worked on