Saltearse al contenido

useObjectSpread

Esta página aún no está disponible en tu idioma.

Prefer object spread over Object.assign() when constructing new objects.

Object spread syntax is more concise, more readable, and performs better than Object.assign() when creating a new object from existing objects. It also has better TypeScript integration.

Object.assign({}, foo);
code-block.js:1:1 lint/nursery/useObjectSpread  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Object spread syntax is more concise, readable, and performs better than Object.assign.

> 1 │ Object.assign({}, foo);
^^^^^^^^^^^^^
2 │

Safe fix: Replace Object.assign({…}, <object>) with { …<object> }.

1 - Object.assign({},·foo);
1+ ({...foo,});
2 2

Object.assign({}, { foo: 'bar' });
code-block.js:1:1 lint/nursery/useObjectSpread  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Object spread syntax is more concise, readable, and performs better than Object.assign.

> 1 │ Object.assign({}, { foo: ‘bar’ });
^^^^^^^^^^^^^
2 │

Safe fix: Replace Object.assign({…}, <object>) with { …<object> }.

1 - Object.assign({},·{·foo:·bar·});
1+ ({foo:·bar·,});
2 2

Object.assign({ foo: 'bar' }, baz);
code-block.js:1:1 lint/nursery/useObjectSpread  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Object spread syntax is more concise, readable, and performs better than Object.assign.

> 1 │ Object.assign({ foo: ‘bar’ }, baz);
^^^^^^^^^^^^^
2 │

Safe fix: Replace Object.assign({…}, <object>) with { …<object> }.

1 - Object.assign({·foo:·bar·},·baz);
1+ ({foo:·bar·,...baz,});
2 2

Object.assign({}, baz, { foo: 'bar' });
code-block.js:1:1 lint/nursery/useObjectSpread  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Object spread syntax is more concise, readable, and performs better than Object.assign.

> 1 │ Object.assign({}, baz, { foo: ‘bar’ });
^^^^^^^^^^^^^
2 │

Safe fix: Replace Object.assign({…}, <object>) with { …<object> }.

1 - Object.assign({},·baz,·{·foo:·bar·});
1+ ({...baz,foo:·bar·,});
2 2

({ ...foo });
({ ...baz, foo: 'bar' });

Modifying an existing object is allowed:

Object.assign(foo, { bar: baz });
biome.json
{
"linter": {
"rules": {
"nursery": {
"useObjectSpread": "error"
}
}
}
}