Skip to content
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

lonyele
Copy link
Contributor

@lonyele lonyele commented Dec 5, 2021

PR Checklist

Overview

Before

It errors when the last return type of higher order function is not typed even though AllowTypedFunctionExpression is true

After

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 use ancestorHasReturnType somewhere inside of isTypedFunctionExpression or checkFunctionExpressionReturnType , but these are also used at explicit-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

@typescript-eslint
Copy link
Contributor

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.

@netlify
Copy link

netlify bot commented Dec 5, 2021

✔️ 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

@nx-cloud
Copy link

nx-cloud bot commented Dec 5, 2021

☁️ Nx Cloud Report

CI ran the following commands for commit a7365e0. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 44 targets

Sent with 💌 from NxCloud.

@codecov
Copy link

codecov bot commented Dec 5, 2021

Codecov Report

Merging #4250 (10922cd) into main (bade083) will increase coverage by 0.32%.
The diff coverage is 88.00%.

❗ Current head 10922cd differs from pull request most recent head a7365e0. Consider uploading reports for the commit a7365e0 to get more accurate results

@@            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     
Flag Coverage Δ
unittest 94.20% <88.00%> (+0.32%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...plugin/src/rules/explicit-module-boundary-types.ts 91.04% <ø> (+0.97%) ⬆️
.../eslint-plugin/src/util/explicitReturnTypeUtils.ts 96.42% <84.21%> (-3.58%) ⬇️
...-plugin/src/rules/explicit-function-return-type.ts 100.00% <100.00%> (ø)
packages/scope-manager/src/lib/es6.ts
...ages/scope-manager/src/lib/esnext.asynciterable.ts
packages/scope-manager/src/lib/es2015.symbol.ts
packages/scope-manager/src/scope/BlockScope.ts
packages/scope-manager/src/lib/esnext.weakref.ts
...ackages/scope-manager/src/referencer/Referencer.ts
...ges/scope-manager/src/lib/es2018.asyncgenerator.ts
... and 138 more

@bradzacher bradzacher added the bug Something isn't working label Dec 15, 2021
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assume... what?

Copy link
Member

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)

Copy link
Contributor Author

@lonyele lonyele Dec 20, 2021

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.

Copy link
Member

@bradzacher bradzacher left a 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!

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Dec 20, 2021
@lonyele
Copy link
Contributor Author

lonyele commented Dec 20, 2021

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.

@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Dec 27, 2021
Copy link
Member

@bradzacher bradzacher left a 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!

@bradzacher bradzacher merged commit d053cde into typescript-eslint:main Jan 17, 2022
@lonyele lonyele deleted the feat/allow-typed-func-expression-with-higher-order-func branch January 24, 2022 08:43
lonyele added a commit to lonyele/typescript-eslint that referenced this pull request Feb 12, 2022
…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
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
3 participants