From eee6d49bbde8d7ff512a009d3dde10c430a6f6c5 Mon Sep 17 00:00:00 2001 From: Denys Kniazevych Date: Fri, 12 Apr 2019 00:25:03 +0200 Subject: [PATCH] fix(eslint-plugin): support BigInt in restrict-plus-operands rule (#344) Fixes #309 --- .../src/rules/restrict-plus-operands.ts | 6 ++++- .../tests/fixtures/tsconfig.json | 2 +- .../rules/restrict-plus-operands.test.ts | 22 +++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin/src/rules/restrict-plus-operands.ts b/packages/eslint-plugin/src/rules/restrict-plus-operands.ts index 6b63f88a4f7..62b1b1f79ce 100644 --- a/packages/eslint-plugin/src/rules/restrict-plus-operands.ts +++ b/packages/eslint-plugin/src/rules/restrict-plus-operands.ts @@ -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'; diff --git a/packages/eslint-plugin/tests/fixtures/tsconfig.json b/packages/eslint-plugin/tests/fixtures/tsconfig.json index 8702b63472b..bedda0e3dec 100644 --- a/packages/eslint-plugin/tests/fixtures/tsconfig.json +++ b/packages/eslint-plugin/tests/fixtures/tsconfig.json @@ -4,6 +4,6 @@ "module": "commonjs", "strict": true, "esModuleInterop": true, - "lib": ["es2015", "es2017"] + "lib": ["es2015", "es2017", "esnext"] } } diff --git a/packages/eslint-plugin/tests/rules/restrict-plus-operands.test.ts b/packages/eslint-plugin/tests/rules/restrict-plus-operands.test.ts index 4cff2c7c5c1..ae4fe89af15 100644 --- a/packages/eslint-plugin/tests/rules/restrict-plus-operands.test.ts +++ b/packages/eslint-plugin/tests/rules/restrict-plus-operands.test.ts @@ -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, + }, + ], + }, ], });