2 * @fileoverview Rule to disallow if as the only statmenet in an else block
3 * @author Brandon Mills
7 //------------------------------------------------------------------------------
9 //------------------------------------------------------------------------------
11 module.exports = function(context) {
14 "IfStatement": function(node) {
15 var ancestors = context.getAncestors(),
16 parent = ancestors.pop(),
17 grandparent = ancestors.pop();
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.");