Skip to content
← Back to rules

oxc/no-rest-spread-properties Restriction

作用

禁止 对象 Rest/Spread 属性

为什么这不好?

对象 rest/spread 属性是相对较新的 JavaScript 特性,可能 并非所有目标环境都支持。如果你需要支持不支持这些特性的较旧 浏览器或 JavaScript 引擎,使用它们 可能会导致运行时错误。此规则通过阻止使用这些现代语法特性, 帮助保持与较旧环境的兼容性。

示例

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

javascript
let { x, ...y } = z;
let z = { x, ...y };

配置

此规则接受一个包含以下属性的配置对象:

objectRestMessage

type: string

default: ""

当找到对象 rest 属性时显示的消息。

objectSpreadMessage

type: string

default: ""

当找到对象 spread 属性时显示的消息。

如何使用

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

json
{
  "rules": {
    "oxc/no-rest-spread-properties": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "oxc/no-rest-spread-properties": "error",
  },
});
bash
oxlint --deny oxc/no-rest-spread-properties

版本

此规则在 v0.4.2 中添加。

参考