Skip to content
Permalink
Browse files

fix(eslint-plugin): support BigInt in restrict-plus-operands rule (#344)

Fixes #309
  • Loading branch information...
webschik authored and bradzacher committed Apr 11, 2019
1 parent ba0d524 commit eee6d49bbde8d7ff512a009d3dde10c430a6f6c5
@@ -54,7 +54,11 @@ export default util.createRule({

const stringType = typeChecker.typeToString(type);

if (stringType === 'number' || stringType === 'string') {
if (
stringType === 'number' ||
stringType === 'string' ||
stringType === 'bigint'
) {
return stringType;
}
return 'invalid';
@@ -4,6 +4,6 @@
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"lib": ["es2015", "es2017"]
"lib": ["es2015", "es2017", "esnext"]
}
}
@@ -23,6 +23,8 @@ ruleTester.run('restrict-plus-operands', rule, {
`var foo = parseInt("5.5", 10) + 10;`,
`var foo = parseFloat("5.5", 10) + 10;`,
`var foo = 1n + 1n;`,
`var foo = BigInt(1) + 1n`,
`var foo = 1n; foo + 2n`,
`
function test () : number { return 2; }
var foo = test("5.5", 10) + 10;
@@ -283,5 +285,25 @@ var foo = pair + pair;
},
],
},
{
code: `var foo = 1n; foo + 1`,
errors: [
{
messageId: 'notBigInts',
line: 1,
column: 15,
},
],
},
{
code: `var foo = 1; foo + 1n`,
errors: [
{
messageId: 'notBigInts',
line: 1,
column: 14,
},
],
},
],
});

0 comments on commit eee6d49

Please sign in to comment.
You can’t perform that action at this time.