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-module-boundary-types] don't check returned functions if parent function has return type #2084

Merged

Conversation

ifiokjr
Copy link
Contributor

@ifiokjr ifiokjr commented May 24, 2020

Description

Version 3.0.0 of the plugin enabled explicit-module-boundary-types by default. Unfortunately it doesn't currently handle the case where the parent function has a type signature. The following correct code produces an error.

export const foo = (a: string): (n: number) => string => {
  return (n) => String(n)
}

This fixes the problem by checking the parent nodes of exported declarations to see if they are already typed. If they are typed it doesn't show the error for child functions.

Fixes #1845

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @ifiokjr!

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.

@codecov
Copy link

codecov bot commented May 24, 2020

Codecov Report

Merging #2084 into master will increase coverage by 0.00%.
The diff coverage is 92.85%.

@@           Coverage Diff           @@
##           master    #2084   +/-   ##
=======================================
  Coverage   93.42%   93.42%           
=======================================
  Files         171      171           
  Lines        7755     7774   +19     
  Branches     2215     2222    +7     
=======================================
+ Hits         7245     7263   +18     
  Misses        244      244           
- Partials      266      267    +1     
Flag Coverage Δ
#unittest 93.42% <92.85%> (+<0.01%) ⬆️
Impacted Files Coverage Δ
...plugin/src/rules/explicit-module-boundary-types.ts 82.75% <50.00%> (+0.14%) ⬆️
.../eslint-plugin/src/util/explicitReturnTypeUtils.ts 98.85% <96.15%> (-1.15%) ⬇️

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.

Mostly LGTM - thanks!

One comment that needs addressing.

packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts Outdated Show resolved Hide resolved
@bradzacher bradzacher added the bug Something isn't working label May 25, 2020
@bradzacher bradzacher changed the title fix(eslint-plugin): explicit-module-boundary-types fix(eslint-plugin): [explicit-module-boundary-types] don't check returned functions if parent function has return type May 25, 2020
@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label May 25, 2020
@ifiokjr ifiokjr force-pushed the fix/explicit-module-boundary-types branch 2 times, most recently from f06e1e0 to 5cac715 Compare May 25, 2020 20:57
@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label May 26, 2020
@ifiokjr ifiokjr force-pushed the fix/explicit-module-boundary-types branch 2 times, most recently from ce93945 to 9b37ff0 Compare May 26, 2020 07:44
@ifiokjr
Copy link
Contributor Author

ifiokjr commented May 26, 2020

I've just pushed again to:

  • Exit early when the type of the ancestor of the node being checked is not a return statement.
  • Immediately return the value from FunctionExpression ancestor checks.
  • Remove comments from the test source code.
  • Add one more deeply nested test case.

Was complaining about inner function expressions.

Fixes typescript-eslint#1845
Exit early when the type of the ancestor of the node being checked is
not a return statement.
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.

LGTM - thanks!

@bradzacher bradzacher merged commit d7d4eeb into typescript-eslint:master May 30, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 30, 2020
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
Development

Successfully merging this pull request may close these issues.

[explicit-module-boundary-types] Complains about inner function expressions
2 participants