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