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

@typescript-eslint typescript-eslint bot commented Aug 4, 2020

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 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

@bradzacher bradzacher commented Aug 4, 2020

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 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 soobing commented Aug 5, 2020

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

@soobing
Copy link
Contributor Author

@soobing 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 soobing commented Aug 25, 2020

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

Copy link
Member

@bradzacher bradzacher left a comment

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.
@soobing
Copy link
Contributor Author

@soobing soobing commented Sep 7, 2020

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

@dbalde

This comment was marked as spam.

Copy link
Member

@bradzacher bradzacher left a comment

LGTM - thanks for your work

@bradzacher bradzacher merged commit efdd521 into typescript-eslint:master Sep 14, 2020
10 checks passed
10 checks passed
Typecheck
Details
Unit tests Unit tests
Details
Code style and lint
Details
Run integration tests on primary Node.js version
Details
Run unit tests on other Node.js versions (10.x)
Details
Run unit tests on other Node.js versions (14.x)
Details
Publish the latest code as a canary version
Details
Semantic Pull Request ready to be squashed
Details
codecov/patch Codecov Report
Details
codecov/project Codecov Report
Details
phaux added a commit to phaux/typescript-eslint that referenced this pull request Sep 28, 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.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

3 participants