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): [prefer-nullish-coalescing] fix parenthesization bug in suggestion#11098
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): [prefer-nullish-coalescing] fix parenthesization bug in suggestion#11098
Uh oh!
There was an error while loading.Please reload this page.
Conversation
…y are missing in the original code
Thanks for the PR,@mdm317! 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 commentedApr 24, 2025 • 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 configuration. |
nx-cloudbot commentedApr 24, 2025 • 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.
codecovbot commentedApr 24, 2025 • 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 ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@## main #11098 +/- ##======================================= Coverage 90.83% 90.84% ======================================= Files 497 497 Lines 50279 50295 +16 Branches 8297 8299 +2 =======================================+ Hits 45672 45690 +18+ Misses 4592 4590 -2 Partials 15 15
Flags with carried forward coverage won't be shown.Click here to find out more.
🚀 New features to boost your workflow:
|
Looks good! |
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 like it will solve the specific bug case but just have a question about being generic and/or reusing code. Thanks for sending!
@@ -932,3 +934,17 @@ function formatComments( | |||
) | |||
.join(''); | |||
} | |||
function getTextWithEnsuredParentheses( |
kirkwaiblingerApr 28, 2025 • 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.
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 wonder if we can leverage existing infrastructure around parenthesization/wrapping rather than hard-code a special case fora ? b : c
... is there a specific reason to do that? I worry we might miss parens on other expressions that might need it?
FWIW I had success passing all the test cases with the following...
context.report({ node,messageId:'preferNullishOverTernary',// TODO: also account for = in the ternary clausedata:{equals:''},suggest:[{messageId:'suggestNullish',data:{equals:''},fix(fixer:TSESLint.RuleFixer):TSESLint.RuleFix{returnfixer.replaceText(node,`${getTextWithParentheses(context.sourceCode,nullishCoalescingParams.nullishCoalescingLeftNode,)} ??${(()=>{constbranch=getBranchNodes(node,operator,).nullishBranch;if(isParenthesized(branch,context.sourceCode)){returngetTextWithParentheses(context.sourceCode,branch,);}returngetWrappedCode(getTextWithParentheses(context.sourceCode,branch),getOperatorPrecedenceForNode(branch),OperatorPrecedence.Coalesce,);})()}`,);},},],});
Curious what you think!
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.
It definitely seems much better to use the existing infrastructure rather than hard-coding it!
I've updated the code to use your approach.
Thanks for pointing it out!
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 sending this in!
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.
Super!
Great review suggestion too Kirk :)
9d6a6d0
intotypescript-eslint:mainUh oh!
There was an error while loading.Please reload this page.
PR Checklist
Overview
When running the
Fix
, add parentheses to conditional expressions that are missing them