chainlint.sed: improve ?!AMP?! placement accuracy

When chainlint.sed detects a broken &&-chain, it places an ?!AMP?!
annotation at the beginning of the line. However, this is an unusual
location for programmers accustomed to error messages (from compilers,
for instance) indicating the exact point of the problem. Therefore,
relocate the ?!AMP?! annotation to the end of the line in order to
better direct the programmer's attention to the source of the problem.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Eric Sunshine
2021-12-13 01:30:50 -05:00
committed by Junio C Hamano
parent f30c1d5eb1
commit db8c7a1cc0
23 changed files with 38 additions and 38 deletions

View File

@ -236,7 +236,7 @@ s/.*\n//
# line ends with pipe "...|" -- valid; not missing "&&" # line ends with pipe "...|" -- valid; not missing "&&"
/|[ ]*$/bcont /|[ ]*$/bcont
# missing end-of-line "&&" -- mark suspect # missing end-of-line "&&" -- mark suspect
/&&[ ]*$/!s/^/?!AMP?!/ /&&[ ]*$/!s/$/ ?!AMP?!/
:cont :cont
# retrieve and print previous line # retrieve and print previous line
x x
@ -303,7 +303,7 @@ bcase
# that line legitimately lacks "&&" # that line legitimately lacks "&&"
:else :else
x x
s/?!AMP?!// s/ ?!AMP?!$//
x x
bcont bcont
@ -311,7 +311,7 @@ bcont
# "suspect" from final contained line since that line legitimately lacks "&&" # "suspect" from final contained line since that line legitimately lacks "&&"
:done :done
x x
s/?!AMP?!// s/ ?!AMP?!$//
x x
# is 'done' or 'fi' cuddled with ")" to close subshell? # is 'done' or 'fi' cuddled with ")" to close subshell?
/done.*)/bclose /done.*)/bclose
@ -354,7 +354,7 @@ bblock
# since that line legitimately lacks "&&" and exit subshell loop # since that line legitimately lacks "&&" and exit subshell loop
:clssolo :clssolo
x x
s/?!AMP?!// s/ ?!AMP?!$//
p p
x x
s/^/>/ s/^/>/

View File

@ -4,6 +4,6 @@
baz baz
>) && >) &&
( (
?!AMP?! bar=$((42 + 1)) bar=$((42 + 1)) ?!AMP?!
baz baz
>) >)

View File

@ -7,6 +7,6 @@
bar && bar &&
{ {
echo c echo c
?!AMP?! } } ?!AMP?!
baz baz
>) >)

View File

@ -1,6 +1,6 @@
( (
foo && foo &&
?!AMP?! bar bar ?!AMP?!
baz && baz &&
wop wop
>) >)

View File

@ -9,11 +9,11 @@
case "$x" in case "$x" in
x) foo ;; x) foo ;;
*) bar ;; *) bar ;;
?!AMP?! esac esac ?!AMP?!
foobar foobar
>) && >) &&
( (
case "$x" in 1) true;; esac && case "$x" in 1) true;; esac &&
?!AMP?! case "$y" in 2) false;; esac case "$y" in 2) false;; esac ?!AMP?!
foobar foobar
>) >)

View File

@ -4,6 +4,6 @@
baz baz
>) && >) &&
( (
?!AMP?! bar=$(gobble blocks) bar=$(gobble blocks) ?!AMP?!
baz baz
>) >)

View File

@ -4,7 +4,7 @@ cd foo &&
>) && >) &&
( (
?!AMP?!cd foo cd foo ?!AMP?!
bar bar
>) && >) &&
@ -17,5 +17,5 @@ cd foo &&
> bar) && > bar) &&
( (
?!AMP?!cd foo cd foo ?!AMP?!
> bar) > bar)

View File

@ -1,9 +1,9 @@
( (
for i in a b c for i in a b c
do do
?!AMP?! echo $i echo $i ?!AMP?!
cat cat
?!AMP?! done done ?!AMP?!
for i in a b c; do for i in a b c; do
echo $i && echo $i &&
cat $i cat $i

View File

@ -1,5 +1,5 @@
( (
x=$(bobble && x=$(bobble &&
?!AMP?!>> wiffle) >> wiffle) ?!AMP?!
echo $x echo $x
>) >)

View File

@ -1,4 +1,4 @@
( (
?!AMP?! cat && echo "multi-line string" cat && echo "multi-line string" ?!AMP?!
bap bap
>) >)

View File

@ -3,10 +3,10 @@
do do
if false if false
then then
?!AMP?! echo "err" echo "err" ?!AMP?!
exit 1 exit 1
?!AMP?! fi fi ?!AMP?!
foo foo
?!AMP?! done done ?!AMP?!
bar bar
>) >)

View File

@ -1,7 +1,7 @@
( (
if test -n "" if test -n ""
then then
?!AMP?! echo very echo very ?!AMP?!
echo empty echo empty
elif test -z "" elif test -z ""
then then
@ -9,7 +9,7 @@
else else
echo foo && echo foo &&
cat cat
?!AMP?! fi fi ?!AMP?!
echo poodle echo poodle
>) && >) &&
( (

View File

@ -1,6 +1,6 @@
( (
foobar && foobar &&
?!AMP?! barfoo barfoo ?!AMP?!
flibble "not a # comment" flibble "not a # comment"
>) && >) &&

View File

@ -3,10 +3,10 @@
then then
while true while true
do do
?!AMP?! echo "pop" echo "pop" ?!AMP?!
echo "glup" echo "glup"
?!AMP?! done done ?!AMP?!
foo foo
?!AMP?! fi fi ?!AMP?!
bar bar
>) >)

View File

@ -1,6 +1,6 @@
( (
x="line 1 line 2 line 3" && x="line 1 line 2 line 3" &&
?!AMP?! y="line 1 line2" y="line 1 line2" ?!AMP?!
foobar foobar
>) && >) &&
( (

View File

@ -4,16 +4,16 @@
>> ) && >> ) &&
(cd foo && (cd foo &&
bar bar
?!AMP?!>> ) >> ) ?!AMP?!
( (
cd foo && cd foo &&
>> bar) && >> bar) &&
( (
cd foo && cd foo &&
?!AMP?!>> bar) >> bar) ?!AMP?!
(cd foo && (cd foo &&
>> bar) && >> bar) &&
(cd foo && (cd foo &&
?!AMP?!>> bar) >> bar) ?!AMP?!
foobar foobar
>) >)

View File

@ -2,6 +2,6 @@ cat >foop &&
( (
cat && cat &&
?!AMP?! cat cat ?!AMP?!
foobar foobar
>) >)

View File

@ -6,6 +6,6 @@
# minor numbers of cows (or do they?) # minor numbers of cows (or do they?)
baz && baz &&
snaff snaff
?!AMP?!>> ) >> ) ?!AMP?!
fuzzy fuzzy
>) >)

View File

@ -3,6 +3,6 @@
bar | bar |
baz && baz &&
fish | fish |
?!AMP?! cow cow ?!AMP?!
sunder sunder
>) >)

View File

@ -1,5 +1,5 @@
( (
?!AMP?!?!SEMI?! cat foo ; echo bar ?!SEMI?! cat foo ; echo bar ?!AMP?!
?!SEMI?! cat foo ; echo bar ?!SEMI?! cat foo ; echo bar
>) && >) &&
( (

View File

@ -1,6 +1,6 @@
( (
echo wobba gorgo snoot wafta snurb && echo wobba gorgo snoot wafta snurb &&
?!AMP?! cat >bip cat >bip ?!AMP?!
echo >bop echo >bop
>) && >) &&
( (

View File

@ -8,7 +8,7 @@
(foo || exit 1) && (foo || exit 1) &&
(foo || exit 1) | (foo || exit 1) |
(foo || exit 1) >baz && (foo || exit 1) >baz &&
?!AMP?! (foo && bar) (foo && bar) ?!AMP?!
?!AMP?!?!SEMI?! (foo && bar; baz) ?!SEMI?! (foo && bar; baz) ?!AMP?!
foobar foobar
>) >)

View File

@ -1,9 +1,9 @@
( (
while true while true
do do
?!AMP?! echo foo echo foo ?!AMP?!
cat cat
?!AMP?! done done ?!AMP?!
while true; do while true; do
echo foo && echo foo &&
cat bar cat bar