This repository has been archived by the owner on Mar 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 885
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add bigint support to restrict-plus-operand rule (#4814)
- Loading branch information
1 parent
a3a0b32
commit e17ea57
Showing
7 changed files
with
75 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions
42
test/rules/restrict-plus-operands/esnext-bigint/test.ts.lint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
[typescript]: >= 3.2.0 | ||
type MyNumber = number; | ||
type MyString = string; | ||
type MyBigInt = bigint; | ||
interface NumberStringBigint { | ||
first: MyNumber, | ||
second: MyString, | ||
third: MyBigInt | ||
} | ||
|
||
var x = 5; | ||
var y = "10"; | ||
var bigintVar = BigInt(200); | ||
var anyVar: any = 200; | ||
var pair: NumberStringBigint = { | ||
first: 5, first: 5, | ||
second: "10" second: "10", | ||
third: BigInt(100), | ||
}; | ||
|
||
const bigIntPassA = BigInt(1) + BigInt(2); | ||
const bigIntPassB = BigInt(1) + 100n; | ||
const bigIntFailA = BigInt(1) + 2; | ||
~~~~~~~~~~~~~ [Operands of '+' operation must either be both strings or both numbers or both bigints, but found bigint + 2] | ||
const bigIntFailB = BigInt(1) + "failureString"; | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~ [Operands of '+' operation must either be both strings or both numbers or both bigints, but found bigint + "failureString". Consider using template literals.] | ||
|
||
const bigIntFailC = bigintVar + x; | ||
~~~~~~~~~~~~~ [Operands of '+' operation must either be both strings or both numbers or both bigints, but found bigint + number] | ||
const bigIntFailD = y + bigintVar; | ||
~~~~~~~~~~~~~ [Operands of '+' operation must either be both strings or both numbers or both bigints, but found string + bigint. Consider using template literals.] | ||
const bigIntFailE = bigintVar + anyVar; | ||
~~~~~~~~~~~~~~~~~~ [Operands of '+' operation must either be both strings or both numbers or both bigints, but found bigint + any] | ||
|
||
const bigIntFailF = pair.first + pair.third; | ||
~~~~~~~~~~~~~~~~~~~~~~~ [Operands of '+' operation must either be both strings or both numbers or both bigints, but found number + bigint] | ||
const bigIntFailG = pair.third + pair.second; | ||
~~~~~~~~~~~~~~~~~~~~~~~~ [Operands of '+' operation must either be both strings or both numbers or both bigints, but found bigint + string. Consider using template literals.] | ||
const bigIntFailH = bigintVar + []; | ||
~~~~~~~~~~~~~~ [Operands of '+' operation must either be both strings or both numbers or both bigints, but found bigint + []] | ||
const bigIntFailI = bigintVar + {}; | ||
~~~~~~~~~~~~~~ [Operands of '+' operation must either be both strings or both numbers or both bigints, but found bigint + {}] |
5 changes: 5 additions & 0 deletions
5
test/rules/restrict-plus-operands/esnext-bigint/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "esnext" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"rules": { | ||
"restrict-plus-operands": true | ||
} | ||
} |