From 649c7dc799489b8fbcbb920c9a6d9397d82f755e Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Tue, 20 Oct 2015 17:58:42 +1100 Subject: [PATCH] Ignore heredoc contents I noticed that we end up treating a heredoc as one big logical line, then passing it through things like the line-length check. So cat <\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 <