Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
fix(eslint-plugin): [no-unnecessary-boolean-literal-compare] fixer should handle parentheses#6569
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
fix(eslint-plugin): [no-unnecessary-boolean-literal-compare] fixer should handle parentheses#6569
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…ould handle parentheses
nx-cloudbot commentedMar 4, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thanks for the PR,@armano2! typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community. The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately. Thanks again! 🙏Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently onhttps://opencollective.com/typescript-eslint. |
netlifybot commentedMar 4, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
✅ Deploy Preview fortypescript-eslint ready!
To edit notification comments on pull requests, go to yourNetlify site settings. |
…olean-literal-compare-braces
codecovbot commentedMar 4, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@## main #6569 +/- ##==========================================+ Coverage 90.66% 90.71% +0.04%========================================== Files 376 376 Lines 12851 12855 +4 Branches 3783 3783 ==========================================+ Hits 11651 11661 +10+ Misses 856 850 -6 Partials 344 344
Flags with carried forward coverage won't be shown.Click here to find out more.
|
| ); | ||
| // if the expression `exp` isn't nullable, or we're comparing to `true`, | ||
| // we can just replace the entire comparison with `exp` or `!exp` |
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.
after further investigation we could simplify this fixer to
fix:function*(fixer){constisUnaryNegation=node.parent!=null&&nodeIsUnaryNegation(node.parent);constmutatedNode=isUnaryNegation ?node.parent! :node;yieldfixer.replaceText(mutatedNode,sourceCode.getText(comparison.expression),);constshouldNegate=comparison.literalBooleanInComparison ?!comparison.negated :comparison.negated;if(isUnaryNegation===shouldNegate){yieldfixer.insertTextBefore(mutatedNode,'!');if(!util.isStrongPrecedenceNode(comparison.expression)){yieldfixer.insertTextBefore(mutatedNode,'(');yieldfixer.insertTextAfter(mutatedNode,')');}}// if the expression `exp` is nullable, and we're not comparing to `true`,// we can just replace the entire comparison with `exp` or `!exp`if(comparison.expressionIsNullableBoolean&&!comparison.literalBooleanInComparison){// provide the default `true`yieldfixer.insertTextBefore(mutatedNode,'(');yieldfixer.insertTextAfter(mutatedNode,' ?? true)');}}
that should allow us to provide better fixer for
// sourceif(!(varBoolean===false)){}// currentif(!(!varBoolean)){}// newif(varBoolean){}
i'm not sure if we should push this with this fix
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.
I like it 😄 +1 to including it here. Also a +1 to filing a followup if you want to get this in sooner.
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.
I'm going to land this as-is for now, just so we can get this fix out with the next release.
We can follow-up next week with the changes to simplify this fixer later
JoshuaKGoldberg left a comment
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.
💯
| ); | ||
| // if the expression `exp` isn't nullable, or we're comparing to `true`, | ||
| // we can just replace the entire comparison with `exp` or `!exp` |
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.
I like it 😄 +1 to including it here. Also a +1 to filing a followup if you want to get this in sooner.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
PR Checklist
instanceof#6567Overview
Add missing handling for removal and adding parenthesis in rule fixer
new cases covered:
old fixer result
new fixer result
initially i was planning to extend range of fixer to include
)(but after further investigation this started generating to many edge caseseg.
(false) === x instanceof Error