add support for heredoc folding of lines
this change in the parser allows for us to have heredocs folded
into logical lines.
Change-Id: I51ebe6cd7b89b5f7194e947896f20b6750e972e3
diff --git a/tools/bash8.py b/tools/bash8.py
index 82a1010..edf7da4 100755
--- a/tools/bash8.py
+++ b/tools/bash8.py
@@ -55,10 +55,41 @@
print_error('E003: Indent not multiple of 4', line)
+def starts_multiline(line):
+ m = re.search("[^<]<<\s*(?P<token>\w+)", line)
+ if m:
+ return m.group('token')
+ else:
+ return False
+
+
+def end_of_multiline(line, token):
+ if token:
+ return re.search("^%s\s*$" % token, line) is not None
+ return False
+
+
def check_files(files):
+ in_multiline = False
+ logical_line = ""
+ token = False
for line in fileinput.input(files):
- check_no_trailing_whitespace(line)
- check_indents(line)
+ # NOTE(sdague): multiline processing of heredocs is interesting
+ if not in_multiline:
+ logical_line = line
+ token = starts_multiline(line)
+ if token:
+ in_multiline = True
+ continue
+ else:
+ logical_line = logical_line + line
+ if not end_of_multiline(line, token):
+ continue
+ else:
+ in_multiline = False
+
+ check_no_trailing_whitespace(logical_line)
+ check_indents(logical_line)
def get_options():