HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux ip-172-31-4-197 6.8.0-1036-aws #38~22.04.1-Ubuntu SMP Fri Aug 22 15:44:33 UTC 2025 x86_64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/api-storage/node_modules/eslint/lib/rules/no-obj-calls.js
/**
 * @fileoverview Rule to flag use of an object property of the global object (Math and JSON) as a function
 * @author James Allardice
 */

"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

const {
	CALL,
	CONSTRUCT,
	ReferenceTracker,
} = require("@eslint-community/eslint-utils");
const getPropertyName = require("./utils/ast-utils").getStaticPropertyName;

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------

const nonCallableGlobals = ["Atomics", "JSON", "Math", "Reflect", "Intl"];

/**
 * Returns the name of the node to report
 * @param {ASTNode} node A node to report
 * @returns {string} name to report
 */
function getReportNodeName(node) {
	if (node.type === "ChainExpression") {
		return getReportNodeName(node.expression);
	}
	if (node.type === "MemberExpression") {
		return getPropertyName(node);
	}
	return node.name;
}

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

/** @type {import('../types').Rule.RuleModule} */
module.exports = {
	meta: {
		type: "problem",

		docs: {
			description:
				"Disallow calling global object properties as functions",
			recommended: true,
			url: "https://eslint.org/docs/latest/rules/no-obj-calls",
		},

		schema: [],

		messages: {
			unexpectedCall: "'{{name}}' is not a function.",
			unexpectedRefCall:
				"'{{name}}' is reference to '{{ref}}', which is not a function.",
		},
	},

	create(context) {
		const sourceCode = context.sourceCode;

		return {
			Program(node) {
				const scope = sourceCode.getScope(node);
				const tracker = new ReferenceTracker(scope);
				const traceMap = {};

				for (const g of nonCallableGlobals) {
					traceMap[g] = {
						[CALL]: true,
						[CONSTRUCT]: true,
					};
				}

				for (const {
					node: refNode,
					path,
				} of tracker.iterateGlobalReferences(traceMap)) {
					const name = getReportNodeName(refNode.callee);
					const ref = path[0];
					const messageId =
						name === ref ? "unexpectedCall" : "unexpectedRefCall";

					context.report({
						node: refNode,
						messageId,
						data: { name, ref },
					});
				}
			},
		};
	},
};