From cefbb2d5f076d307a9558fdd3c11f369fede1576 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 4 Jun 2019 08:29:33 -0400 Subject: [PATCH] Update: support "bigint" in valid-typeof rule BigInt just moved to Stage 4, so add support for it to the valid-typeof rule. --- docs/rules/valid-typeof.md | 2 +- lib/rules/valid-typeof.js | 2 +- tests/lib/rules/valid-typeof.js | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/rules/valid-typeof.md b/docs/rules/valid-typeof.md index 2ce02b4906b2..fd0294d205aa 100644 --- a/docs/rules/valid-typeof.md +++ b/docs/rules/valid-typeof.md @@ -1,6 +1,6 @@ # enforce comparing `typeof` expressions against valid strings (valid-typeof) -For a vast majority of use cases, the result of the `typeof` operator is one of the following string literals: `"undefined"`, `"object"`, `"boolean"`, `"number"`, `"string"`, `"function"` and `"symbol"`. It is usually a typing mistake to compare the result of a `typeof` operator to other string literals. +For a vast majority of use cases, the result of the `typeof` operator is one of the following string literals: `"undefined"`, `"object"`, `"boolean"`, `"bigint"`, `"number"`, `"string"`, `"function"` and `"symbol"`. It is usually a typing mistake to compare the result of a `typeof` operator to other string literals. ## Rule Details diff --git a/lib/rules/valid-typeof.js b/lib/rules/valid-typeof.js index 16b2a47d371c..e4cedf3c52ae 100644 --- a/lib/rules/valid-typeof.js +++ b/lib/rules/valid-typeof.js @@ -39,7 +39,7 @@ module.exports = { create(context) { - const VALID_TYPES = ["symbol", "undefined", "object", "boolean", "number", "string", "function"], + const VALID_TYPES = ["symbol", "undefined", "object", "boolean", "bigint", "number", "string", "function"], OPERATORS = ["==", "===", "!=", "!=="]; const requireStringLiterals = context.options[0] && context.options[0].requireStringLiterals; diff --git a/tests/lib/rules/valid-typeof.js b/tests/lib/rules/valid-typeof.js index 0033a4f8abdb..50c7558d0675 100644 --- a/tests/lib/rules/valid-typeof.js +++ b/tests/lib/rules/valid-typeof.js @@ -25,6 +25,7 @@ ruleTester.run("valid-typeof", rule, { "typeof foo === 'function'", "typeof foo === 'undefined'", "typeof foo === 'boolean'", + "typeof foo === 'bigint'", "typeof foo === 'number'", "'string' === typeof foo", "'object' === typeof foo",