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: boolean
hasKey
=
const object: Record<string, unknown>
object
.
Object.hasOwnProperty(v: PropertyKey): boolean

Determines whether an object has a property with the specified name.

@paramv A property name.

hasOwnProperty
("key");
const
const isPrototypeOf: boolean
isPrototypeOf
=
const object: Record<string, unknown>
object
.
Object.isPrototypeOf(v: Object): boolean

Determines whether an object exists in another object's prototype chain.

@paramv Another object whose prototype chain is to be checked.

isPrototypeOf
(
const other: Record<string, unknown>
other
);
const
const isEnumerable: boolean
isEnumerable
=
const object: Record<string, unknown>
object
.
Object.propertyIsEnumerable(v: PropertyKey): boolean

Determines whether a specified property is enumerable.

@paramv A property name.

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.