-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
fix(eslint-plugin): [explicit-function-return-type] find ReturnStatement inside of BlockStatement #894
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 |
Codecov Report
@@ 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
|
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 => { |
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'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
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.
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...)
#928