no-prototype-builtins
What it does
Section titled “What it does”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.
Why it matters
Section titled “Why it matters”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.
Example
Section titled “Example”...a.hasOwnProperty("b"); a?.isPrototypeOf(b); a["propertyIsEnumerable"]("c"); Object.prototype.hasOwnProperty.call(a, "b"); a.hasOwnProperty;...Configuration
Section titled “Configuration”js: lint: rules: no-prototype-builtins: warn # off (default), warn, errorEnabled 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.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| eslint | no-prototype-builtins |
full |