close

no-object-as-default-parameter

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/no-object-as-default-parameter': 'error',
    },
  },
]);

Rule Details

Disallow non-empty object literals as function-parameter defaults. Passing a partial object replaces the entire default object, so individual defaulted properties should usually be expressed with parameter destructuring instead.

Examples of incorrect code for this rule:

function read(options = { cache: true, encoding: "utf8" }) {}

function connect({ secure } = { secure: true }) {}

Examples of correct code for this rule:

function read({ cache = true, encoding = "utf8" } = {}) {}

function read(options = {}) {}

const defaults = { cache: true };
function read(options = defaults) {}

The rule is syntax-based. A TypeScript annotation does not exempt a non-empty object literal default:

function range(
  options: { minimum: number; maximum: number } = {
    minimum: 0,
    maximum: 10,
  },
) {}

Original Documentation