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

feat(eslint-plugin): [promise-function-async] check for promises in implicit return types #6330

Conversation

ericbf
Copy link
Contributor

@ericbf ericbf commented Jan 12, 2023

When we return a union containing a promise from a function implicitly, it's often a mistake. This commit makes it so if the return type is explicit, any Promise in the return type (whether it's part of a union or not) will flag the function. If it is intentional, make the return type explicit.

Fixes #6329

PR Checklist

Overview

This implements the heuristic that @bradzacher suggested. If the return type is explicit, it allows unions with non-Promise types, but if it is implicit, it flags those.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @ericbf!

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.

@nx-cloud
Copy link

nx-cloud bot commented Jan 12, 2023

☁️ Nx Cloud Report

CI is running/has finished running commands for commit be9531d. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 47 targets

Sent with 💌 from NxCloud.

@netlify
Copy link

netlify bot commented Jan 12, 2023

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit be9531d
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/63e6abc43fc01b0008da403d
😎 Deploy Preview https://deploy-preview-6330--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@codecov
Copy link

codecov bot commented Jan 12, 2023

Codecov Report

Merging #6330 (be9531d) into main (bbfed02) will decrease coverage by 0.03%.
The diff coverage is 0.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6330      +/-   ##
==========================================
- Coverage   90.61%   90.59%   -0.03%     
==========================================
  Files         372      372              
  Lines       12709    12712       +3     
  Branches     3739     3743       +4     
==========================================
  Hits        11516    11516              
- Misses        853      856       +3     
  Partials      340      340              
Flag Coverage Δ
unittest 90.59% <0.00%> (-0.03%) ⬇️

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

Impacted Files Coverage Δ
.../eslint-plugin/src/rules/promise-function-async.ts 98.07% <ø> (ø)
packages/type-utils/src/containsAllTypesByName.ts 0.00% <0.00%> (ø)

@ericbf ericbf changed the title [promise-function-async] Only allow unions in explicit return types feat(eslint-plugin): check for promises in implicit return types Jan 12, 2023
@ericbf ericbf force-pushed the promise-function-async-allow-union-in-explicit-types-only branch from 3527630 to c65b905 Compare January 12, 2023 22:19
@bradzacher bradzacher changed the title feat(eslint-plugin): check for promises in implicit return types feat(eslint-plugin): [promise-function-async] check for promises in implicit return types Feb 10, 2023
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.

overall the changes look good - but we'll need to ensure we're not breaking the API

@bradzacher bradzacher added enhancement New feature or request awaiting response Issues waiting for a reply from the OP or another party labels Feb 10, 2023
When we return a union containing a promise from a function
implicitly, it's often a mistake. This commit makes it so if the
return type is explicit, any `Promise` in the return type (whether
it's part of a union or not) will flag the function. If it is
intentional, make the return type explicit.

Fixes typescript-eslint#6329
@ericbf ericbf force-pushed the promise-function-async-allow-union-in-explicit-types-only branch from c30bf71 to be9531d Compare February 10, 2023 20:40
@bradzacher bradzacher removed the awaiting response Issues waiting for a reply from the OP or another party label Feb 13, 2023
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.

thanks for this!

@bradzacher bradzacher added this pull request to the merge queue Feb 20, 2023
Merged via the queue into typescript-eslint:main with commit de1e5ce Feb 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enhancement: [promise-function-async] flag non-async functions returning unions with non-Promise types
2 participants