Skip to content

objectPrototypeBuiltIns

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

✅ This rule is included in the ts logical and logicalStrict presets.

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
const hasKey: any
hasKey
=
const object: any
object
.
any
hasOwnProperty
("key");
const
const isPrototypeOf: any
isPrototypeOf
=
const object: any
object
.
any
isPrototypeOf
(
const other: any
other
);
const
const isEnumerable: any
isEnumerable
=
const object: any
object
.
any
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 ❤️‍🔥 around the world by the Flint team and contributors.