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): [return-await] clean up in-try-catch detection and make autofixes safe #9031
base: main
Are you sure you want to change the base?
fix(eslint-plugin): [return-await] clean up in-try-catch detection and make autofixes safe #9031
Conversation
…ake autofixes safe
Thanks for the PR, @kirkwaiblinger! 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. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
}, | ||
], | ||
}, | ||
{ | ||
code: ` | ||
async function bar() {} |
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 just tests 3 totally separable errors, so I broke it up into 3 separate tests.
}); | ||
} else if (!isAwait && isInTryCatch) { | ||
if (inCatch(expression) && !hasFinallyBlock(expression)) { | ||
return; |
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.
@@ -222,13 +250,29 @@ export default createRule({ | |||
return; | |||
} | |||
|
|||
const affectsErrorHandling = affectsExplicitErrorHandling(expression); |
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.
PR Checklist
Overview
These 3 bugs are closely related, and the code is largely interdependent, so I figured it would be easiest to group into 1 PR. We can do sequential PRs instead if need be.
The diff looks like there's a lot going on, but I think it's actually not so bad, if we go step-by-step. (Then again, this is all swimming around in my head so it probably makes more sense to me than to a reader):
try
,catch
, orfinally
, we now just find the nearesttry-catch-finally
statement and work from there, rather than checking each ancestor separately. (bye-byeinTry
,inCatch
,hasFinallyBlock
,isReturnPromiseInFinally
, all replaced byfindEnclosingTryStatement
)in-try-catch
into a helper function that now also checks nestedtry-catch-finally
statements, rather than just the closest one found (affectsExplicitErrorHandling
), fixing Bug: [return-await] should handle nested try-catch-finally blocks with "in-try-catch" option #8907.in-try-catch
thanks to the above helper, fixing Bug: [return-await] awaited promise allowed in terminal catch block #8663.in-try-catch
option as well, as the condition for whether to autofix or suggest a fix, fixing Bug: [return-await] unsafe autofixes in error handling code #8661.try-catch-finally
s (Bug: [return-await] should handle nested try-catch-finally blocks with "in-try-catch" option #8907)