introduce if/then & for/do rules

we mostly have a consistent style on if/then & for/do in devstack,
except when we don't. This attempts to build a set of rules to
enforce this.

Because there are times when lines are legitimately long, and there
is a continuation, this starts off ignoring if and for loops with
continuations. But for short versions, we should enforce this.

Changes to make devstack pass are included. The fact that the
cleanup patch was so small is pretty solid reason that this is
actually the style we've all agreed to.

Part of a git stash from hong kong that I finally cleaned up.

Change-Id: I6376d7afd59cc5ebba9ed69e5ee784a3d5934a10
diff --git a/tools/bash8.py b/tools/bash8.py
index 2623358..9fb51ec 100755
--- a/tools/bash8.py
+++ b/tools/bash8.py
@@ -21,9 +21,19 @@
 # Currently Supported checks
 #
 # Errors
+# Basic white space errors, for consistent indenting
 # - E001: check that lines do not end with trailing whitespace
 # - E002: ensure that indents are only spaces, and not hard tabs
 # - E003: ensure all indents are a multiple of 4 spaces
+#
+# Structure errors
+#
+# A set of rules that help keep things consistent in control blocks.
+# These are ignored on long lines that have a continuation, because
+# unrolling that is kind of "interesting"
+#
+# - E010: *do* not on the same line as *for*
+# - E011: *then* not on the same line as *if*
 
 import argparse
 import fileinput
@@ -51,6 +61,23 @@
     print(" - %s: L%s" % (fileinput.filename(), fileinput.filelineno()))
 
 
+def not_continuation(line):
+    return not re.search('\\\\$', line)
+
+def check_for_do(line):
+    if not_continuation(line):
+        if re.search('^\s*for ', line):
+            if not re.search(';\s*do(\b|$)', line):
+                print_error('E010: Do not on same line as for', line)
+
+
+def check_if_then(line):
+    if not_continuation(line):
+        if re.search('^\s*if \[', line):
+            if not re.search(';\s*then(\b|$)', line):
+                print_error('E011: Then non on same line as if', line)
+
+
 def check_no_trailing_whitespace(line):
     if re.search('[ \t]+$', line):
         print_error('E001: Trailing Whitespace', line)
@@ -100,6 +127,8 @@
 
         check_no_trailing_whitespace(logical_line)
         check_indents(logical_line)
+        check_for_do(logical_line)
+        check_if_then(logical_line)
 
 
 def get_options():