Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enhancement: [no-misused-promises] should include checks around synchronous using statements and Symbol.dispose. #10357

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

Open
4 tasks done
kirkwaiblinger opened this issue Nov 18, 2024 · 0 comments
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin

Comments

@kirkwaiblinger
Copy link
Member

kirkwaiblinger commented Nov 18, 2024

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/no-misused-promises/

Description

I would like the rule to add a few checks for misused promises involved in explicit resource management code. This is split out from #10208 (comment)

Fail

// rule does not inspect variable for misused promise-returning functions
const a = {
    async [Symbol.dispose]() {}
} 
const b: Disposable = a;
//                    ~ <-- expected report here.


// `using` statement without explicit type
using c = {
    async [Symbol.dispose]() {}
//  ~~~~~~~~~~~~~~~~~~~~~~ <-- expected report here.
};

// combination of both of the above
const d = {
    async [Symbol.dispose]() {}
} 
using e = d;
//        ~ <-- expected report here.

Pass

// just a sync disposable
using a = {
    [Symbol.dispose]() {}
}

// proper use of await using (note `Symbol.asyncDispose`)
await using b = {
    async [Symbol.asyncDispose]() {}
}

Additional Info

Note that the upcoming strict-void-return aims to be a superset of no-misused-promises, so perhaps this check will make sense to add there also, see #9707

@kirkwaiblinger kirkwaiblinger added package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for team members to take a look enhancement: plugin rule option New rule option for an existing eslint-plugin rule labels Nov 18, 2024
@kirkwaiblinger kirkwaiblinger changed the title Enhancement: [no-misused-promises] should include checks around synchronous using statements. Enhancement: [no-misused-promises] should include checks around synchronous using statements and Symbol.dispose. Nov 19, 2024
@bradzacher bradzacher added accepting prs Go ahead, send a pull request that resolves this issue and removed triage Waiting for team members to take a look labels Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting prs Go ahead, send a pull request that resolves this issue enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin
Projects
None yet
Development

No branches or pull requests

2 participants