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] doesn't report on ternary but on equivalent ||#10517
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] doesn't report on ternary but on equivalent ||#10517
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Thanks for the PR,@OlivierZal! 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 commentedDec 18, 2024 • 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 commentedDec 18, 2024 • 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.
View yourCI Pipeline Execution ↗ for commitb771c7f.
☁️Nx Cloud last updated this comment at |
db11672
to586aa99
Compare0360ad0
to3f23cb4
Comparecodecovbot commentedDec 28, 2024 • 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 #10517 +/- ##==========================================+ Coverage 87.17% 87.18% +0.01%========================================== Files 448 450 +2 Lines 15598 15617 +19 Branches 4555 4562 +7 ==========================================+ Hits 13597 13616 +19 Misses 1645 1645 Partials 356 356
Flags with carried forward coverage won't be shown.Click here to find out more.
|
3f23cb4
toea899f8
CompareOlivierZal commentedDec 29, 2024 • 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.
@JoshuaKGoldberg,@kirkwaiblinger,this check seems to be stuck. However, tests passed so I guess the PR is ready for a first review. |
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.
A good start - nice job working with such tricky existing logic!
The tests forvalid
cases and primitives are very nice and thorough. Requesting changes on more thorough coverage ofinvalid
please. Thanks!
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
dfa9df1
to74a4059
CompareOlivierZal commentedDec 31, 2024 • 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.
Hi@JoshuaKGoldberg, thanks for the review, I've made at least 2 of the requested changes:
Regarding the fix/suggestion logic tests following the
Do you see any other cases I’ve missed that I could add? Or do you have something else in mind? |
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 think this is plenty thorough enough for me 😄 but I've also kind of burned out on reviewingprefer-nullish-coalescing
. We should get review from another @typescript-eslint/triage-team member.
@JoshuaKGoldberg,@kirkwaiblinger, waiting for this PR having a second review, I keep updating the branch each time a new PR is merged. Is it the right thing to do, or can I leave it as is until the review? |
OlivierZal commentedJan 20, 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.
Ready for review, but I remain open to feedback on#10517 (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.
I think the current algorithm and factorization looks good! There's one minor complaint, where I think you've added a workaround which can be avoided - I made a little suggestion PR in order to illustrate this, seeOlivierZal#2. Fortunately the test cases you've written validated this well when I was playing around 👍
I think if we make those few changes we'll be close to done iterating! 🙂
suggestion for prefer-nullish-coalescing PR
@kirkwaiblinger, I’m delighted I wasn’t too far off the mark 😅. Ultimately, I realized that the inconsistency mentioned in the corresponding issue went beyond the cited example, and since I’m still quite new to the project, I wasn’t entirely sure if taking a few liberties was appropriate. Thank you so much for your time, help, and guidance. Thelast commit only fixes a lint issue inthis commit; all the other checks passed successfully. |
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.
Few little nits but this is otherwise basically an approval! Great work on this!! It's delightful work on a real tricky part of the codebase 👍 Thanks for working on this!
(parent.consequent === node || | ||
parent.alternate === node || | ||
node.type === AST_NODE_TYPES.UnaryExpression) | ||
) { |
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.
Oh, I'm realizing that theseUnaryExpression
recursions are unnecessary as well, I think, right?
(parent.consequent===node|| | |
parent.alternate===node|| | |
node.type===AST_NODE_TYPES.UnaryExpression) | |
){ | |
(parent.consequent===node||parent.alternate===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.
indeed, it was the second part of my "workaround", that your suggestion fixed.
(parent.consequent === node || | ||
parent.alternate === node || | ||
node.type === AST_NODE_TYPES.UnaryExpression) |
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.
(parent.consequent===node|| | |
parent.alternate===node|| | |
node.type===AST_NODE_TYPES.UnaryExpression) | |
(parent.consequent===node||parent.alternate===node) |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Co-authored-by: Kirk Waiblinger <53019676+kirkwaiblinger@users.noreply.github.com>
Fixed! |
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.
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.
[Praise] Really nice refactors here. Love to see a -62 line count on a 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.
🚀 thanks for pushing through on this!
1e2305e
intotypescript-eslint:mainUh oh!
There was an error while loading.Please reload this page.
| datasource | package | from | to || ---------- | -------------------------------- | ------ | ------ || npm | @typescript-eslint/eslint-plugin | 8.21.0 | 8.22.0 || npm | @typescript-eslint/parser | 8.21.0 | 8.22.0 |## [v8.22.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8220-2025-01-27)##### 🩹 Fixes- **eslint-plugin:** \[no-unnecessary-template-expression] handle template literal type ([#10612](typescript-eslint/typescript-eslint#10612))- **eslint-plugin:** \[prefer-readonly] autofixer doesn't add type to property that is mutated in the constructor ([#10552](typescript-eslint/typescript-eslint#10552))- **eslint-plugin:** \[no-extraneous-class] handle accessor keyword ([#10678](typescript-eslint/typescript-eslint#10678))- **eslint-plugin:** \[no-shadow] don't report unnecessarily on valid ways of using module augmentation ([#10616](typescript-eslint/typescript-eslint#10616))- **eslint-plugin:** \[no-duplicate-type-constituents] handle nested types ([#10638](typescript-eslint/typescript-eslint#10638))- **eslint-plugin:** \[prefer-nullish-coalescing] doesn't report on ternary but on equivalent || ([#10517](typescript-eslint/typescript-eslint#10517))##### ❤️ Thank You- mdm317- Olivier Zalmanski [@OlivierZal](https://github.com/OlivierZal)- Ronen Amiel- YeonJuan [@yeonjuan](https://github.com/yeonjuan)You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
| datasource | package | from | to || ---------- | -------------------------------- | ------ | ------ || npm | @typescript-eslint/eslint-plugin | 8.21.0 | 8.22.0 || npm | @typescript-eslint/parser | 8.21.0 | 8.22.0 |## [v8.22.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8220-2025-01-27)##### 🩹 Fixes- **eslint-plugin:** \[no-unnecessary-template-expression] handle template literal type ([#10612](typescript-eslint/typescript-eslint#10612))- **eslint-plugin:** \[prefer-readonly] autofixer doesn't add type to property that is mutated in the constructor ([#10552](typescript-eslint/typescript-eslint#10552))- **eslint-plugin:** \[no-extraneous-class] handle accessor keyword ([#10678](typescript-eslint/typescript-eslint#10678))- **eslint-plugin:** \[no-shadow] don't report unnecessarily on valid ways of using module augmentation ([#10616](typescript-eslint/typescript-eslint#10616))- **eslint-plugin:** \[no-duplicate-type-constituents] handle nested types ([#10638](typescript-eslint/typescript-eslint#10638))- **eslint-plugin:** \[prefer-nullish-coalescing] doesn't report on ternary but on equivalent || ([#10517](typescript-eslint/typescript-eslint#10517))##### ❤️ Thank You- mdm317- Olivier Zalmanski [@OlivierZal](https://github.com/OlivierZal)- Ronen Amiel- YeonJuan [@yeonjuan](https://github.com/yeonjuan)You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
PR Checklist
Overview