Skip to content

objectPrototypeBuiltIns

Reports direct calls to Object.prototype methods on object instances.

✅ This rule is included in the ts logical preset.

Objects can have properties that shadow the built-in methods from Object.prototype such as hasOwnProperty, isPrototypeOf, and propertyIsEnumerable. Additionally, objects created with Object.create(null) do not inherit from Object.prototype and will not have these methods. Calling these methods directly on objects can lead to errors or security vulnerabilities.

const hasKey = object.hasOwnProperty("key");
const isPrototypeOf = object.isPrototypeOf(other);
const isEnumerable = object.propertyIsEnumerable("prop");

This rule is not configurable.

If code only uses objects with hardcoded keys and never uses Object.create(null) or allows user-controlled object keys, this rule might not be necessary. Alternately, if your codebase overrides these properties -which is a dangerous legacy pattern most runtimes recommend against- you might not be able to enable this rule.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.