no-object-as-default-parameter

March 27, 2026 ยท View on GitHub

๐Ÿ“ Disallow the use of objects as default parameters.

๐Ÿ’ผ This rule is enabled in the following configs: โœ… recommended, โ˜‘๏ธ unopinionated.

Default parameters should not be passed to a function through an object literal. The foo = {a: false} parameter works fine if only used with one option. As soon as additional options are added, you risk replacing the whole foo = {a: false, b: true} object when passing only one option: {a: true}. For this reason, object destructuring should be used instead.

Examples

// โŒ
function foo({a} = {a: false}) {}

// โœ…
function foo(options) {
	const {a} = {a: false, ...options};
}
// โŒ
const abc = (foo = {a: false, b: 123}) => {};

// โœ…
const foo = ({a = false, b = 123}) => {};
// โœ…
const abc = (foo = {}) => {};
// โœ…
const abc = (foo = false) => {};