-
-
Notifications
You must be signed in to change notification settings - Fork 191
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
12$: diagnostic: typeof operator should warn when comparing to invalid string literals #1213
Comments
This is a great idea! I'll put 12$ on it. |
Hey Strager, I would love to try and tackle this issue! |
@milanjijo are you working on this task? |
@strager Is there any way to currently check a string literal against this list ("undefined", "object", "boolean", "number", "bigint", "string", "symbol" or "function") in the code? |
@singalhimanshu yes, you can compare the Expression::Literal->span()->string_view() to each element of the array. The detection code for a similar diagnostic which might help can be seen here: src/quick-lint-js/fe/parse.cpp:524 |
Is anyone still working on this issue ? Otherwise I would be interested to tackle it as i already have a working piece of code. Thank you ! |
When performing checks like
typeof x == "string"
, it is perfectly possible to misspell it as something liketypeof x == "strng"
(missingi
), which will always return false. Maybe there should be a warning for this?More generally, expressions of the form
typeof <a> [== or != or === or !==] <b>
where b is a string and not"undefined"
,"object"
,"boolean"
,"number"
,"bigint"
,"string"
,"symbol"
or"function"
I would be happy to implement this if approved and no-one else wants to :)
The text was updated successfully, but these errors were encountered: