Skip to content

Commit

Permalink
fix!: only require awaiting promises returned from inside try/catch…
Browse files Browse the repository at this point in the history
… blocks (#133)

Returning unawaited promises from inside try/catch blocks is usually
a bug as the author more than likely intends the catch part to handle
errors.

The configuration in this PR disallows `await` before `return` unless
it is inside a `try/catch` in which case it is required.

`await` before `return` doesn't cause any harm but I don't think we
can configure the rule any other way.

This is a breaking change but one that is fixable with `npm run lint -- --fix`

Fixes: #130

BREAKING CHANGE: `await` is not allowed before `return` unless it is inside a `try/catch` in which case it is required

Co-authored-by: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com>
  • Loading branch information
achingbrain and SgtPooki committed Apr 5, 2023
1 parent fb5e5b6 commit a6e4a7b
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ module.exports = {
'@typescript-eslint/no-this-alias': 'off', // allow 'const self = this'
'@typescript-eslint/await-thenable': 'error', // disallows awaiting a value that is not a "Thenable"
'@typescript-eslint/restrict-template-expressions': 'off', // allow values with `any` type in template literals
'no-return-await': 'off', // disable this rule to use @typescript-eslint/return-await instead
'@typescript-eslint/return-await': ['error', 'in-try-catch'], // require awaiting thenables returned from try/catch
'jsdoc/require-param': 'off', // do not require jsdoc for params
'jsdoc/require-param-type': 'off' // allow compiler to derive param type
}
Expand Down

0 comments on commit a6e4a7b

Please sign in to comment.