UNPKG

1.12 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 type: "problem",
15
16 docs: {
17 description: "disallow calling global object properties as functions",
18 category: "Possible Errors",
19 recommended: true,
20 url: "https://eslint.org/docs/rules/no-obj-calls"
21 },
22
23 schema: []
24 },
25
26 create(context) {
27
28 return {
29 CallExpression(node) {
30
31 if (node.callee.type === "Identifier") {
32 const name = node.callee.name;
33
34 if (name === "Math" || name === "JSON" || name === "Reflect") {
35 context.report({ node, message: "'{{name}}' is not a function.", data: { name } });
36 }
37 }
38 }
39 };
40
41 }
42};