Skip to content

no-prototype-builtins

Reports a call of hasOwnProperty, isPrototypeOf or propertyIsEnumerable made on an object itself: obj.hasOwnProperty(k), obj?.hasOwnProperty(k) and obj['hasOwnProperty'](k). Reading the property without a call, and Object.prototype.hasOwnProperty.call(obj, k), are not reported.

The method comes from the prototype chain, and the object may not have it. Object.create(null) objects have no hasOwnProperty, so the call throws, and data from outside (a parsed JSON with a key "hasOwnProperty") can replace the method with its own value.

To fix, call it from the prototype: Object.prototype.hasOwnProperty.call(obj, k), or use Object.hasOwn(obj, k) where the target supports it.

Reported
...
a.hasOwnProperty("b"); a?.isPrototypeOf(b); a["propertyIsEnumerable"]("c"); Object.prototype.hasOwnProperty.call(a, "b"); a.hasOwnProperty;
...
js:
lint:
rules:
no-prototype-builtins: warn # off (default), warn, error

Enabled by the presets: js/eslint-recommended, js/biome-recommended.

Suppress one line with sudsy-disable-next-line no-prototype-builtins in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
eslint no-prototype-builtins full