UNPKG

1.09 kBJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag use of an object property of the global object (Math and JSON) as a function
3 * @author James Allardice
4 */
5
6"use strict";
7
8//------------------------------------------------------------------------------
9// Rule Definition
10//------------------------------------------------------------------------------
11
12module.exports = {
13 meta: {
14 docs: {
15 description: "disallow calling global object properties as functions",
16 category: "Possible Errors",
17 recommended: true,
18 url: "https://eslint.org/docs/rules/no-obj-calls"
19 },
20
21 schema: []
22 },
23
24 create(context) {
25
26 return {
27 CallExpression(node) {
28
29 if (node.callee.type === "Identifier") {
30 const name = node.callee.name;
31
32 if (name === "Math" || name === "JSON" || name === "Reflect") {
33 context.report({ node, message: "'{{name}}' is not a function.", data: { name } });
34 }
35 }
36 }
37 };
38
39 }
40};