Skip to content

fix(eslint-plugin): [explicit-function-return-type] find ReturnStatement inside of BlockStatement #894

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

Closed

Conversation

lonyele
Copy link
Contributor

@lonyele lonyele commented Aug 22, 2019

@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

@codecov
Copy link

codecov bot commented Aug 22, 2019

Codecov Report

Merging #894 into master will not change coverage.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master     #894   +/-   ##
=======================================
  Coverage   94.13%   94.13%           
=======================================
  Files         115      115           
  Lines        5011     5011           
  Branches     1399     1398    -1     
=======================================
  Hits         4717     4717           
  Misses        166      166           
  Partials      128      128
Impacted Files Coverage Δ
...-plugin/src/rules/explicit-function-return-type.ts 100% <100%> (ø) ⬆️

if (body.type === AST_NODE_TYPES.BlockStatement) {
// Check if ReturnStatement exist among body and use that argument
// for checking whether it is a function expression
body.body.some(statement => {
Copy link
Member

Choose a reason for hiding this comment

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

There's one problem with this code - it'll allow you to have multiple return statements nested in the code, which could have different return types.

ie - the following code will pass:

function foo() {
  if (true) {
    return 1;
  }

  return (): void => {};
}

This is where things get difficult. The best way to approach this is via maintaining state during traversal and then doing checks on the :exit.
Eg https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/src/rules/require-await.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah you are definitely right, I'll make a fix(though I don't have much time right now so it'll be done probably after few weeks...)

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Nov 12, 2019
@bradzacher bradzacher added the stale PRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period label Apr 13, 2020
@bradzacher bradzacher closed this Apr 13, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 14, 2020
@lonyele lonyele deleted the fix/finding-return-statement branch February 12, 2022 10:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awaiting response Issues waiting for a reply from the OP or another party bug Something isn't working stale PRs or Issues that are at risk of being or have been closed due to inactivity for a prolonged period
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[explicit-function-return-type] Have to type every chain of higher order function
2 participants