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
Update: enforceForLogicalOperands no-extra-boolean-cast (fixes #12137) #12734
Update: enforceForLogicalOperands no-extra-boolean-cast (fixes #12137) #12734
Conversation
…ttps://github.com/jmoore914/eslint into no-extra-boolean-cast-enforce-for-logical-operands
@jmoore914 the title can be just:
|
@mdjermanovic thanks, title has been updated! |
Re-run the checks and it's passing now. It happens sometimes on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR, this looks very good in general!
…wer parameters to functions; check precedence in fixer
Nice suggestions! Let me know what you think now :) |
…edence check; added additional example
…cast-enforce-for-logical-operands
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes! Looks great, just left several minor suggestions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Just a couple of minor suggestions and I think this is finished.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small question about checking if Boolean
is an actual global, but otherwise this LGTM!
@@ -1,6 +1,6 @@ | |||
/** | |||
* @fileoverview Tests for no-extra-boolean-cast rule. | |||
* @author Brandon Mills | |||
*@fileoverview Tests for no-extra-boolean-cast rule. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind reverting these two line changes? Seems like an accidental change.
function isBooleanFunctionOrConstructorCall(node) { | ||
|
||
// Boolean(<bool>) and new Boolean(<bool>) | ||
return (node.type === "CallExpression" || node.type === "NewExpression") && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to ensure that Boolean
isn't a shadowed global variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should be also done in CallExpression(node)
.
Though I think that both global Boolean
fixes can be a separate PR because it's an existing issue (this function was extracted from UnaryExpression(node)
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Separating it out into a separate PR sounds good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks!
This PR also fixes 3 bugs in the default behavior:
/*eslint no-extra-boolean-cast: ["error"]*/
// these were false negatives
Boolean(Boolean(a));
new Boolean(Boolean(a));
// these were false positives
Boolean(a, !!b);
new Boolean(a, !!b);
// this was invalid autofix to: a = b ? c : d;
!!(a = b) ? c : d;
Side note: the fixer can be improved to avoid some unnecessary parens. This can be a separate PR as it's already happening in the actual master version for extra Boolean()
so I believe it isn't directly related to this enhancement.
Also, it's questionable should the fixer add parens around b || c
for if (a || Boolean(b || c)) {}
since a || b || c
has different semantics. I think this isn't a big issue as it doesn't change behavior, it can be evaluated and fixed if necessary in the same PR for the extra parens.
I edited the description just to link the issue. Not sure why that issue doesn't appear under "Linked issues" in the list of issues to choose. @jmoore914 I think that the accidental change noticed in this comment is the only unaddressed concern at the moment. |
…cast-enforce-for-logical-operands
Could've sworn I fixed that! Well, should be all good now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Thanks for contributing! |
@jmoore914 Thank you for taking this on and getting it landed. I look forward to being able to use it soon. |
…#12137) (eslint#12734) * Working rule, updated documentation * New: Added enforceForLogicalOperands option to no-extra-boolean-cast (fixes eslint#12137) * Add default for schema option; renamed functions for clarity; pass fewer parameters to functions; check precedence in fixer * Removed extra variable from function; fixed function name; fixed precedence check; added additional example * Updated documentation * Removed outdated legacy code method * Added additional tests * Renamed function * Added additional test; updated documentation * Switched docs examples order; fixed comments in rule; added test for inserting space * Fixed accidentally edited lines
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[X ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
fixes #12137
What changes did you make? (Give an overview)
Is there anything you'd like reviewers to focus on?
Nope