chainlint.sed: improve ?!SEMI?! placement accuracy
When chainlint.sed detects commands separated by a semicolon rather than by `&&`, it places a ?!SEMI?! 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 ?!SEMI?! annotation to the location of the semicolon 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
fbd992b61b3acb6ce235d678bfe65a60c503dddd
5 files changed
+18
-18
t/chainlint.sed
+2
-2
@@ -126,7 +126,7 @@ b
126
# "&&" (but not ";" in a string)
127
:oneline
128
/;/{
129
- /"[^"]*;[^"]*"/!s/^/?!SEMI?!/
129
+ /"[^"]*;[^"]*"/!s/;/; ?!SEMI?!/
130
}
131
b
132
@@ -230,7 +230,7 @@ s/.*\n//
230
# string and not ";;" in one-liner "case...esac")
231
/;/{
232
/;;/!{
233
- /"[^"]*;[^"]*"/!s/^/?!SEMI?!/
233
+ /"[^"]*;[^"]*"/!s/;/; ?!SEMI?!/
234
}
235
}
236
# line ends with pipe "...|" -- valid; not missing "&&"
t/chainlint/negated-one-liner.expect
+2
-2
@@ -1,5 +1,5 @@
1
! (foo && bar) &&
2
! (foo && bar) >baz &&
3
4
-?!SEMI?!! (foo; bar) &&
5
-?!SEMI?!! (foo; bar) >baz
4
+! (foo; ?!SEMI?! bar) &&
5
+! (foo; ?!SEMI?! bar) >baz
t/chainlint/one-liner.expect
+3
-3
@@ -2,8 +2,8 @@
2
(foo && bar) |
3
(foo && bar) >baz &&
4
5
-?!SEMI?!(foo; bar) &&
6
-?!SEMI?!(foo; bar) |
7
-?!SEMI?!(foo; bar) >baz &&
5
+(foo; ?!SEMI?! bar) &&
6
+(foo; ?!SEMI?! bar) |
7
+(foo; ?!SEMI?! bar) >baz &&
8
9
(foo "bar; baz")
t/chainlint/semicolon.expect
+7
-7
@@ -1,20 +1,20 @@
1
(
2
-?!SEMI?! cat foo ; echo bar ?!AMP?!
3
-?!SEMI?! cat foo ; echo bar
2
+ cat foo ; ?!SEMI?! echo bar ?!AMP?!
3
+ cat foo ; ?!SEMI?! echo bar
4
>) &&
5
(
6
-?!SEMI?! cat foo ; echo bar &&
7
-?!SEMI?! cat foo ; echo bar
6
+ cat foo ; ?!SEMI?! echo bar &&
7
+ cat foo ; ?!SEMI?! echo bar
8
>) &&
9
(
10
echo "foo; bar" &&
11
-?!SEMI?! cat foo; echo bar
11
+ cat foo; ?!SEMI?! echo bar
12
>) &&
13
(
14
-?!SEMI?! foo;
14
+ foo; ?!SEMI?!
15
>) &&
16
(
17
cd foo &&
18
for i in a b c; do
19
-?!SEMI?! echo;
19
+ echo; ?!SEMI?!
20
> done)
t/chainlint/subshell-one-liner.expect
+4
-4
@@ -2,13 +2,13 @@
2
(foo && bar) &&
3
(foo && bar) |
4
(foo && bar) >baz &&
5
-?!SEMI?! (foo; bar) &&
6
-?!SEMI?! (foo; bar) |
7
-?!SEMI?! (foo; bar) >baz &&
5
+ (foo; ?!SEMI?! bar) &&
6
+ (foo; ?!SEMI?! bar) |
7
+ (foo; ?!SEMI?! bar) >baz &&
8
(foo || exit 1) &&
9
(foo || exit 1) |
10
(foo || exit 1) >baz &&
11
(foo && bar) ?!AMP?!
12
-?!SEMI?! (foo && bar; baz) ?!AMP?!
12
+ (foo && bar; ?!SEMI?! baz) ?!AMP?!
13
foobar
14
>)