2 * @fileoverview Rule to disallow use of Object.prototype builtins on objects
3 * @author Andrew Levine
7 //------------------------------------------------------------------------------
9 //------------------------------------------------------------------------------
16 description: "disallow calling some `Object.prototype` methods directly on objects",
17 category: "Possible Errors",
19 url: "https://eslint.org/docs/rules/no-prototype-builtins"
26 const DISALLOWED_PROPS = [
29 "propertyIsEnumerable"
33 * Reports if a disallowed property is used in a CallExpression
34 * @param {ASTNode} node The CallExpression node.
37 function disallowBuiltIns(node) {
38 if (node.callee.type !== "MemberExpression" || node.callee.computed) {
41 const propName = node.callee.property.name;
43 if (DISALLOWED_PROPS.indexOf(propName) > -1) {
45 message: "Do not access Object.prototype method '{{prop}}' from target object.",
46 loc: node.callee.property.loc.start,
47 data: { prop: propName },
54 CallExpression: disallowBuiltIns