f54350e76515ef0bb442fa3e095eb19f5424fcef
[platform/framework/web/crosswalk-tizen.git] /
1 /**
2  * @fileoverview Rule to enforce a particular function style
3  * @author Nicholas C. Zakas
4  * @copyright 2013 Nicholas C. Zakas. All rights reserved.
5  */
6 "use strict";
7
8 //------------------------------------------------------------------------------
9 // Rule Definition
10 //------------------------------------------------------------------------------
11
12 module.exports = function(context) {
13
14     var style = context.options[0],
15         enforceDeclarations = (style === "declaration");
16
17     return {
18
19         "FunctionDeclaration": function(node) {
20             if (!enforceDeclarations) {
21                 context.report(node, "Expected a function expression.");
22             }
23         },
24
25         "FunctionExpression": function() {
26             var parent = context.getAncestors().pop();
27
28             if (enforceDeclarations && parent.type === "VariableDeclarator") {
29                 context.report(parent, "Expected a function declaration.");
30             }
31         },
32
33         "ArrowFunctionExpression": function() {
34             var parent = context.getAncestors().pop();
35
36             if (enforceDeclarations && parent.type === "VariableDeclarator") {
37                 context.report(parent, "Expected a function declaration.");
38             }
39         }
40
41     };
42
43 };