Skip to content

Enhancement: [return-await] Option for unopinionated "in-try-catch" #9030

Closed
@kirkwaiblinger

Description

@kirkwaiblinger

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/return-await

Description

The current in-try-catch option handles two separate concerns

  • Correctness - requiring await where it impacts control flow (due to try-catch-finally)
  • Stylistic - forbidding await elsewhere

I would propose for there to be a rule option that handles only the correctness portion. That is to say, it should enforce await wherever in-try-catch currently does, but not report where in-try-catch forbids await.

Fail

// same as in-try-catch
async function f() {
  try {
    return returnsPromise();
  } catch { }
}

Pass

async function f() {
   return returnsPromise();
}

async function f() {
   return await returnsPromise();
}

// same as in-try-catch
async function f() {
  try {
    return await returnsPromise();
  } catch { }
}

Additional Info

I think this would be valuable in order to be able to recommend a less disruptive version of the rule in a preset, see #8667

Metadata

Metadata

Labels

enhancement: plugin rule optionNew rule option for an existing eslint-plugin rulelocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-pluginteam assignedA member of the typescript-eslint team should work on this.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions