Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from Jun 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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