Actualizacion maquina principal
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / eslint / lib / rules / no-spaced-func.js
1 /**
2  * @fileoverview Rule to check that spaced function application
3  * @author Matt DuVall <http://www.mattduvall.com>
4  * @deprecated in ESLint v3.3.0
5  */
6
7 "use strict";
8
9 //------------------------------------------------------------------------------
10 // Rule Definition
11 //------------------------------------------------------------------------------
12
13 module.exports = {
14     meta: {
15         type: "layout",
16
17         docs: {
18             description: "disallow spacing between function identifiers and their applications (deprecated)",
19             category: "Stylistic Issues",
20             recommended: false,
21             url: "https://eslint.org/docs/rules/no-spaced-func"
22         },
23
24         deprecated: true,
25
26         replacedBy: ["func-call-spacing"],
27
28         fixable: "whitespace",
29         schema: []
30     },
31
32     create(context) {
33
34         const sourceCode = context.getSourceCode();
35
36         /**
37          * Check if open space is present in a function name
38          * @param {ASTNode} node node to evaluate
39          * @returns {void}
40          * @private
41          */
42         function detectOpenSpaces(node) {
43             const lastCalleeToken = sourceCode.getLastToken(node.callee);
44             let prevToken = lastCalleeToken,
45                 parenToken = sourceCode.getTokenAfter(lastCalleeToken);
46
47             // advances to an open parenthesis.
48             while (
49                 parenToken &&
50                 parenToken.range[1] < node.range[1] &&
51                 parenToken.value !== "("
52             ) {
53                 prevToken = parenToken;
54                 parenToken = sourceCode.getTokenAfter(parenToken);
55             }
56
57             // look for a space between the callee and the open paren
58             if (parenToken &&
59                 parenToken.range[1] < node.range[1] &&
60                 sourceCode.isSpaceBetweenTokens(prevToken, parenToken)
61             ) {
62                 context.report({
63                     node,
64                     loc: lastCalleeToken.loc.start,
65                     message: "Unexpected space between function name and paren.",
66                     fix(fixer) {
67                         return fixer.removeRange([prevToken.range[1], parenToken.range[0]]);
68                     }
69                 });
70             }
71         }
72
73         return {
74             CallExpression: detectOpenSpaces,
75             NewExpression: detectOpenSpaces
76         };
77
78     }
79 };