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
rule: no double-negation in boolean context #557
Comments
Working on this. The rule name |
That name sounds good to me. |
I'd go no-extra-Boolean-cast We tend to use "extra" in a lot of rules |
Couple of on-the-fly decisions I've made and hope you can confirm:
|
@btmills: First one: nope, those values are both observable. Remember, |
@michaelficarra Thanks, I forgot to consider the result of the expression. Should have a PR here in a few minutes. |
Disallows double-negation Boolean casts in contexts where the result is already coerced to a Boolean. Proposed in eslint#557 by @michaelficarra.
New Rule: no-extra-boolean-cast (fixes #557)
Double negation (
!!<expr>
) is often used for casting to bool, but in a boolean context this is unnecessary. Boolean contexts are anywhere a value will be coerced to boolean.if(<bool>) ...
<bool> ? ... : ...
do ... while(<bool>)
while(<bool>) ...
for(...; <bool>; ...) ...
Boolean(<bool>)
new Boolean(<bool>)
!<bool>
A similar proposal was recently submitted to jshint: jshint/jshint#1487.
The text was updated successfully, but these errors were encountered: