-
Notifications
You must be signed in to change notification settings - Fork 172
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
fix(valid-typeof): allow comparison with variables other than undefined, null, Object #570
Conversation
@kitsonk @lucacasonato @nayeemrmn what do you think about this PR? |
It would be good to get an example of what this would trigger on (e.g. a "bad" example). I am confused on what it would add over and above existing TypeScript strict type checking. |
@kitsonk typeof foo === "strnig"
typeof foo == "undefimed"
typeof bar != "nunber"
typeof bar !== "fucntion" There's one difference between ESLint's typeof foo === undefined
typeof foo == null
typeof foo !== Object I think TypeScript checking also treat these kinds of comparison as valid, but they are most likely mistakes by a programmer, so it'd be good to lint it. In summary, this PR changes two things:
|
Of those, only these two don't produce errors in TypeScript (which is somewhat disappointing, as I would have thought they would have had overlap type errors): typeof a === undefined
typeof a == null I am of the opinion we should avoid overlap of such things, personally. |
@kitsonk One concern I have is whether or not we need to care about JavaScript. If we avoided overlap with TypeScript, erroneous codes like |
@magurotuna What's the status of this PR? Are you still trying to get this merged? If so, please rebase, otherwise please close. |
Closing because it's stale. More consideration and discussion will be needed. |
Fixes #566
Please see #566 (comment) before reviewing because this fix relaxes the current restriction of
valid-typeof
rule, being against the previous discussion at #38.In addition, I've done with the following things:
VisitAll
instead ofVisit
to handle nested cases (Rules that should be refined further #330)