59d807da30de39c6e71df5b5f2c95894b2c7c173
[platform/framework/web/crosswalk-tizen.git] /
1 /**
2  * @fileoverview Rule to disallow if as the only statmenet in an else block
3  * @author Brandon Mills
4  */
5 "use strict";
6
7 //------------------------------------------------------------------------------
8 // Rule Definition
9 //------------------------------------------------------------------------------
10
11 module.exports = function(context) {
12
13     return {
14         "IfStatement": function(node) {
15             var ancestors = context.getAncestors(),
16                 parent = ancestors.pop(),
17                 grandparent = ancestors.pop();
18
19             if (parent && parent.type === "BlockStatement" &&
20                     parent.body.length === 1 && grandparent &&
21                     grandparent.type === "IfStatement" &&
22                     parent === grandparent.alternate) {
23                 context.report(node, "Unexpected if as the only statement in an else block.");
24             }
25         }
26     };
27
28 };