Skip to content
← Back to rules

eslint/no-proto Restriction

🚧 An auto-fix is planned for this rule, but not implemented at this time.

它的作用

禁止使用 __proto__ 属性。

为什么这不好?

__proto__ 属性自 ECMAScript 3.1 起已被弃用, 不应在新代码中使用。请改用 Object.getPrototypeOfObject.setPrototypeOf

有关更多信息,请参阅 MDN 文档

示例

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

javascript
var a = obj.__proto__;

var a = obj["__proto__"];

obj.__proto__ = b;

obj["__proto__"] = b;

如何使用

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

json
{
  "rules": {
    "no-proto": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "no-proto": "error",
  },
});
bash
oxlint --deny no-proto

版本

此规则于 v0.2.14 中添加。

参考资料