Skip to content
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

[diagnostic] warn on typeof undeclared variable #825

Open
vegerot opened this issue Aug 16, 2022 · 2 comments
Open

[diagnostic] warn on typeof undeclared variable #825

vegerot opened this issue Aug 16, 2022 · 2 comments

Comments

@vegerot
Copy link
Contributor

vegerot commented Aug 16, 2022

Thanks for quick-lint! Big fan

While working on my first JS project in a while, I wrote this bug

function foo(obj1, obj2) {
  if (typeof obj !== typeof obj2) {}
  
}

and was disappointed quick-lint didn’t at least give me a warning

@strager
Copy link
Collaborator

strager commented Aug 16, 2022

typeof is often used to detect if a variable exists in the global scope. We can't know what the programmer intended for typeof in your example.

Can you think of a heuristic which will catch your example but not produce false positive warnings for things like typeof WebTransport?

@CoderMuffin
Copy link
Contributor

CoderMuffin commented Mar 17, 2024

@strager @vegerot maybe it should be a warning unless it is immediately compared to "undefined"?
maybe a config setting could be added to disable it if it is too aggressive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants