2 * @fileoverview Rule to disallow use of Object.prototype builtins on objects
3 * @author Andrew Levine
7 //------------------------------------------------------------------------------
9 //------------------------------------------------------------------------------
11 const astUtils = require("./utils/ast-utils");
13 //------------------------------------------------------------------------------
15 //------------------------------------------------------------------------------
22 description: "disallow calling some `Object.prototype` methods directly on objects",
23 category: "Possible Errors",
25 url: "https://eslint.org/docs/rules/no-prototype-builtins"
31 prototypeBuildIn: "Do not access Object.prototype method '{{prop}}' from target object."
36 const DISALLOWED_PROPS = [
39 "propertyIsEnumerable"
43 * Reports if a disallowed property is used in a CallExpression
44 * @param {ASTNode} node The CallExpression node.
47 function disallowBuiltIns(node) {
49 const callee = astUtils.skipChainExpression(node.callee);
51 if (callee.type !== "MemberExpression") {
55 const propName = astUtils.getStaticPropertyName(callee);
57 if (propName !== null && DISALLOWED_PROPS.indexOf(propName) > -1) {
59 messageId: "prototypeBuildIn",
60 loc: callee.property.loc,
61 data: { prop: propName },
68 CallExpression: disallowBuiltIns