Skip to content

Commit 561b46c

Browse files
jrngitster
authored andcommitted
test-lint: find unportable sed, echo, test, and export usage after &&
Instead of anchoring these checks with "^\s*", just check that the usage is preceded by a word boundary. So now we can catch test $cond && export foo=bar just like we already catch test $cond && export foo=bar As a side effect, this will detect usage of "sed -i", "echo -n", "test a == b", and "export a=b" in comments. That is not ideal but it's potentially useful because people sometimes copy code from comments so it can be good to also avoid nonportable patterns there. To avoid false positives, keep the checks for 'declare' and 'which' anchored. Those are frequently used words in normal English-language comments. Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7bbc4e8 commit 561b46c

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

t/check-non-portable-shell.pl

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ sub err {
1616

1717
while (<>) {
1818
chomp;
19-
/^\s*sed\s+-i/ and err 'sed -i is not portable';
20-
/^\s*echo\s+-n/ and err 'echo -n is not portable (please use printf)';
19+
/\bsed\s+-i/ and err 'sed -i is not portable';
20+
/\becho\s+-n/ and err 'echo -n is not portable (please use printf)';
2121
/^\s*declare\s+/ and err 'arrays/declare not portable';
2222
/^\s*[^#]\s*which\s/ and err 'which is not portable (please use type)';
23-
/test\s+[^=]*==/ and err '"test a == b" is not portable (please use =)';
24-
/^\s*export\s+[^=]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)';
23+
/\btest\s+[^=]*==/ and err '"test a == b" is not portable (please use =)';
24+
/\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)';
2525
# this resets our $. for each file
2626
close ARGV if eof;
2727
}

0 commit comments

Comments
 (0)