Skip to content

Commit

Permalink
Fix S17647(no-identical-expressions): Consider bigint for 1bit shif…
Browse files Browse the repository at this point in the history
…ting as valid (#416)
  • Loading branch information
victor-diez-sonarsource committed Aug 23, 2023
1 parent 244cd5d commit 88a748d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/rules/no-identical-expressions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ function hasIdentifierOperands(node: TSESTree.BinaryExpression | TSESTree.Logica
}

function isOneOntoOneShifting(node: TSESTree.BinaryExpression | TSESTree.LogicalExpression) {
return node.operator === '<<' && isLiteral(node.left) && node.left.value === 1;
return (
node.operator === '<<' &&
isLiteral(node.left) &&
(node.left.value === 1 || node.left.value === 1n)
);
}

const message =
Expand Down
1 change: 1 addition & 0 deletions tests/rules/no-identical-expressions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import rule = require('../../src/rules/no-identical-expressions');
ruleTester.run('no-identical-expressions', rule, {
valid: [
{ code: `1 << 1;` },
{ code: `1n << 1n;` },
{ code: `foo(), foo();` },
{ code: `if (Foo instanceof Foo) { }` },
{
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es2015",
"target": "es2020",
"module": "commonjs",
"lib": ["es2017"],
"strict": true,
Expand Down

0 comments on commit 88a748d

Please sign in to comment.