Actualizacion maquina principal
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / eslint / lib / rules / no-obj-calls.js
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 // Requirements
10 //------------------------------------------------------------------------------
11
12 const { CALL, ReferenceTracker } = require("eslint-utils");
13
14 //------------------------------------------------------------------------------
15 // Helpers
16 //------------------------------------------------------------------------------
17
18 const nonCallableGlobals = ["Atomics", "JSON", "Math", "Reflect"];
19
20 //------------------------------------------------------------------------------
21 // Rule Definition
22 //------------------------------------------------------------------------------
23
24 module.exports = {
25     meta: {
26         type: "problem",
27
28         docs: {
29             description: "disallow calling global object properties as functions",
30             category: "Possible Errors",
31             recommended: true,
32             url: "https://eslint.org/docs/rules/no-obj-calls"
33         },
34
35         schema: [],
36
37         messages: {
38             unexpectedCall: "'{{name}}' is not a function."
39         }
40     },
41
42     create(context) {
43
44         return {
45             Program() {
46                 const scope = context.getScope();
47                 const tracker = new ReferenceTracker(scope);
48                 const traceMap = {};
49
50                 for (const global of nonCallableGlobals) {
51                     traceMap[global] = {
52                         [CALL]: true
53                     };
54                 }
55
56                 for (const { node } of tracker.iterateGlobalReferences(traceMap)) {
57                     context.report({ node, messageId: "unexpectedCall", data: { name: node.callee.name } });
58                 }
59             }
60         };
61     }
62 };