unicorn/prefer-spread
eslint-plugin-unicorn
Safe autofix
eslint.config.js
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-spread": "error",
},
},
];Prefer the spread operator over Array.from(…), Array#concat(…), Array#{slice,toSpliced}(), and trivial for…of copies.
Array.from(set).map(element => foo(element));const array = array1.concat(array2);const copy = array.slice();[...set].map(element => foo(element));const array = [...array1, ...array2];const copy = [...array];Examples from the ESLint documentation.
unicorn/prefer-spread
eslint-plugin-unicorn
import unicorn from "eslint-plugin-unicorn";
export default [
{
plugins: { unicorn },
rules: {
"unicorn/prefer-spread": "error",
},
},
];unicorn/prefer-spread
unicorn plugin · style
{
"rules": {
"unicorn/prefer-spread": "error"
}
}Biome does not have this rule.
Require spread operators instead of .apply()
Prefer export…from when re-exporting.
Enforce consistent brace style for case clauses.
Disallow confusing uses of Array#with().
Enforce consistent break/return/continue/throw position in case clauses.
Disallow member access from await expression.