]> git.proxmox.com Git - pve-eslint.git/blame - eslint/lib/rules/no-spaced-func.js
import 8.3.0 source
[pve-eslint.git] / eslint / lib / rules / no-spaced-func.js
CommitLineData
eb39fafa
DC
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
13module.exports = {
14 meta: {
15 type: "layout",
16
17 docs: {
18 description: "disallow spacing between function identifiers and their applications (deprecated)",
eb39fafa
DC
19 recommended: false,
20 url: "https://eslint.org/docs/rules/no-spaced-func"
21 },
22
23 deprecated: true,
24
25 replacedBy: ["func-call-spacing"],
26
27 fixable: "whitespace",
28 schema: [],
29
30 messages: {
31 noSpacedFunction: "Unexpected space between function name and paren."
32 }
33 },
34
35 create(context) {
36
37 const sourceCode = context.getSourceCode();
38
39 /**
40 * Check if open space is present in a function name
41 * @param {ASTNode} node node to evaluate
42 * @returns {void}
43 * @private
44 */
45 function detectOpenSpaces(node) {
46 const lastCalleeToken = sourceCode.getLastToken(node.callee);
47 let prevToken = lastCalleeToken,
48 parenToken = sourceCode.getTokenAfter(lastCalleeToken);
49
50 // advances to an open parenthesis.
51 while (
52 parenToken &&
53 parenToken.range[1] < node.range[1] &&
54 parenToken.value !== "("
55 ) {
56 prevToken = parenToken;
57 parenToken = sourceCode.getTokenAfter(parenToken);
58 }
59
60 // look for a space between the callee and the open paren
61 if (parenToken &&
62 parenToken.range[1] < node.range[1] &&
63 sourceCode.isSpaceBetweenTokens(prevToken, parenToken)
64 ) {
65 context.report({
66 node,
67 loc: lastCalleeToken.loc.start,
68 messageId: "noSpacedFunction",
69 fix(fixer) {
70 return fixer.removeRange([prevToken.range[1], parenToken.range[0]]);
71 }
72 });
73 }
74 }
75
76 return {
77 CallExpression: detectOpenSpaces,
78 NewExpression: detectOpenSpaces
79 };
80
81 }
82};