- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 191
Open
Labels
for hireGet paid for working on this task: https://quick-lint-js.com/hiring.htmlGet paid for working on this task: https://quick-lint-js.com/hiring.htmlgood first issueGood for newcomers and C++ beginnersGood for newcomers and C++ beginners
Description
When performing checks like typeof x == "string"
, it is perfectly possible to misspell it as something like typeof x == "strng"
(missing i
), 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 :)
Metadata
Metadata
Assignees
Labels
for hireGet paid for working on this task: https://quick-lint-js.com/hiring.htmlGet paid for working on this task: https://quick-lint-js.com/hiring.htmlgood first issueGood for newcomers and C++ beginnersGood for newcomers and C++ beginners
Activity
[-][diagnostic] typeof operator should warn when comparing to invalid string literals [/-][+]diagnostic: typeof operator should warn when comparing to invalid string literals [/+]strager commentedon Apr 27, 2024
This is a great idea! I'll put 12$ on it.
[-]diagnostic: typeof operator should warn when comparing to invalid string literals [/-][+]12$: diagnostic: typeof operator should warn when comparing to invalid string literals [/+]milanjijo commentedon May 14, 2024
Hey Strager, I would love to try and tackle this issue!
singalhimanshu commentedon Jun 9, 2024
@milanjijo are you working on this task?
singalhimanshu commentedon Jun 9, 2024
@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?
CoderMuffin commentedon Jun 9, 2024
@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
dubloom commentedon Aug 26, 2024
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 !