Skip to content

Commit

Permalink
Update: support "bigint" in valid-typeof rule (#11802)
Browse files Browse the repository at this point in the history
* 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 e4ab053
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion 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"`, `"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

Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion lib/rules/valid-typeof.js
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions tests/lib/rules/valid-typeof.js
Expand Up @@ -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",
Expand Down

0 comments on commit e4ab053

Please sign in to comment.