summaryrefslogtreecommitdiff
path: root/tools/eslint/lib/rules/no-lone-blocks.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/eslint/lib/rules/no-lone-blocks.js')
-rw-r--r--tools/eslint/lib/rules/no-lone-blocks.js25
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/eslint/lib/rules/no-lone-blocks.js b/tools/eslint/lib/rules/no-lone-blocks.js
new file mode 100644
index 0000000000..25d8c34f00
--- /dev/null
+++ b/tools/eslint/lib/rules/no-lone-blocks.js
@@ -0,0 +1,25 @@
+/**
+ * @fileoverview Rule to flag blocks with no reason to exist
+ * @author Brandon Mills
+ */
+
+"use strict";
+
+//------------------------------------------------------------------------------
+// Rule Definition
+//------------------------------------------------------------------------------
+
+module.exports = function(context) {
+
+ return {
+ "BlockStatement": function (node) {
+ // Check for any occurrence of BlockStatement > BlockStatement or
+ // Program > BlockStatement
+ var parent = context.getAncestors().pop();
+ if (parent.type === "BlockStatement" || parent.type === "Program") {
+ context.report(node, "Block is nested inside another block.");
+ }
+ }
+ };
+
+};