chainlint: match 'quoted' here-doc tags
authorEric Sunshine <sunshine@sunshineco.com>
Mon, 13 Aug 2018 08:47:35 +0000 (04:47 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Aug 2018 19:22:11 +0000 (12:22 -0700)
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>
t/chainlint.sed
t/chainlint/here-doc.expect
t/chainlint/here-doc.test
t/chainlint/subshell-here-doc.expect
t/chainlint/subshell-here-doc.test

index 2af1a68..2901494 100644 (file)
@@ -94,8 +94,8 @@
 
 # here-doc -- swallow it to avoid false hits within its body (but keep the
 # command to which it was attached)
-/<<[   ]*[-\\]*[A-Za-z0-9_]/ {
-       s/^\(.*\)<<[    ]*[-\\]*\([A-Za-z0-9_][A-Za-z0-9_]*\)/<\2>\1<</
+/<<[   ]*[-\\']*[A-Za-z0-9_]/ {
+       s/^\(.*\)<<[    ]*[-\\']*\([A-Za-z0-9_][A-Za-z0-9_]*\)'*/<\2>\1<</
        s/[     ]*<<//
        :hereslurp
        N
@@ -158,7 +158,7 @@ s/.*\n//
        /"[^'"]*'[^'"]*"/!bsqstring
 }
 # here-doc -- swallow it
-/<<[   ]*[-\\]*[A-Za-z0-9_]/bheredoc
+/<<[   ]*[-\\']*[A-Za-z0-9_]/bheredoc
 # comment or empty line -- discard since final non-comment, non-empty line
 # before closing ")", "done", "elsif", "else", or "fi" will need to be
 # re-visited to drop "suspect" marking since final line of those constructs
@@ -268,7 +268,7 @@ bcheckchain
 # found here-doc -- swallow it to avoid false hits within its body (but keep
 # the command to which it was attached)
 :heredoc
-s/^\(.*\)<<[   ]*[-\\]*\([A-Za-z0-9_][A-Za-z0-9_]*\)/<\2>\1<</
+s/^\(.*\)<<[   ]*[-\\']*\([A-Za-z0-9_][A-Za-z0-9_]*\)'*/<\2>\1<</
 s/[    ]*<<//
 :hereslurpsub
 N
index 33bc3cc..aff6568 100644 (file)
@@ -2,4 +2,6 @@ boodle wobba        gorgo snoot        wafta snurb &&
 
 cat >foo &&
 
+cat >bar &&
+
 horticulture
index 8986eef..f2bb14b 100644 (file)
@@ -14,6 +14,13 @@ boz
 woz
 Arbitrary_Tag_42
 
+# LINT: swallow 'quoted' here-doc
+cat <<'FUMP' >bar &&
+snoz
+boz
+woz
+FUMP
+
 # LINT: swallow here-doc (EOF is last line of test)
 horticulture <<\EOF
 gomez
index 7c2da63..7663ea7 100644 (file)
@@ -5,5 +5,6 @@
 >) &&
 (
        cat >bup &&
+       cat >bup2 &&
        meep
 >)
index 05139af..b6b5a9b 100644 (file)
@@ -27,5 +27,9 @@
        glink
        FIZZ
        ARBITRARY
+       cat <<-'ARBITRARY2' >bup2 &&
+       glink
+       FIZZ
+       ARBITRARY2
        meep
 )