2 * @fileoverview Rule to flag use of an object property of the global object (Math and JSON) as a function
3 * @author James Allardice
8 //------------------------------------------------------------------------------
10 //------------------------------------------------------------------------------
12 const { CALL, ReferenceTracker } = require("eslint-utils");
14 //------------------------------------------------------------------------------
16 //------------------------------------------------------------------------------
18 const nonCallableGlobals = ["Atomics", "JSON", "Math", "Reflect"];
20 //------------------------------------------------------------------------------
22 //------------------------------------------------------------------------------
29 description: "disallow calling global object properties as functions",
30 category: "Possible Errors",
32 url: "https://eslint.org/docs/rules/no-obj-calls"
38 unexpectedCall: "'{{name}}' is not a function."
46 const scope = context.getScope();
47 const tracker = new ReferenceTracker(scope);
50 for (const global of nonCallableGlobals) {
56 for (const { node } of tracker.iterateGlobalReferences(traceMap)) {
57 context.report({ node, messageId: "unexpectedCall", data: { name: node.callee.name } });