-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
valid-typeof: recommend "requireStringLiterals" true by default #14074
Comments
not just nowadays - typeof has never returned a non-string value. The reason for the option is so you can do That said, it's clearer to hardcode the string literal, so I'm in favor of this change :-) |
Hi @wmertens, thanks for the issue!
I'm not in favor of this change, because
Maybe we could use getStaticValue to check more than just string literals by default. |
if It's worth noting that many engines optimize typeof with a string literal, but historically do not do this for |
I think we can assume that the global
That's a good point, but I'm still not sure would it qualify for |
That is very much not a safe assumption unless you’re statically looking for all undefined assignments in the file, and unless eslint can know for certain it’s either an ES Module, or a node module - otherwise it could be concatenated with another file that defined |
But wouldn't it be ok to show an error in this case, so that only crazy people that redefine Are people like that even running eslint? |
If anyone wants to submit that rule change proposal, I'd be willing to champion reporting |
Do we need a special case in |
@btmills not everybody uses no-undefined, I personally find it annoying |
We aren’t moving forward with this, so closing. |
The version of ESLint you are using.
7.18
The problem you want to solve.
I typed
typeof v !== undefined
instead oftypeof v !== 'undefined'
and eslint with the recommended settings didn't warn me. This was one of those hard to find stupid bugs.Your take on the correct solution to problem.
Since
typeof
nowadays only returns strings, I propose that the optionrequireStringLiterals
betrue
by default in theeslint:recommended
settings.Are you willing to submit a pull request to implement this change?
Sure
The text was updated successfully, but these errors were encountered: