This rule raises an issue when a function parameter has an object literal as its default value.

Why is this an issue?

Using object literals as default parameters creates unexpected behavior when the function is called with partial objects.

When you define a parameter like foo = {a: false, b: true} and then call the function with {a: true}, JavaScript completely replaces the default object instead of merging the properties. This means the b property disappears entirely, which is rarely the intended behavior.

This pattern becomes especially problematic as your code evolves. When you add new properties to the default object, any existing function calls that pass partial objects will lose those new default values. This can introduce subtle bugs that are difficult to track down.

Object destructuring with individual default values provides more predictable behavior. Each property gets its own default value, and JavaScript only overrides the properties you explicitly provide.

What is the potential impact?

This issue can lead to runtime errors when code expects certain properties to exist but they have been inadvertently removed. It can also cause logical errors where missing properties result in incorrect application behavior, making debugging more difficult.

How to fix?

Replace object literal defaults with object destructuring and individual property defaults. This ensures each property has its own default value that won’t be lost when partial objects are passed.

Non-compliant code example

const processOptions = (options = {a: false, b: 123}) => {
  // When called with {a: true}, b becomes undefined
  console.log(options.a, options.b);
}; // Noncompliant

Compliant code example

const processOptions = ({a = false, b = 123} = {}) => {
  // When called with {a: true}, b retains its default value of 123
  console.log(a, b);
};

Documentation