-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
fix(eslint-plugin): [explicit-function-return-type] support AllowTypedFunctionExpression within AllowHigherOrderFunction #4250
Conversation
Thanks for the PR, @lonyele! 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 on https://opencollective.com/typescript-eslint. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day. |
✔️ Deploy Preview for typescript-eslint ready! 🔨 Explore the source changes: a7365e0 🔍 Inspect the deploy log: https://app.netlify.com/sites/typescript-eslint/deploys/61c06d5ce04fc30007776d1f 😎 Browse the preview: https://deploy-preview-4250--typescript-eslint.netlify.app |
Codecov Report
@@ Coverage Diff @@
## main #4250 +/- ##
==========================================
+ Coverage 93.88% 94.20% +0.32%
==========================================
Files 297 152 -145
Lines 11179 8111 -3068
Branches 3246 2595 -651
==========================================
- Hits 10495 7641 -2854
+ Misses 416 266 -150
+ Partials 268 204 -64
Flags with carried forward coverage won't be shown. Click here to find out 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.
Looks good to me, thanks!
I'm a little shaky on this rule in particular so I'll defer to another maintainer on full approval.
if (ancestor.returnType) { | ||
return true; | ||
} | ||
// assume |
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.
assume... what?
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.
this was copy pasted from the old code.
idk what it was supposed to be (I probably wrote it lol)
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 it was just a mistake to remove it. Comments on this function I found are already giving some good "whys" and leaving it may confuse others(actually including me when I first saw it :D) thus I removed it.
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 see you've added tests for
allowTypedFunctionExpressions: true,
allowHigherOrderFunctions: true,
Could you also ensure that there are suitable tests for all of these option combos as well?
allowTypedFunctionExpressions: false,
allowHigherOrderFunctions: true,
allowTypedFunctionExpressions: true,
allowHigherOrderFunctions: false,
allowTypedFunctionExpressions: false,
allowHigherOrderFunctions: false,
Just want to ensure that there aren't any regressions accidentally introduced by a change in logic in this very complicated rule!
Yeah, you were dead right. There was a flaw. I somehow touched this same code before when figuring out how to approach this problem and missed including it in my final approach. Now it looks much better. |
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 building this!
…dFunctionExpression within AllowHigherOrderFunction (typescript-eslint#4250) * refactor: move function to be used more widely * feat: find if the ancestor(top level) is typed * test: add more test cases * fix: lint fail on test case * fix: make working with option combos * chore: remove unnecessary comment
PR Checklist
Fixes [explicit-function-return-type] Return type needed after injection by higher order functions despite options #758
Fixes [explicit-function-return-type] allowTypedFunctionExpressions should support return values and default parameters #682
Fixes [explicit-function-return-type] option to ignore return value on functions with return type signatures #2839
Overview
Before
It errors when the last return type of higher order function is not typed even though
AllowTypedFunctionExpression
is trueAfter
If the ancestor(top level) is typed, ignore the last return type of higher order function since It is explicitly typed at the beginning.
Context
It seems like this functionality has already been used at
explicit-boundary-module-type
which looks to be usable at this rule finding if the top level is already typed. I wanted to useancestorHasReturnType
somewhere inside ofisTypedFunctionExpression
orcheckFunctionExpressionReturnType
, but these are also used atexplicit-boundary-module-type
liek this thus I made this solution. Hope I got near to the solution.Big shame that I didn't finish other PR's that you've already commented... I haven't thought about me away from programming for somehow. From now on, I plan to finish some unfinished jobs(#894, #901) and I thought this functionality needs to be done first