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>
This commit is contained in:
Eric Sunshine 2018-08-13 04:47:35 -04:00 committed by Junio C Hamano
parent c2c29cc03e
commit 7e32a31b21
5 changed files with 18 additions and 4 deletions

View 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

View File

@ -2,4 +2,6 @@ boodle wobba gorgo snoot wafta snurb &&
cat >foo &&
cat >bar &&
horticulture

View 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

View File

@ -5,5 +5,6 @@
>) &&
(
cat >bup &&
cat >bup2 &&
meep
>)

View File

@ -27,5 +27,9 @@
glink
FIZZ
ARBITRARY
cat <<-'ARBITRARY2' >bup2 &&
glink
FIZZ
ARBITRARY2
meep
)