Skip to content
← Back to rules

unicorn/prefer-spread Style

🛠️ An auto-fix is available for this rule for some violations.

What it does ​

Enforces the use of the spread operator (...) over outdated patterns.

Why is this bad? ​

Using the spread operator is more concise and readable.

Examples ​

Examples of incorrect code for this rule:

javascript
const foo = Array.from(set);
const foo = Array.from(new Set([1, 2]));

Examples of correct code for this rule:

javascript
[...set].map(() => {});
Array.from(...argumentsArray);

How to use ​

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "unicorn/prefer-spread": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "unicorn/prefer-spread": "error",
  },
});
bash
oxlint --deny unicorn/prefer-spread

Version ​

This rule was added in v0.0.17.

References ​