Skip to content

Commit eee6d49

Browse files
webschikbradzacher
authored andcommitted
fix(eslint-plugin): support BigInt in restrict-plus-operands rule (#344)
Fixes #309
1 parent ba0d524 commit eee6d49

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

packages/eslint-plugin/src/rules/restrict-plus-operands.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ export default util.createRule({
5454

5555
const stringType = typeChecker.typeToString(type);
5656

57-
if (stringType === 'number' || stringType === 'string') {
57+
if (
58+
stringType === 'number' ||
59+
stringType === 'string' ||
60+
stringType === 'bigint'
61+
) {
5862
return stringType;
5963
}
6064
return 'invalid';

packages/eslint-plugin/tests/fixtures/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"module": "commonjs",
55
"strict": true,
66
"esModuleInterop": true,
7-
"lib": ["es2015", "es2017"]
7+
"lib": ["es2015", "es2017", "esnext"]
88
}
99
}

packages/eslint-plugin/tests/rules/restrict-plus-operands.test.ts

+22
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ ruleTester.run('restrict-plus-operands', rule, {
2323
`var foo = parseInt("5.5", 10) + 10;`,
2424
`var foo = parseFloat("5.5", 10) + 10;`,
2525
`var foo = 1n + 1n;`,
26+
`var foo = BigInt(1) + 1n`,
27+
`var foo = 1n; foo + 2n`,
2628
`
2729
function test () : number { return 2; }
2830
var foo = test("5.5", 10) + 10;
@@ -283,5 +285,25 @@ var foo = pair + pair;
283285
},
284286
],
285287
},
288+
{
289+
code: `var foo = 1n; foo + 1`,
290+
errors: [
291+
{
292+
messageId: 'notBigInts',
293+
line: 1,
294+
column: 15,
295+
},
296+
],
297+
},
298+
{
299+
code: `var foo = 1; foo + 1n`,
300+
errors: [
301+
{
302+
messageId: 'notBigInts',
303+
line: 1,
304+
column: 14,
305+
},
306+
],
307+
},
286308
],
287309
});

0 commit comments

Comments
 (0)