close

no-prototype-builtins

Configuration

PresetConfigured Value
✅ js.configs.recommended"error"
rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'no-prototype-builtins': 'error',
    },
  },
]);

Rule Details

This rule disallows calling Object.prototype methods directly on object instances. In particular, it flags calls to hasOwnProperty, isPrototypeOf, and propertyIsEnumerable invoked as members of a target object. Such calls can break on objects created with Object.create(null) (which do not inherit from Object.prototype) or on objects that define shadowing properties with the same names.

Examples of incorrect code for this rule:

var hasBarProperty = foo.hasOwnProperty('bar');
var isPrototypeOfBar = foo.isPrototypeOf(bar);
var barIsEnumerable = foo.propertyIsEnumerable('bar');

Examples of correct code for this rule:

var hasBarProperty = Object.prototype.hasOwnProperty.call(foo, 'bar');
var isPrototypeOfBar = Object.prototype.isPrototypeOf.call(foo, bar);
var barIsEnumerable = {}.propertyIsEnumerable.call(foo, 'bar');

Options

This rule has no options.

Original Documentation