-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Disallow implicit boolean casting of strings and numbers #49
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
Comments
We’re interested in doing this in GitHub Desktop: desktop/desktop#3538. I tried to add a rule in desktop/desktop#3550, but the type information available was limited, and @iAmWillShepherd suggested that we try to write this rule with TSLint instead. |
I suppose you'd need to use the Language Service API to access accurate type information, especially when you're accessing properties that were defined in a separate file. Not sure how easy it'd be to integrate that into ESLint's lifecycle. |
Bump! I would love to see this too. This could be added as an option for the |
flow supports this via their Speaking from experience over my last few months at facebook, it's actually really, really annoying; most engineers I've spoken to hate it! But if there is demand from the community, it's a rule we could look into. |
As a temporary workaround, one can use I miss this feature from Flow and would love to see this as a rule. Chatter I saw on the TypeScript tracker indicated it is unlikely to be added to the compiler. |
|
It'd be great to have a lint rule that disallows (possible) strings and numbers from being implicitly converted to booleans:
Besides
if
statements this would apply to ternary statements as well as&&
,||
and!
operators.For the above examples passing code could be:
I can see a stricter version of this rule which enforces explicit conversions even if a value can only be a string or number.
The text was updated successfully, but these errors were encountered: