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-find] support ternary branches in prefer-find#8421
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-find] support ternary branches in prefer-find#8421
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Thanks for the PR,@kirkwaiblinger! 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 commentedFeb 9, 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 commentedFeb 9, 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.
codecovbot commentedFeb 9, 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 #8421 +/- ##==========================================+ Coverage 86.94% 87.06% +0.11%========================================== Files 252 251 -1 Lines 12251 12278 +27 Branches 3861 3870 +9 ==========================================+ Hits 10652 10690 +38+ Misses 1332 1316 -16- Partials 267 272 +5
Flags with carried forward coverage won't be shown.Click here to find out more.
|
Uh oh!
There was an error while loading.Please reload this page.
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.
Uh oh!
There was an error while loading.Please reload this page.
| }, | ||
| ], | ||
| }, | ||
| { |
JoshuaKGoldbergFeb 23, 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.
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.
[Testing] Just to be through, could you also add a test for a desired report with and within a ternary? Like thevalid case above, but either with two.filters or with the[0] on the other side of the last)?
(Math.random()<0.5 ?[1,2,3].filter(x=>false) :[1,2,3].filter(x=>true))[0];
(Math.random()<0.5 ?[1,2,3].find(x=>true) :[1,2,3].filter(x=>true)[0]);
The cases lower down are a bit more complex. It's nice to have more straightforward ones to use as a reference too.
| }, | ||
| { | ||
| code:` | ||
| declare const f: any, g: any; |
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.
[Testing] Nit: here and below, if there's no need to use anany, might as well avoid it:
| declareconstf:any,g:any; | |
| declareconstf:unknown,g:unknown; |
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 would have a type error without. I was just too lazy to write out the actual type of the filter callback (and the rule doesn't care about the type of the filter callback) so i went for the easiest way to not error :)
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.
Personally, I'm +1 to avoid semantic errors, at least in newly added tests :)
Especially when it's not that hard:
- declare const f: any, g: any;+ declare const f: (x: unknown) => boolean, g: (x: unknown) => boolean;
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.
Fair enough, changed
Co-authored-by: Josh Goldberg ✨ <git@joshuakgoldberg.com>
8ea5d4c to9d1b79aCompare
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.
LGTM, nice! Since it's tricky logic being touched, will leave open for a bit under1 approval.
auvred 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.
LGTM 🚀
f397a3aUh oh!
There was an error while loading.Please reload this page.
auvred 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.



PR Checklist
Overview
Adds support for recursively checking ternary branches.