diff --git a/bashate/bashate.py b/bashate/bashate.py index 6262f49..60adaf1 100644 --- a/bashate/bashate.py +++ b/bashate/bashate.py @@ -87,7 +87,9 @@ def check_function_decl(line, report): def starts_multiline(line): - m = re.search("[^<]<<\s*(?P\w+)", line) + # note, watch out for <\w+)([\'\"]?)", line) return m.group('token') if m else False @@ -257,7 +259,10 @@ class BashateRun(object): if verbose: print("Running bashate on %s" % fileinput.filename()) - # NOTE(sdague): multiline processing of heredocs is interesting + # strip out heredocs, and don't run any checks on + # their contents. These are usually things like yaml + # files or other bits and pieces that don't obey our + # syntax such as indenting or line-length. if not in_multiline: logical_line = line token = starts_multiline(line) @@ -270,6 +275,11 @@ class BashateRun(object): continue else: in_multiline = False + # XXX: if we want to do something with + # heredocs in the future, then the whole thing + # is now stored in logical_line. for now, + # skip + continue # Don't run any tests on comment lines if logical_line.lstrip().startswith('#'): diff --git a/bashate/tests/samples/heredoc_ignore.sh b/bashate/tests/samples/heredoc_ignore.sh new file mode 100644 index 0000000..4427b27 --- /dev/null +++ b/bashate/tests/samples/heredoc_ignore.sh @@ -0,0 +1,42 @@ +#!/bin/bash + +FOO=< /tmp/tofile + + this is a file + that does not obey our indenting + or our line length ------------------------------------------------- + +EOF + +cat << 'EOF' | sed 's/foo/bar' + + this is a file + that does not obey our indenting + or our line length ------------------------------------------------- + +EOF + +cat <<"EOF" + + this is a file + that does not obey our indenting + or our line length ------------------------------------------------- + +EOF + +cat > foo <