UNPKG

759 BJavaScriptView Raw
1/**
2 * @fileoverview Rule to flag blocks with no reason to exist
3 * @author Brandon Mills
4 */
5
6//------------------------------------------------------------------------------
7// Rule Definition
8//------------------------------------------------------------------------------
9
10module.exports = function(context) {
11
12 "use strict";
13
14 return {
15 "BlockStatement": function (node) {
16 // Check for any occurrence of BlockStatement > BlockStatement or
17 // Program > BlockStatement
18 var parent = context.getAncestors().pop();
19 if (parent.type === "BlockStatement" || parent.type === "Program") {
20 context.report(node, "Block is nested inside another block.");
21 }
22 }
23 };
24
25};