Skip to content

Enhancement: [return-await] change rule option to object #9546

Closed as not planned
@phaux

Description

@phaux

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

From #9030 (comment)

Another approach here might be restructuring the options as

"affectsControlFlow": "always" | "never" | "dontCare",  
"doesNotAffectControlFlow": "always" | "never" | "dontCare"  

but that seems needlessly breaking 🤷

and #9364 (comment)

Maybe change the option so that instead of a string it's an object:

{
  default: "always" | "never" | "ignore", 
  inTryCatch?: "always" | "never" | "ignore", // undefined means "same as default" 
}

And make the string options aliases for backward compatibility:

  • "always" - { default: "always" }
  • "in-try-catch" - { default: "never", inTryCatch: "always" }
  • "never" - { default: "never" }

The new option would be { default: "ignore", inTryCatch: "always" }

In the future, there could be more conditions added. For example, someone might want to use "always" but make an exception for single-line arrow functions to make them less noisy:

/* eslint @typescript-eslint/promise-function-async: "error" */
/* eslint @typescript-eslint/return-await: ["error", { default: "always", inArrowFunction: "ignore" }] */

promise.then(async (v) => doSomethingAsync(v)) // allowed

Fail

// no changes

Pass

// no changes

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    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-pluginwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions