close

prefer-optional-catch-binding

Unreleased

Configuration

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

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/prefer-optional-catch-binding': 'error',
    },
  },
]);

Rule Details

Omit unused catch bindings. A reference from a nested scope counts as a use, as do writes to the caught variable.

Unused destructuring bindings are also checked. Comments surrounding the binding are preserved; a binding containing comments is reported without an automatic fix. Binding defaults are not removed.

Examples of incorrect code:

try { work(); } catch (error) {}

Examples of correct code:

try { work(); } catch {}

Options

This rule has no options. It is enabled at error severity in unicornPlugin.configs.recommended.

Original Documentation