question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`valid-typeof` does not report invalid comparisons to `undefined`

See original GitHub issue

What version of ESLint are you using? 3.1.0

What parser (default, Babel-ESLint, etc.) are you using? default

Please show your full configuration:

{
  "rules": {
    "valid-typeof": 2
  }
}

What did you do? Please include the actual source code causing the issue.

// oops, this was probably supposed to be the string 'undefined'
if (typeof window === undefined) {
  foo();
}

What did you expect to happen?

I expect ESLint to report an error, since the global undefined value is not a valid typeof comparison.

What actually happened? Please include the actual, raw output from ESLint.

ESLint did not detect any errors.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:18 (18 by maintainers)

github_iconTop GitHub Comments

3reactions
nzakascommented, Jul 18, 2016

I think the only way we can possibly do something that makes sense is to add an option like requireStringLiterals that ensures the RHS is always a string. Anything else is just guessing and not appropriate for this rule.

2reactions
ilyavolodincommented, Aug 13, 2016

Sorry, I meant string literals.

Read more comments on GitHub >

github_iconTop Results From Across the Web

valid-typeof - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Do TypeScript and ESLint have overlapping purposes?
1:13 error 'someUndefinedVariable' is not defined no-undef 4:1 error ... 7:20 error Invalid typeof comparison value valid-typeof 9:3 error ...
Read more >
Invalid typeof value '{a}' - JSLint Error Explanations
The "Invalid typeof value '{a}'" error is thrown when JSHint encounters a comparison with a typeof expression on one side and an invalid...
Read more >
List of available rules - ESLint - Pluggable JavaScript linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Disallow Use of undefined Variable (no-undefined) - ESLint
Examples of incorrect code for this rule: /*eslint no-undefined: "error"*/ var foo = undefined; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found