close

catch-or-return

Configuration

PresetConfigured Value
✅ promisePlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, promisePlugin } from '@rslint/core';

export default defineConfig([
  promisePlugin.configs.recommended,
  {
    rules: {
      'promise/catch-or-return': 'error',
    },
  },
]);

Enforce the use of catch() on un-returned promises.

Rule Details

A promise that is used as a statement — rather than returned from a function — must be terminated with a rejection handler. Without one, rejected promises produce unhandled-rejection errors that are easy to miss. This rule enforces that every such promise chain ends with .catch() (or a configured alternative), so the caller cannot silently swallow errors.

Examples of incorrect code for this rule:

frank().then(go)

Promise.resolve(frank)

function callPromise(promise, cb) {
  promise.then(cb)
}

Examples of correct code for this rule:

frank().then(go).catch(doIt)

function a() {
  return frank().then(go)
}

cy.get('.myClass').then(go)

Options

allowThen

Pass { "allowThen": true } to accept a two-argument .then(onFulfilled, onRejected) call as a valid termination in place of .catch().

{ "promise/catch-or-return": ["error", { "allowThen": true }] }
frank().then(a, b)
frank().then(go).then(zam, doIt)

allowThenStrict

Like allowThen, but the first argument to .then() must be null so the handler is exclusively for rejections.

{ "promise/catch-or-return": ["error", { "allowThenStrict": true }] }
frank().then(go).then(null, doIt)

allowFinally

Pass { "allowFinally": true } to allow a .finally() call after a valid termination.

{ "promise/catch-or-return": ["error", { "allowFinally": true }] }
frank().then(go).catch(doIt).finally(fn)

terminationMethod

Replace catch with an alternative method name, or provide an array of accepted names.

{ "promise/catch-or-return": ["error", { "terminationMethod": "done" }] }
frank().then(go).done()
{ "promise/catch-or-return": ["error", { "terminationMethod": ["catch", "asCallback", "finally"] }] }
frank().then(go).catch(doIt)
frank().then(go).asCallback(fn)
frank().then(go).finally(fn)

Differences from ESLint

None known.

Original Documentation