Skip to content

Latest commit

Β 

History

History
40 lines (29 loc) Β· 1.07 KB

File metadata and controls

40 lines (29 loc) Β· 1.07 KB

no-object-as-default-parameter

πŸ“ 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) => {};