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

feat: valid-typeof: always ban undefined #15635

Merged
merged 6 commits into from Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions lib/rules/valid-typeof.js
Expand Up @@ -72,6 +72,8 @@ module.exports = {
if (VALID_TYPES.indexOf(value) === -1) {
context.report({ node: sibling, messageId: "invalidValue" });
}
} else if (sibling.type === "Identifier" && sibling.name === "undefined") {
context.report({ node: sibling, messageId: "notString" });
mdjermanovic marked this conversation as resolved.
Show resolved Hide resolved
} else if (requireStringLiterals && !isTypeofExpression(sibling)) {
context.report({ node: sibling, messageId: "notString" });
}
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/rules/valid-typeof.js
Expand Up @@ -141,6 +141,10 @@ ruleTester.run("valid-typeof", rule, {
options: [{ requireStringLiterals: true }],
errors: [{ messageId: "notString", type: "Identifier" }]
},
{
code: "if (typeof bar !== undefined) {}",
errors: [{ messageId: "notString", type: "Identifier" }]
},
{
code: "typeof foo === undefined",
options: [{ requireStringLiterals: true }],
Expand Down