7fb9fc286472a402a9172bbefd8d66dab3f13da3
[platform/framework/web/crosswalk-tizen.git] /
1 /**
2  * @fileoverview Rule to check that spaced function application
3  * @author Matt DuVall <http://www.mattduvall.com>
4  */
5
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Rule Definition
10 //------------------------------------------------------------------------------
11
12 module.exports = function(context) {
13
14     function detectOpenSpaces(node) {
15         var lastCalleeToken = context.getLastToken(node.callee);
16         var tokens = context.getTokens(node);
17         var i = tokens.indexOf(lastCalleeToken), l = tokens.length;
18         while (i < l && tokens[i].value !== "(") {
19             ++i;
20         }
21         if (i >= l) {
22             return;
23         }
24         // look for a space between the callee and the open paren
25         if (tokens[i - 1].range[1] !== tokens[i].range[0]) {
26             context.report(node, "Unexpected space between function name and paren.");
27         }
28     }
29
30     return {
31         "CallExpression": detectOpenSpaces,
32         "NewExpression": detectOpenSpaces
33     };
34
35 };