chainlint: match "quoted" here-doc tags

A here-doc tag can be quoted ('EOF'/"EOF") or escaped (\EOF) to suppress interpolation within the body. chainlint recognizes single-quoted and escaped tags, but does not know about double-quoted tags. For completeness, teach it to recognize double-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 29, 2018 at 05:45 UTC 3042b6bb59787613e36e459bf60994a26bb5a5df
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
@@ -159,7 +159,7 @@ s/.*\n//
159 }
160 :folded
161 # here-doc -- swallow it
162 -/<<[ ]*[-\\']*[A-Za-z0-9_]/bheredoc
162 +/<<[ ]*[-\\'"]*[A-Za-z0-9_]/bheredoc
163 # comment or empty line -- discard since final non-comment, non-empty line
164 # before closing ")", "done", "elsif", "else", or "fi" will need to be
165 # re-visited to drop "suspect" marking since final line of those constructs
@@ -281,7 +281,7 @@ bfolded
281 # found here-doc -- swallow it to avoid false hits within its body (but keep
282 # the command to which it was attached)
283 :heredoc
284 -s/^\(.*\)<<[ ]*[-\\']*\([A-Za-z0-9_][A-Za-z0-9_]*\)'*/<\2>\1<</
284 +s/^\(.*\)<<[ ]*[-\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</
285 s/[ ]*<<//
286 :hereslurpsub
287 N
t/chainlint/here-doc.expect
+2
@@ -4,4 +4,6 @@ cat >foo &&
4
5 cat >bar &&
6
7 +cat >boo &&
8 +
9 horticulture
t/chainlint/here-doc.test
+7
@@ -21,6 +21,13 @@ boz
21 woz
22 FUMP
23
24 +# LINT: swallow "quoted" here-doc
25 +cat <<"zump" >boo &&
26 +snoz
27 +boz
28 +woz
29 +zump
30 +
31 # LINT: swallow here-doc (EOF is last line of test)
32 horticulture <<\EOF
33 gomez
t/chainlint/subshell-here-doc.expect
+1
@@ -6,5 +6,6 @@
6 (
7 cat >bup &&
8 cat >bup2 &&
9 + cat >bup3 &&
10 meep
11 >)
t/chainlint/subshell-here-doc.test
+4
@@ -31,5 +31,9 @@
31 glink
32 FIZZ
33 ARBITRARY2
34 + cat <<-"ARBITRARY3" >bup3 &&
35 + glink
36 + FIZZ
37 + ARBITRARY3
38 meep
39 )