Skip to content

Commit

Permalink
fix(eslint-plugin): support BigInt in restrict-plus-operands rule (#344)
Browse files Browse the repository at this point in the history
Fixes #309
  • Loading branch information
webschik authored and bradzacher committed Apr 11, 2019
1 parent ba0d524 commit eee6d49
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/eslint-plugin/src/rules/restrict-plus-operands.ts
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin/tests/fixtures/tsconfig.json
Expand Up @@ -4,6 +4,6 @@
"module": "commonjs",
"strict": true,
"esModuleInterop": true,
"lib": ["es2015", "es2017"]
"lib": ["es2015", "es2017", "esnext"]
}
}
22 changes: 22 additions & 0 deletions packages/eslint-plugin/tests/rules/restrict-plus-operands.test.ts
Expand Up @@ -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;
Expand Down Expand Up @@ -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.