Skip to content
Permalink
Browse files

Update: support "bigint" in valid-typeof rule (#11802)

* Update: support "bigint" in valid-typeof rule

BigInt just moved to Stage 4, so add support for it to
the valid-typeof rule.

* Docs: add Further Reading to valid-typeof rule

This commit adds a Further Reading section to the
valid-typeof rule documentation.
  • Loading branch information...
cjihrig authored and ilyavolodin committed Jun 8, 2019
1 parent e0fafc8 commit e4ab0531c4e44c23494c6a802aa2329d15ac90e5
Showing with 7 additions and 2 deletions.
  1. +5 −1 docs/rules/valid-typeof.md
  2. +1 −1 lib/rules/valid-typeof.js
  3. +1 −0 tests/lib/rules/valid-typeof.js
@@ -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"`, `"number"`, `"string"`, `"function"`, `"symbol"`, and `"bigint"`. It is usually a typing mistake to compare the result of a `typeof` operator to other string literals.

## Rule Details

@@ -57,3 +57,7 @@ typeof bar === typeof qux
## When Not To Use It

You may want to turn this rule off if you will be using the `typeof` operator on host objects.

## Further Reading

* [MDN: `typeof` documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof)
@@ -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", "number", "string", "function", "bigint"],
OPERATORS = ["==", "===", "!=", "!=="];

const requireStringLiterals = context.options[0] && context.options[0].requireStringLiterals;
@@ -26,6 +26,7 @@ ruleTester.run("valid-typeof", rule, {
"typeof foo === 'undefined'",
"typeof foo === 'boolean'",
"typeof foo === 'number'",
"typeof foo === 'bigint'",
"'string' === typeof foo",
"'object' === typeof foo",
"'function' === typeof foo",

0 comments on commit e4ab053

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