Skip to content
← Back to rules

unicorn/prefer-spread Style

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

它的作用

强制使用 展开运算符 (...) 代替过时的模式。

为什么这不好?

使用展开运算符更加简洁且易读。

示例

以下是此规则的错误代码示例:

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

以下是此规则的正确代码示例:

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

如何使用

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

版本

此规则于 v0.0.17 中加入。

参考资料