`valid-typeof` does not report invalid comparisons to `undefined`
See original GitHub issueWhat 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:
- Created 7 years ago
- Comments:18 (18 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.Sorry, I meant string literals.