]> git.ipfire.org Git - thirdparty/git.git/commitdiff
chainlint.sed: improve ?!AMP?! placement accuracy
authorEric Sunshine <sunshine@sunshineco.com>
Mon, 13 Dec 2021 06:30:50 +0000 (01:30 -0500)
committerJunio C Hamano <gitster@pobox.com>
Mon, 13 Dec 2021 22:15:29 +0000 (14:15 -0800)
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>
23 files changed:
t/chainlint.sed
t/chainlint/arithmetic-expansion.expect
t/chainlint/block.expect
t/chainlint/broken-chain.expect
t/chainlint/case.expect
t/chainlint/command-substitution.expect
t/chainlint/cuddled.expect
t/chainlint/for-loop.expect
t/chainlint/here-doc-multi-line-command-subst.expect
t/chainlint/here-doc-multi-line-string.expect
t/chainlint/if-in-loop.expect
t/chainlint/if-then-else.expect
t/chainlint/inline-comment.expect
t/chainlint/loop-in-if.expect
t/chainlint/multi-line-string.expect
t/chainlint/nested-cuddled-subshell.expect
t/chainlint/nested-here-doc.expect
t/chainlint/nested-subshell-comment.expect
t/chainlint/pipe.expect
t/chainlint/semicolon.expect
t/chainlint/subshell-here-doc.expect
t/chainlint/subshell-one-liner.expect
t/chainlint/while-loop.expect

index 8a25c5b855e7ea9d28d208a3302ecb68965f34b6..883a2b307c04639b36e2985638310b33677c8a8e 100644 (file)
@@ -236,7 +236,7 @@ s/.*\n//
 # line ends with pipe "...|" -- valid; not missing "&&"
 /|[    ]*$/bcont
 # missing end-of-line "&&" -- mark suspect
-/&&[   ]*$/!s/^/?!AMP?!/
+/&&[   ]*$/!s/$/ ?!AMP?!/
 :cont
 # retrieve and print previous line
 x
@@ -303,7 +303,7 @@ bcase
 # that line legitimately lacks "&&"
 :else
 x
-s/?!AMP?!//
+s/ ?!AMP?!$//
 x
 bcont
 
@@ -311,7 +311,7 @@ bcont
 # "suspect" from final contained line since that line legitimately lacks "&&"
 :done
 x
-s/?!AMP?!//
+s/ ?!AMP?!$//
 x
 # is 'done' or 'fi' cuddled with ")" to close subshell?
 /done.*)/bclose
@@ -354,7 +354,7 @@ bblock
 # since that line legitimately lacks "&&" and exit subshell loop
 :clssolo
 x
-s/?!AMP?!//
+s/ ?!AMP?!$//
 p
 x
 s/^/>/
index 09457d31966193da7a324f0cbc417ce05354f15a..56cd5b69f5b498328909e5b696b14bdf5e8a7f5a 100644 (file)
@@ -4,6 +4,6 @@
        baz
 >) &&
 (
-?!AMP?!        bar=$((42 + 1))
+       bar=$((42 + 1)) ?!AMP?!
        baz
 >)
index fed7e89ae8ffaec249c2a3a86a915979a34681f0..6333237cb2fdb87110da7be204a3cad86b8541ff 100644 (file)
@@ -7,6 +7,6 @@
        bar &&
        {
                echo c
-?!AMP?!        }
+       } ?!AMP?!
        baz
 >)
index 55b0f42a534d65caefa2089c16eff01fd00462c8..0960a8c7c0d9bcce977491c2056242fcdd6477a2 100644 (file)
@@ -1,6 +1,6 @@
 (
        foo &&
-?!AMP?!        bar
+       bar ?!AMP?!
        baz &&
        wop
 >)
index 41f121fbbf9c9664640fc81c3e9e4315dadd42c3..a4b92d46131c2953546e1744e143276a36b70202 100644 (file)
@@ -9,11 +9,11 @@
        case "$x" in
        x) foo ;;
        *) bar ;;
-?!AMP?!        esac
+       esac ?!AMP?!
        foobar
 >) &&
 (
        case "$x" in 1) true;; esac &&
-?!AMP?!        case "$y" in 2) false;; esac
+       case "$y" in 2) false;; esac ?!AMP?!
        foobar
 >)
index ad4118e537e42e1156146c11ce80f288381b1af3..f276067b7b3f299e1244a80c2d9ef7f352afccf7 100644 (file)
@@ -4,6 +4,6 @@
        baz
 >) &&
 (
-?!AMP?!        bar=$(gobble blocks)
+       bar=$(gobble blocks) ?!AMP?!
        baz
 >)
index b506d4622197a837c66ca56dd22cf7d191664e68..b6c4ed90a97a45806ce2b23b27e2e23b0c319369 100644 (file)
@@ -4,7 +4,7 @@ cd foo &&
 >) &&
 
 (
-?!AMP?!cd foo
+cd foo ?!AMP?!
        bar
 >) &&
 
@@ -17,5 +17,5 @@ cd foo &&
 >      bar) &&
 
 (
-?!AMP?!cd foo
+cd foo ?!AMP?!
 >      bar)
index c33cf56ee73ab7b75c4194d842443d019fa08440..dc209e21bdc73eeea2bae256852493a6b05c01c2 100644 (file)
@@ -1,9 +1,9 @@
 (
        for i in a b c
        do
-?!AMP?!                echo $i
+               echo $i ?!AMP?!
                cat
-?!AMP?!        done
+       done ?!AMP?!
        for i in a b c; do
                echo $i &&
                cat $i
index e5fb752d2fc22ac421704925a51fc952ecf530e1..3a35bb014cc29019d1fdfd04310084e3e144574c 100644 (file)
@@ -1,5 +1,5 @@
 (
        x=$(bobble &&
-?!AMP?!>>              wiffle)
+>>             wiffle) ?!AMP?!
        echo $x
 >)
index 32038a070c2ad881f7136028ceb1be41f57c9a43..a3b9a5472df07f7c439ab33419f64b5b06d993ec 100644 (file)
@@ -1,4 +1,4 @@
 (
-?!AMP?!        cat && echo "multi-line string"
+       cat && echo "multi-line string" ?!AMP?!
        bap
 >)
index 03d3ceb22d8971ddad5c81c1c5a7714d7f988f8e..7d918372695a7f4d4c45280bc7aa657f012adfdd 100644 (file)
@@ -3,10 +3,10 @@
        do
                if false
                then
-?!AMP?!                        echo "err"
+                       echo "err" ?!AMP?!
                        exit 1
-?!AMP?!                fi
+               fi ?!AMP?!
                foo
-?!AMP?!        done
+       done ?!AMP?!
        bar
 >)
index a80f5e6c75f73a8c6972f1acccfa9157749b4829..3055d5606c59298055ffa956a82c83a584064949 100644 (file)
@@ -1,7 +1,7 @@
 (
        if test -n ""
        then
-?!AMP?!                echo very
+               echo very ?!AMP?!
                echo empty
        elif test -z ""
        then
@@ -9,7 +9,7 @@
        else
                echo foo &&
                cat
-?!AMP?!        fi
+       fi ?!AMP?!
        echo poodle
 >) &&
 (
index fc9f250ac48e61c1555eea13bdea0c84f691dbb8..3d655a32b0b269879a239fec61c3b3ad061b558d 100644 (file)
@@ -1,6 +1,6 @@
 (
        foobar &&
-?!AMP?!        barfoo
+       barfoo ?!AMP?!
        flibble "not a # comment"
 >) &&
 
index 088e622c3141e1a298ba79c85aa274dfab90ee53..cebd3ae95e38c048fb44819e5ae334fc2081259f 100644 (file)
@@ -3,10 +3,10 @@
        then
                while true
                do
-?!AMP?!                        echo "pop"
+                       echo "pop" ?!AMP?!
                        echo "glup"
-?!AMP?!                done
+               done ?!AMP?!
                foo
-?!AMP?!        fi
+       fi ?!AMP?!
        bar
 >)
index 2829516495b73e7680bf0c650a6f53e4bcc37439..f1be2baf0af154a79f529c1e84e3b7d78a49ecc3 100644 (file)
@@ -1,6 +1,6 @@
 (
        x="line 1               line 2          line 3" &&
-?!AMP?!        y="line 1               line2"
+       y="line 1               line2" ?!AMP?!
        foobar
 >) &&
 (
index c2a59ffc335cb1c4ed7a30c7a59597de4f24ef91..aa522658edff1c45476cb7fe44d15c2064fbfd5c 100644 (file)
@@ -4,16 +4,16 @@
 >>     ) &&
        (cd foo &&
                bar
-?!AMP?!>>      )
+>>     ) ?!AMP?!
        (
                cd foo &&
 >>             bar) &&
        (
                cd foo &&
-?!AMP?!>>              bar)
+>>             bar) ?!AMP?!
        (cd foo &&
 >>             bar) &&
        (cd foo &&
-?!AMP?!>>              bar)
+>>             bar) ?!AMP?!
        foobar
 >)
index 0c9ef1cfc6959e1b4093200769b2401467e927ad..f9604d3facad8c6f3883e671e36a6be2723d7f93 100644 (file)
@@ -2,6 +2,6 @@ cat >foop &&
 
 (
        cat &&
-?!AMP?!        cat
+       cat ?!AMP?!
        foobar
 >)
index 15b68d437379d79ed563205e6246779bc84b967a..925e49bae9586bbcf0c791599c6c0ed2fece56cf 100644 (file)
@@ -6,6 +6,6 @@
                # minor numbers of cows (or do they?)
                baz &&
                snaff
-?!AMP?!>>      )
+>>     ) ?!AMP?!
        fuzzy
 >)
index 211b901dbc423086a6b6ebfa80a695f5f21b8929..ede6bcc6078e39f202a8205bc0b3777de59c58f4 100644 (file)
@@ -3,6 +3,6 @@
        bar |
        baz &&
        fish |
-?!AMP?!        cow
+       cow ?!AMP?!
        sunder
 >)
index 1d79384606d2a2f3d3ceb72a9cfaa3ee7adbc95e..ffc87bdffb33bdd43053e3ea149e1c18878eb184 100644 (file)
@@ -1,5 +1,5 @@
 (
-?!AMP?!?!SEMI?!        cat foo ; echo bar
+?!SEMI?!       cat foo ; echo bar ?!AMP?!
 ?!SEMI?!       cat foo ; echo bar
 >) &&
 (
index 7e057aee420395d0876139211b46d6439e5e43e4..9d3f25b3f57094a3f50264982f726d29caec8073 100644 (file)
@@ -1,6 +1,6 @@
 (
        echo wobba             gorgo snoot             wafta snurb &&
-?!AMP?!        cat >bip
+       cat >bip ?!AMP?!
        echo >bop
 >) &&
 (
index 51162821d7e146caf59f8c769da22ec5ca07047a..ec77aa5b95249cfd53af8e788e49914a0c978a92 100644 (file)
@@ -8,7 +8,7 @@
        (foo || exit 1) &&
        (foo || exit 1) |
        (foo || exit 1) >baz &&
-?!AMP?!        (foo && bar)
-?!AMP?!?!SEMI?!        (foo && bar; baz)
+       (foo && bar) ?!AMP?!
+?!SEMI?!       (foo && bar; baz) ?!AMP?!
        foobar
 >)
index 13cff2c0a511c6f81171f667a63632b78d387bad..f8b9fcf62b568a7c26ff49ad53db1e0a35e65ea4 100644 (file)
@@ -1,9 +1,9 @@
 (
        while true
        do
-?!AMP?!                echo foo
+               echo foo ?!AMP?!
                cat
-?!AMP?!        done
+       done ?!AMP?!
        while true; do
                echo foo &&
                cat bar