Sha256: e61f20d8d99afac20620a8cb11e5dcf1709fed20a0dfeb66b1afad6aa7c6e297

Contents?: true

Size: 1.61 KB

Versions: 43

Compression:

Stored size: 1.61 KB

Contents

/**
 * @fileoverview Rule to disallow use of Object.prototype builtins on objects
 * @author Andrew Levine
 */
"use strict";

//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------

module.exports = {
    meta: {
        docs: {
            description: "disallow calling some `Object.prototype` methods directly on objects",
            category: "Possible Errors",
            recommended: false,
            url: "https://eslint.org/docs/rules/no-prototype-builtins"
        },

        schema: []
    },

    create(context) {
        const DISALLOWED_PROPS = [
            "hasOwnProperty",
            "isPrototypeOf",
            "propertyIsEnumerable"
        ];

        /**
         * Reports if a disallowed property is used in a CallExpression
         * @param {ASTNode} node The CallExpression node.
         * @returns {void}
         */
        function disallowBuiltIns(node) {
            if (node.callee.type !== "MemberExpression" || node.callee.computed) {
                return;
            }
            const propName = node.callee.property.name;

            if (DISALLOWED_PROPS.indexOf(propName) > -1) {
                context.report({
                    message: "Do not access Object.prototype method '{{prop}}' from target object.",
                    loc: node.callee.property.loc.start,
                    data: { prop: propName },
                    node
                });
            }
        }

        return {
            CallExpression: disallowBuiltIns
        };
    }
};

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
govuk_publishing_components-18.0.0 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.21.0 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.20.0 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.19.1 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.19.0 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.18.0 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.17.0 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.16.0 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.15.0 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.14.0 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.13.0 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.12.2 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.12.1 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.12.0 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.11.0 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.10.0 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.9.0 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.8.0 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.7.0 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js
govuk_publishing_components-17.6.1 node_modules/standard/node_modules/eslint/lib/rules/no-prototype-builtins.js