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): [return-await] don't error for in-try-catch if the return is in a catch without a finally #2356

Merged
merged 16 commits into from Sep 14, 2020

Conversation

soobing
Copy link
Contributor

@soobing soobing commented Aug 4, 2020

Fixes #2344

Added below two TC, and fixed.

  • if you return a promise within a catch, and there is no finally, then it must not be awaited.
  • if you return a promise within a finally, then it must not be awaited.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @soobing!

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 Aug 4, 2020

Codecov Report

Merging #2356 into master will increase coverage by 0.01%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #2356      +/-   ##
==========================================
+ Coverage   92.81%   92.82%   +0.01%     
==========================================
  Files         290      290              
  Lines        9453     9481      +28     
  Branches     2647     2657      +10     
==========================================
+ Hits         8774     8801      +27     
- Misses        322      323       +1     
  Partials      357      357              
Flag Coverage Δ
#unittest 92.82% <ø> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
packages/eslint-plugin/src/rules/return-await.ts 95.69% <ø> (-0.08%) ⬇️
packages/experimental-utils/src/ts-eslint/Scope.ts 100.00% <0.00%> (ø)
...es/eslint-plugin/src/rules/no-use-before-define.ts 94.36% <0.00%> (ø)
packages/eslint-plugin/src/rules/no-unused-vars.ts 93.06% <0.00%> (+0.21%) ⬆️

@bradzacher
Copy link
Member

So the issue in question isn't that the code was erroring - it's that it shouldn't error.

The code should work in the following way for in-try-catch mode:

  • if you return a promise within a try, then it must be awaited.
  • if you return a promise within a catch, and there is no finally, then it must not be awaited.
  • if you return a promise within a catch, and there is a finally, then it must be awaited.
  • if you return a promise within a finally, then it must not be awaited.

@bradzacher bradzacher added awaiting response Issues waiting for a reply from the OP or another party bug Something isn't working labels Aug 4, 2020
@bradzacher bradzacher changed the title [return-await] Added test including 'throw' in try block fix(eslint-plugin): [return-await] don't error for in-try-catch if the return is in a catch without a finally Aug 4, 2020
@soobing
Copy link
Contributor Author

soobing commented Aug 5, 2020

Aha.. thanks for the kind explanation.
I will try again.

@soobing
Copy link
Contributor Author

soobing commented Aug 19, 2020

@bradzacher
Hi, I tried again. Please review my code 😋.
I also change this PR's description #2356 (comment)

@soobing
Copy link
Contributor Author

soobing commented Aug 25, 2020

@bradzacher hi, could you review again? I don't know How to ask review again so I am mentioning 🦊

@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Aug 25, 2020
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.

The code LGTM.
Thanks for your work!

Could you please update the docs for the in-try-catch option?

Specifically, could you make it very clear how it works, doing something like this will be good.


in-try-catch

Requires that a returned promise must be awaited in try-catch-finally blocks, and disallows it elsewhere. Specifically:

  • if you return a promise within a try, then it must be awaited.
  • if you return a promise within a catch, and there is no finally, then it must not be awaited.
  • if you return a promise within a catch, and there is a finally, then it must be awaited.
  • if you return a promise within a finally, then it must not be awaited.

@bradzacher bradzacher added the awaiting response Issues waiting for a reply from the OP or another party label Sep 6, 2020
@soobing
Copy link
Contributor Author

soobing commented Sep 7, 2020

@bradzacher Thanks for review!
I updated the docs and also added some examples.

@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Sep 8, 2020
@dbalde

This comment has been minimized.

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 for your work

@bradzacher bradzacher merged commit efdd521 into typescript-eslint:master Sep 14, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 15, 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.

[return-await] await should be required in catch block only when it has a finally block
3 participants