Blame view

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