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>
Eric Sunshine committed
Dec 13, 2021 at 01:30 UTC
db8c7a1cc02e545dd75b55e2ccbab2de51cd06ae
23 files changed
+38
-38
t/chainlint.sed
+4
-4
@@ -236,7 +236,7 @@ s/.*\n//
236
# line ends with pipe "...|" -- valid; not missing "&&"
237
/|[ ]*$/bcont
238
# missing end-of-line "&&" -- mark suspect
239
-/&&[ ]*$/!s/^/?!AMP?!/
239
+/&&[ ]*$/!s/$/ ?!AMP?!/
240
:cont
241
# retrieve and print previous line
242
x
@@ -303,7 +303,7 @@ bcase
303
# that line legitimately lacks "&&"
304
:else
305
x
306
-s/?!AMP?!//
306
+s/ ?!AMP?!$//
307
x
308
bcont
309
@@ -311,7 +311,7 @@ bcont
311
# "suspect" from final contained line since that line legitimately lacks "&&"
312
:done
313
x
314
-s/?!AMP?!//
314
+s/ ?!AMP?!$//
315
x
316
# is 'done' or 'fi' cuddled with ")" to close subshell?
317
/done.*)/bclose
@@ -354,7 +354,7 @@ bblock
354
# since that line legitimately lacks "&&" and exit subshell loop
355
:clssolo
356
x
357
-s/?!AMP?!//
357
+s/ ?!AMP?!$//
358
p
359
x
360
s/^/>/
t/chainlint/arithmetic-expansion.expect
+1
-1
@@ -4,6 +4,6 @@
4
baz
5
>) &&
6
(
7
-?!AMP?! bar=$((42 + 1))
7
+ bar=$((42 + 1)) ?!AMP?!
8
baz
9
>)
t/chainlint/block.expect
+1
-1
@@ -7,6 +7,6 @@
7
bar &&
8
{
9
echo c
10
-?!AMP?! }
10
+ } ?!AMP?!
11
baz
12
>)
t/chainlint/broken-chain.expect
+1
-1
@@ -1,6 +1,6 @@
1
(
2
foo &&
3
-?!AMP?! bar
3
+ bar ?!AMP?!
4
baz &&
5
wop
6
>)
t/chainlint/case.expect
+2
-2
@@ -9,11 +9,11 @@
9
case "$x" in
10
x) foo ;;
11
*) bar ;;
12
-?!AMP?! esac
12
+ esac ?!AMP?!
13
foobar
14
>) &&
15
(
16
case "$x" in 1) true;; esac &&
17
-?!AMP?! case "$y" in 2) false;; esac
17
+ case "$y" in 2) false;; esac ?!AMP?!
18
foobar
19
>)
t/chainlint/command-substitution.expect
+1
-1
@@ -4,6 +4,6 @@
4
baz
5
>) &&
6
(
7
-?!AMP?! bar=$(gobble blocks)
7
+ bar=$(gobble blocks) ?!AMP?!
8
baz
9
>)
t/chainlint/cuddled.expect
+2
-2
@@ -4,7 +4,7 @@ cd foo &&
4
>) &&
5
6
(
7
-?!AMP?!cd foo
7
+cd foo ?!AMP?!
8
bar
9
>) &&
10
@@ -17,5 +17,5 @@ cd foo &&
17
> bar) &&
18
19
(
20
-?!AMP?!cd foo
20
+cd foo ?!AMP?!
21
> bar)
t/chainlint/for-loop.expect
+2
-2
@@ -1,9 +1,9 @@
1
(
2
for i in a b c
3
do
4
-?!AMP?! echo $i
4
+ echo $i ?!AMP?!
5
cat
6
-?!AMP?! done
6
+ done ?!AMP?!
7
for i in a b c; do
8
echo $i &&
9
cat $i
t/chainlint/here-doc-multi-line-command-subst.expect
+1
-1
@@ -1,5 +1,5 @@
1
(
2
x=$(bobble &&
3
-?!AMP?!>> wiffle)
3
+>> wiffle) ?!AMP?!
4
echo $x
5
>)
t/chainlint/here-doc-multi-line-string.expect
+1
-1
@@ -1,4 +1,4 @@
1
(
2
-?!AMP?! cat && echo "multi-line string"
2
+ cat && echo "multi-line string" ?!AMP?!
3
bap
4
>)
t/chainlint/if-in-loop.expect
+3
-3
@@ -3,10 +3,10 @@
3
do
4
if false
5
then
6
-?!AMP?! echo "err"
6
+ echo "err" ?!AMP?!
7
exit 1
8
-?!AMP?! fi
8
+ fi ?!AMP?!
9
foo
10
-?!AMP?! done
10
+ done ?!AMP?!
11
bar
12
>)
t/chainlint/if-then-else.expect
+2
-2
@@ -1,7 +1,7 @@
1
(
2
if test -n ""
3
then
4
-?!AMP?! echo very
4
+ echo very ?!AMP?!
5
echo empty
6
elif test -z ""
7
then
@@ -9,7 +9,7 @@
9
else
10
echo foo &&
11
cat
12
-?!AMP?! fi
12
+ fi ?!AMP?!
13
echo poodle
14
>) &&
15
(
t/chainlint/inline-comment.expect
+1
-1
@@ -1,6 +1,6 @@
1
(
2
foobar &&
3
-?!AMP?! barfoo
3
+ barfoo ?!AMP?!
4
flibble "not a # comment"
5
>) &&
6
t/chainlint/loop-in-if.expect
+3
-3
@@ -3,10 +3,10 @@
3
then
4
while true
5
do
6
-?!AMP?! echo "pop"
6
+ echo "pop" ?!AMP?!
7
echo "glup"
8
-?!AMP?! done
8
+ done ?!AMP?!
9
foo
10
-?!AMP?! fi
10
+ fi ?!AMP?!
11
bar
12
>)
t/chainlint/multi-line-string.expect
+1
-1
@@ -1,6 +1,6 @@
1
(
2
x="line 1 line 2 line 3" &&
3
-?!AMP?! y="line 1 line2"
3
+ y="line 1 line2" ?!AMP?!
4
foobar
5
>) &&
6
(
t/chainlint/nested-cuddled-subshell.expect
+3
-3
@@ -4,16 +4,16 @@
4
>> ) &&
5
(cd foo &&
6
bar
7
-?!AMP?!>> )
7
+>> ) ?!AMP?!
8
(
9
cd foo &&
10
>> bar) &&
11
(
12
cd foo &&
13
-?!AMP?!>> bar)
13
+>> bar) ?!AMP?!
14
(cd foo &&
15
>> bar) &&
16
(cd foo &&
17
-?!AMP?!>> bar)
17
+>> bar) ?!AMP?!
18
foobar
19
>)
t/chainlint/nested-here-doc.expect
+1
-1
@@ -2,6 +2,6 @@ cat >foop &&
2
3
(
4
cat &&
5
-?!AMP?! cat
5
+ cat ?!AMP?!
6
foobar
7
>)
t/chainlint/nested-subshell-comment.expect
+1
-1
@@ -6,6 +6,6 @@
6
# minor numbers of cows (or do they?)
7
baz &&
8
snaff
9
-?!AMP?!>> )
9
+>> ) ?!AMP?!
10
fuzzy
11
>)
t/chainlint/pipe.expect
+1
-1
@@ -3,6 +3,6 @@
3
bar |
4
baz &&
5
fish |
6
-?!AMP?! cow
6
+ cow ?!AMP?!
7
sunder
8
>)
t/chainlint/semicolon.expect
+1
-1
@@ -1,5 +1,5 @@
1
(
2
-?!AMP?!?!SEMI?! cat foo ; echo bar
2
+?!SEMI?! cat foo ; echo bar ?!AMP?!
3
?!SEMI?! cat foo ; echo bar
4
>) &&
5
(
t/chainlint/subshell-here-doc.expect
+1
-1
@@ -1,6 +1,6 @@
1
(
2
echo wobba gorgo snoot wafta snurb &&
3
-?!AMP?! cat >bip
3
+ cat >bip ?!AMP?!
4
echo >bop
5
>) &&
6
(
t/chainlint/subshell-one-liner.expect
+2
-2
@@ -8,7 +8,7 @@
8
(foo || exit 1) &&
9
(foo || exit 1) |
10
(foo || exit 1) >baz &&
11
-?!AMP?! (foo && bar)
12
-?!AMP?!?!SEMI?! (foo && bar; baz)
11
+ (foo && bar) ?!AMP?!
12
+?!SEMI?! (foo && bar; baz) ?!AMP?!
13
foobar
14
>)
t/chainlint/while-loop.expect
+2
-2
@@ -1,9 +1,9 @@
1
(
2
while true
3
do
4
-?!AMP?! echo foo
4
+ echo foo ?!AMP?!
5
cat
6
-?!AMP?! done
6
+ done ?!AMP?!
7
while true; do
8
echo foo &&
9
cat bar