Switches to using git ls-files instead of a hardcoded list of scripts to lint (shellcheck doesn't support recursively scanning for scripts itself). This means a few files that were not previously linted now are, so need fixes.
Adds a .shellcheckrc which is used to enable optional shellcheck checks via enable=all. Most of these checks either already passed or have been fixed in this PR - however, a few others need a closer look so have been disabled for now to reduce the size of this PR.
As part of doing this I discovered an NLTK bug with setting NLTK_DATA after #1595, which has now been fixed. Since that change was not yet released, I've not mentioned the fix here in the changelog.
Shellcheck's optional checks as of v0.10.0:
$ shellcheck --list-optional
name: add-default-case
desc: Suggest adding a default case in `case` statements
example: case $? in 0) echo 'Success';; esac
fix: case $? in 0) echo 'Success';; *) echo 'Fail' ;; esac
name: avoid-nullary-conditions
desc: Suggest explicitly using -n in `[ $var ]`
example: [ "$var" ]
fix: [ -n "$var" ]
name: check-extra-masked-returns
desc: Check for additional cases where exit codes are masked
example: rm -r "$(get_chroot_dir)/home"
fix: set -e; dir="$(get_chroot_dir)"; rm -r "$dir/home"
name: check-set-e-suppressed
desc: Notify when set -e is suppressed during function invocation
example: set -e; func() { cp *.txt ~/backup; rm *.txt; }; func && echo ok
fix: set -e; func() { cp *.txt ~/backup; rm *.txt; }; func; echo ok
name: check-unassigned-uppercase
desc: Warn when uppercase variables are unassigned
example: echo $VAR
fix: VAR=hello; echo $VAR
name: deprecate-which
desc: Suggest 'command -v' instead of 'which'
example: which javac
fix: command -v javac
name: quote-safe-variables
desc: Suggest quoting variables without metacharacters
example: var=hello; echo $var
fix: var=hello; echo "$var"
name: require-double-brackets
desc: Require [[ and warn about [ in Bash/Ksh
example: [ -e /etc/issue ]
fix: [[ -e /etc/issue ]]
name: require-variable-braces
desc: Suggest putting braces around all variable references
example: var=hello; echo $var
fix: var=hello; echo ${var}
git ls-files
instead of a hardcoded list of scripts to lint (shellcheck doesn't support recursively scanning for scripts itself). This means a few files that were not previously linted now are, so need fixes..shellcheckrc
which is used to enable optional shellcheck checks viaenable=all
. Most of these checks either already passed or have been fixed in this PR - however, a few others need a closer look so have been disabled for now to reduce the size of this PR.NLTK_DATA
after #1595, which has now been fixed. Since that change was not yet released, I've not mentioned the fix here in the changelog.Shellcheck's optional checks as of v0.10.0:
See also: https://github.com/koalaman/shellcheck/blob/master/shellcheck.1.md