Skip to content
This repository was archived by the owner on Oct 3, 2024. It is now read-only.

Commit 88a748d

Browse files
Fix S17647(no-identical-expressions): Consider bigint for 1bit shifting as valid (#416)
1 parent 244cd5d commit 88a748d

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

src/rules/no-identical-expressions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ function hasIdentifierOperands(node: TSESTree.BinaryExpression | TSESTree.Logica
5353
}
5454

5555
function isOneOntoOneShifting(node: TSESTree.BinaryExpression | TSESTree.LogicalExpression) {
56-
return node.operator === '<<' && isLiteral(node.left) && node.left.value === 1;
56+
return (
57+
node.operator === '<<' &&
58+
isLiteral(node.left) &&
59+
(node.left.value === 1 || node.left.value === 1n)
60+
);
5761
}
5862

5963
const message =

tests/rules/no-identical-expressions.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import rule = require('../../src/rules/no-identical-expressions');
2323
ruleTester.run('no-identical-expressions', rule, {
2424
valid: [
2525
{ code: `1 << 1;` },
26+
{ code: `1n << 1n;` },
2627
{ code: `foo(), foo();` },
2728
{ code: `if (Foo instanceof Foo) { }` },
2829
{

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es2015",
3+
"target": "es2020",
44
"module": "commonjs",
55
"lib": ["es2017"],
66
"strict": true,

0 commit comments

Comments
 (0)