chainlint: match 'quoted' here-doc tags

A here-doc tag can be quoted ('EOF') or escaped (\EOF) to suppress interpolation within the body. Although, chainlint recognizes escaped tags, it does not know about quoted tags. For completeness, teach it to recognize quoted tags, as well. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Aug 13, 2018 at 04:47 UTC 7e32a31b2101c3ced65ea9367c747930a4eb39d9
5 files changed +18 -4
t/chainlint.sed
+4 -4
@@ -94,8 +94,8 @@
94
95 # here-doc -- swallow it to avoid false hits within its body (but keep the
96 # command to which it was attached)
97 -/<<[ ]*[-\\]*[A-Za-z0-9_]/ {
98 - s/^\(.*\)<<[ ]*[-\\]*\([A-Za-z0-9_][A-Za-z0-9_]*\)/<\2>\1<</
97 +/<<[ ]*[-\\']*[A-Za-z0-9_]/ {
98 + s/^\(.*\)<<[ ]*[-\\']*\([A-Za-z0-9_][A-Za-z0-9_]*\)'*/<\2>\1<</
99 s/[ ]*<<//
100 :hereslurp
101 N
@@ -158,7 +158,7 @@ s/.*\n//
158 /"[^'"]*'[^'"]*"/!bsqstring
159 }
160 # here-doc -- swallow it
161 -/<<[ ]*[-\\]*[A-Za-z0-9_]/bheredoc
161 +/<<[ ]*[-\\']*[A-Za-z0-9_]/bheredoc
162 # comment or empty line -- discard since final non-comment, non-empty line
163 # before closing ")", "done", "elsif", "else", or "fi" will need to be
164 # re-visited to drop "suspect" marking since final line of those constructs
@@ -268,7 +268,7 @@ bcheckchain
268 # found here-doc -- swallow it to avoid false hits within its body (but keep
269 # the command to which it was attached)
270 :heredoc
271 -s/^\(.*\)<<[ ]*[-\\]*\([A-Za-z0-9_][A-Za-z0-9_]*\)/<\2>\1<</
271 +s/^\(.*\)<<[ ]*[-\\']*\([A-Za-z0-9_][A-Za-z0-9_]*\)'*/<\2>\1<</
272 s/[ ]*<<//
273 :hereslurpsub
274 N
t/chainlint/here-doc.expect
+2
@@ -2,4 +2,6 @@ boodle wobba gorgo snoot wafta snurb &&
2
3 cat >foo &&
4
5 +cat >bar &&
6 +
7 horticulture
t/chainlint/here-doc.test
+7
@@ -14,6 +14,13 @@ boz
14 woz
15 Arbitrary_Tag_42
16
17 +# LINT: swallow 'quoted' here-doc
18 +cat <<'FUMP' >bar &&
19 +snoz
20 +boz
21 +woz
22 +FUMP
23 +
24 # LINT: swallow here-doc (EOF is last line of test)
25 horticulture <<\EOF
26 gomez
t/chainlint/subshell-here-doc.expect
+1
@@ -5,5 +5,6 @@
5 >) &&
6 (
7 cat >bup &&
8 + cat >bup2 &&
9 meep
10 >)
t/chainlint/subshell-here-doc.test
+4
@@ -27,5 +27,9 @@
27 glink
28 FIZZ
29 ARBITRARY
30 + cat <<-'ARBITRARY2' >bup2 &&
31 + glink
32 + FIZZ
33 + ARBITRARY2
34 meep
35 )