no-proto

Disallow the __proto__ property

object.__proto__ is a getter and setter that objects inherit from Object.prototype. An object made with Object.create(null) doesn't have it, so on that object __proto__ is an ordinary property and reading it returns undefined. Object.getPrototypeOf() and Object.setPrototypeOf() work on every object.

Using __proto__ as a key in an object literal sets the new object's prototype, and that isn't reported.

Configure#

Off by default. To turn it on:

bunfig.toml
[lint.rules]
"no-proto" = "error" # or "warn"

Examples#

example.js2 problems
const parent = user.__proto__;
user["__proto__"] = admin;
example.jsNo problems
const parent = Object.getPrototypeOf(user);
Object.setPrototypeOf(user, admin);

const guest = { __proto__: user, name: "guest" };