Skip to content

Commit

Permalink
fix(eslint-plugin): [no-unsafe-enum-comparison] exempt bit shift oper…
Browse files Browse the repository at this point in the history
…ators (#7074)

* fix: exempt bit shift operators

* Add test for other bit shift operator

* fix: extend regex to replace if statement

* fix: use more precise regex

---------

Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
  • Loading branch information
Melandra and JoshuaKGoldberg committed Jul 17, 2023
1 parent b62affe commit b3e0e75
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Expand Up @@ -63,7 +63,7 @@ export default util.createRule({
}

return {
'BinaryExpression[operator=/=|<|>/]'(
'BinaryExpression[operator=/^[<>!=]?={0,2}$/]'(
node: TSESTree.BinaryExpression,
): void {
const left = getTypeFromNode(node.left);
Expand Down
Expand Up @@ -292,6 +292,20 @@ ruleTester.run('strict-enums-comparison', rule, {
num === someFunction;
mixed === someFunction;
`,
`
enum Fruit {
Apple,
}
const bitShift = 1 << Fruit.Apple;
`,
`
enum Fruit {
Apple,
}
const bitShift = 1 >> Fruit.Apple;
`,
],
invalid: [
{
Expand Down

0 comments on commit b3e0e75

Please sign in to comment.