Skip to content

Change @typescript-eslint/return-await to in-try-catch? #130

@achingbrain

Description

@achingbrain

The default setting for @typescript-eslint/return-await is ['error', 'always'].

This disallows code like:

async function myAsyncFunction () {
  return someOtherAsyncFunction()
}

instead demanding:

async function myAsyncFunction () {
  return await someOtherAsyncFunction()
}

It doesn't seem to make any difference to the stack traces and we have other rules that catch floating promises so I'm not sure what value it adds, and it occasionally raises some eyebrows.

The rule comes from standard but it's not even clear that the standard maintainers are for this version of the rule.

It does have another mode which is "in-try-catch", this disallows this sort of thing, demanding and await before the return, which seems a bit more useful, as it looks like the author might think any rejection would be caught which is not the case:

try {
  return someOtherAsyncFunction()
} catch (err) {
  // phew!
}

Shall we switch this rule to "in-try-catch"?

Cc @whizzzkid @SgtPooki

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions