Skip to content

Commit b3e0e75

Browse files
fix(eslint-plugin): [no-unsafe-enum-comparison] exempt bit shift operators (#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>
1 parent b62affe commit b3e0e75

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

packages/eslint-plugin/src/rules/no-unsafe-enum-comparison.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default util.createRule({
6363
}
6464

6565
return {
66-
'BinaryExpression[operator=/=|<|>/]'(
66+
'BinaryExpression[operator=/^[<>!=]?={0,2}$/]'(
6767
node: TSESTree.BinaryExpression,
6868
): void {
6969
const left = getTypeFromNode(node.left);

packages/eslint-plugin/tests/rules/no-unsafe-enum-comparison.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,20 @@ ruleTester.run('strict-enums-comparison', rule, {
292292
num === someFunction;
293293
mixed === someFunction;
294294
`,
295+
`
296+
enum Fruit {
297+
Apple,
298+
}
299+
300+
const bitShift = 1 << Fruit.Apple;
301+
`,
302+
`
303+
enum Fruit {
304+
Apple,
305+
}
306+
307+
const bitShift = 1 >> Fruit.Apple;
308+
`,
295309
],
296310
invalid: [
297311
{

0 commit comments

Comments
 (0)