1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | module.exports = function(context) {
|
11 |
|
12 | "use strict";
|
13 |
|
14 | function findOpenParen(tokens) {
|
15 | var i, token, hasArgumentList = false, numOpen = 0;
|
16 |
|
17 |
|
18 | for(i = tokens.length - 1; i >= 0; --i) {
|
19 | token = tokens[i];
|
20 | if (token.value === "(") {
|
21 | --numOpen;
|
22 | } else if (token.value === ")") {
|
23 | hasArgumentList = true;
|
24 | ++numOpen;
|
25 | }
|
26 | if (hasArgumentList && numOpen <= 0) {
|
27 | return i;
|
28 | }
|
29 | }
|
30 | }
|
31 |
|
32 | function detectOpenSpaces(node) {
|
33 | var tokens = context.getTokens(node),
|
34 | openParenIndex = findOpenParen(tokens),
|
35 | openParen = tokens[openParenIndex],
|
36 | callee = tokens[openParenIndex - 1];
|
37 |
|
38 |
|
39 | if (!openParenIndex) { return; }
|
40 |
|
41 |
|
42 | if (callee.range[1] !== openParen.range[0]) {
|
43 | context.report(node, "Spaced function application is not allowed.");
|
44 | }
|
45 | }
|
46 |
|
47 | return {
|
48 | "CallExpression": detectOpenSpaces,
|
49 | "NewExpression": detectOpenSpaces
|
50 | };
|
51 |
|
52 | };
|