Enable some simple ShellCheck rules.
Note for reviewers: bash and shellcheck on macOS are different from ones on Ubuntu.
For local tests the latest shellcheck version 0.6.0 should be used (see #15166).
Forgot about macOS quirks (#14115). Going to fix right now.
Forgot about macOS quirks (#14115). Going to fix right now.
Fixed. OP updated with a note for reviewers.
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
ACK https://github.com/bitcoin/bitcoin/pull/16327/commits/077b62ec53bc2a892218e6f1311b3cbf0dc7daf6 test/lint/lint-shell.sh passes on macOS 10.14.5
I was wrong: the 05fa54d56b8ed61925c0a7b58d505130162263df commit is misleading. There is nothing macOS specific in SC1087, SC2206, SC2207, SC2230 and SC2236 warnings.
The point is the default shellcheck version on bionic is:
$ /usr/bin/shellcheck -V | grep version:
version: 0.4.6
But we use version 0.6.0 (see #15166).
The misleading commit will be removed today.
Strong concept ACK:
As an active reviewer of all shell scripts added to the project I applaud this change: it will make sure more of the bugs introduced due to "language level misunderstandings" are fixed before human review takes place. That is clearly a good thing.
Case in point: This change fixes such a bug/misunderstanding in contrib/verify-commits/gpg.sh.
6 | @@ -7,10 +7,11 @@ export LC_ALL=C 7 | set -e 8 | srcdir="$(dirname $0)" 9 | cd "$srcdir" 10 | +# shellcheck disable=SC2230 11 | if [ -z ${LIBTOOLIZE} ] && GLIBTOOLIZE="`which glibtoolize 2>/dev/null`"; then
Does command -v work here?
Yes, it does. Going to fix tonight.
Also in command -v 2>/dev/null the 2>/dev/null is redundant, right?
85 | @@ -86,18 +86,23 @@ fi 86 | WGETOUT=$(wget -N "$HOST1$BASEDIR$SIGNATUREFILENAME" 2>&1) 87 | 88 | #and then see if wget completed successfully 89 | +# shellcheck disable=SC2181 90 | if [ $? -ne 0 ]; then
I believe we can just do:
if ! WGETOUT=$(wget -N "$HOST1$BASEDIR$SIGNATUREFILENAME" 2>&1); then
Fixed.
utACK e8683bf3e08c4fbc8c4159decaaa40134dac1eb5
Strongly in favor of stricter linting with shellcheck for shell scripts. They can be very hard to debug or fail silently if they're not.
When @dongcarl's comments are addressed I think these changes should be ready to go. One last thing:
These tests remain disabled after this PR:
SC2006 # Use $(..) instead of legacy `..`.
SC2046 # Quote this to prevent word splitting.
SC2086 # Double quote to prevent globbing and word splitting.
SC2162 # read without -r will mangle backslashes.
I think it makes sense to keep these disabled with one exception:
@hebasto Would it be feasible to also enable SC2006?
Given the problems with the legacy form and the fact that all of these problems can be avoided by simply switching to $(…) I think it is worth having shellcheck guiding PR authors. That way human reviews don't have to repeat the arguments below :-)
Quoting shellcheck:
$(...) notation instead of legacy backticked `...`.echo "You are running on `uname`"
echo "You are running on $(uname)"
Backtick command substitution `...` is legacy syntax with several issues.
$(...) command substitution has none of these problems, and is therefore strongly encouraged.
None.
utACK 4dd301824bf6bc646210240884db8d9c869c4874 modulo squash + @dongcarl's comment about shellcheck disable=SC2181
@hebasto Title "Enable shellcheck rules" and description could be the squashed messages? :-)
Very nice!
utACK cb2f23d55f7b8ff27719561fc446fa5a9b9657c7
Enabled ShellCheck rules:
SC1087
SC2001
SC2004
SC2005
SC2006
SC2016
SC2028
SC2048
SC2066 (note that IFS already contains only a line feed)
SC2116
SC2166
SC2181
SC2206
SC2207
SC2230
SC2236
@practicalswift the rules in commit message are ordered now.
utACK 1ac454a3844b9b8389de0f660fa9455c0efa7140
utACK 1ac454a
ACK 1ac454a3844b9b8389de0f660fa9455c0efa7140
Tested ./autogen.sh, contrib/install_db4.sh, contrib/devtools/gen-manpages.sh, contrib/verify-commits/gpg.sh, contrib/verifybinaries/verify.sh bitcoin-core-0.18.0 all still work. test/lint/lint-all.sh seems to pass.