Open gdevenyi opened 5 years ago
Thanks for pointing these out. Some of these could indeed be errors.
I'll bring up the idea integrating this tool into our testing suite.
Until then though I think these won't be fixed, at least not the errors that are more opinionated rather than indicating bugs.
I'm a big fan of static analysis tools though so hopefully we can get this going on the repo. 👍
I agree some are opinions, and some are to avoid corner cases, but as LORIS gets more users, there will be more corner cases, so avoiding them with good hygiene is a start.
Followup, updated to shellcheck 0.7:
In ./test/integration.sh line 38:
l) url="$OPTARG"
^-^ SC2034: url appears unused. Verify use (or export if used externally).
In ./test/integration.sh line 52:
export LORIS_DB_CONFIG=$(pwd)/config.xml
^-------------^ SC2155: Declare and assign separately to avoid masking return values.
In ./test/integration.sh line 55:
php -S localhost:8000 -t ../htdocs ../htdocs/router.php 2>&1 > /dev/null &
^--^ SC2069: To redirect stdout+stderr, 2>&1 must be last (or use '{ cmd > file; } 2>&1' to clarify).
In ./test/integration.sh line 67:
mysql -h $host -D $database -u $username -p$password -e "UPDATE Config SET Value='http://localhost:8000' WHERE ConfigID=(SELECT ID FROM ConfigSettings WHERE Name='url')"
^---^ SC2086: Double quote to prevent globbing and word splitting.
^-------^ SC2086: Double quote to prevent globbing and word splitting.
^-------^ SC2086: Double quote to prevent globbing and word splitting.
^-------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
mysql -h "$host" -D "$database" -u "$username" -p"$password" -e "UPDATE Config SET Value='http://localhost:8000' WHERE ConfigID=(SELECT ID FROM ConfigSettings WHERE Name='url')"
In ./test/integration.sh line 69:
mysql -h $host -D $database -u $username -p$password -e "UPDATE Config SET Value='$(pwd | sed "s#test##")' WHERE ConfigID=(SELECT ID FROM ConfigSettings WHERE Name='base')"
^---^ SC2086: Double quote to prevent globbing and word splitting.
^-------^ SC2086: Double quote to prevent globbing and word splitting.
^-------^ SC2086: Double quote to prevent globbing and word splitting.
^-------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
mysql -h "$host" -D "$database" -u "$username" -p"$password" -e "UPDATE Config SET Value='$(pwd | sed "s#test##")' WHERE ConfigID=(SELECT ID FROM ConfigSettings WHERE Name='base')"
In ./test/integration.sh line 72:
if [ ! -z "$module" ]; then
^-- SC2236: Use -n instead of ! -z.
In ./test/integration.sh line 74:
echo Running integration test for module: $module;
^-----^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
echo Running integration test for module: "$module";
In ./test/integration.sh line 75:
../vendor/bin/phpunit --configuration phpunit.xml ../modules/$module/test
^-----^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
../vendor/bin/phpunit --configuration phpunit.xml ../modules/"$module"/test
For more information:
https://www.shellcheck.net/wiki/SC2034 -- url appears unused. Verify use (o...
https://www.shellcheck.net/wiki/SC2069 -- To redirect stdout+stderr, 2>&1 m...
https://www.shellcheck.net/wiki/SC2155 -- Declare and assign separately to ...
In ./test/wait-for-services.sh line 7:
cmd="$@"
^--^ SC2124: Assigning an array to a string! Assign as array, or use * instead of @ to concatenate.
In ./test/wait-for-services.sh line 16:
until $(curl --output /dev/null --silent --head --fail http://selenium:4444/wd/hub); do
^-- SC2091: Remove surrounding $() to avoid executing output.
For more information:
https://www.shellcheck.net/wiki/SC2091 -- Remove surrounding $() to avoid e...
https://www.shellcheck.net/wiki/SC2124 -- Assigning an array to a string! A...
In ./test/dockerized-integration-tests.sh line 11:
docker-compose run -T --rm ${CONTAINER} vendor/bin/phpunit --configuration test/phpunit.xml --testsuite LorisCoreIntegrationTests $*
^-- SC2048: Use "$@" (with quotes) to prevent whitespace problems.
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
docker-compose run -T --rm ${CONTAINER} vendor/bin/phpunit --configuration test/phpunit.xml --testsuite LorisCoreIntegrationTests "$*"
In ./test/dockerized-integration-tests.sh line 12:
docker-compose run -T --rm ${CONTAINER} vendor/bin/phpunit --configuration test/phpunit.xml --testsuite LorisModuleIntegrationTests $*
^-- SC2048: Use "$@" (with quotes) to prevent whitespace problems.
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
docker-compose run -T --rm ${CONTAINER} vendor/bin/phpunit --configuration test/phpunit.xml --testsuite LorisModuleIntegrationTests "$*"
For more information:
https://www.shellcheck.net/wiki/SC2048 -- Use "$@" (with quotes) to prevent...
https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...
In ./test/dockerized-unit-tests.sh line 11:
docker-compose run -T --rm ${CONTAINER} vendor/bin/phpunit --configuration test/phpunit.xml --testsuite LorisUnitTests $*
^-- SC2048: Use "$@" (with quotes) to prevent whitespace problems.
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
docker-compose run -T --rm ${CONTAINER} vendor/bin/phpunit --configuration test/phpunit.xml --testsuite LorisUnitTests "$*"
For more information:
https://www.shellcheck.net/wiki/SC2048 -- Use "$@" (with quotes) to prevent...
https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...
In ./test/run-php-linter.sh line 6:
for i in `ls php/libraries/*.class.inc modules/*/php/* modules/*/ajax/* htdocs/*.php htdocs/*/*.php`;
^-- SC2045: Iterating over ls output is fragile. Use globs.
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
Did you mean:
for i in $(ls php/libraries/*.class.inc modules/*/php/* modules/*/ajax/* htdocs/*.php htdocs/*/*.php);
In ./test/run-php-linter.sh line 8:
php -l $i >/dev/null || exit $?;
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
php -l "$i" >/dev/null || exit $?;
For more information:
https://www.shellcheck.net/wiki/SC2045 -- Iterating over ls output is fragi...
https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...
https://www.shellcheck.net/wiki/SC2006 -- Use $(...) notation instead of le...
In ./test/unittests.sh line 30:
export LORIS_DB_CONFIG=$(pwd)/config.xml
^-------------^ SC2155: Declare and assign separately to avoid masking return values.
In ./test/unittests.sh line 34:
echo Running Unit test: $1 in file $2;
^-- SC2086: Double quote to prevent globbing and word splitting.
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
echo Running Unit test: "$1" in file "$2";
In ./test/unittests.sh line 35:
../vendor/bin/phpunit --configuration phpunit.xml $1 $2
^-- SC2086: Double quote to prevent globbing and word splitting.
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
../vendor/bin/phpunit --configuration phpunit.xml "$1" "$2"
In ./test/unittests.sh line 38:
echo Running Unit test: $1;
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
echo Running Unit test: "$1";
In ./test/unittests.sh line 39:
../vendor/bin/phpunit --configuration phpunit.xml $1 ./unittests/$1.php
^-- SC2086: Double quote to prevent globbing and word splitting.
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
../vendor/bin/phpunit --configuration phpunit.xml "$1" ./unittests/"$1".php
For more information:
https://www.shellcheck.net/wiki/SC2155 -- Declare and assign separately to ...
https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...
In ./tools/deprecated/dump_all_tables_data_only.sh line 5:
GIT_MYSQL=/[BACKUP_LOCATION]
^-------^ SC2034: GIT_MYSQL appears unused. Verify use (or export if used externally).
^----------------^ SC2125: Brace expansions and globs are literal in assignments. Quote it or use an array.
^---------------^ SC2102: Ranges can only match single chars (mentioned due to duplicates).
In ./tools/deprecated/dump_all_tables_data_only.sh line 11:
for T in `mysql -N -B -e 'show tables'`;
^----------------------------^ SC2006: Use $(...) notation instead of legacy backticked `...`.
Did you mean:
for T in $(mysql -N -B -e 'show tables');
In ./tools/deprecated/dump_all_tables_data_only.sh line 14:
mysqldump $DATABASE --complete-insert --no-create-db --no-create-info --skip-opt --verbose --compact --add-locks $T | sed -E 's/LOCK TABLES (`[^`]+`)/TRUNCATE TABLE \1;\nLOCK TABLES \1/g' > ../../test/RBfiles/RB_$T.sql
^-- SC2086: Double quote to prevent globbing and word splitting.
^-- SC2016: Expressions don't expand in single quotes, use double quotes for that.
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
mysqldump $DATABASE --complete-insert --no-create-db --no-create-info --skip-opt --verbose --compact --add-locks "$T" | sed -E 's/LOCK TABLES (`[^`]+`)/TRUNCATE TABLE \1;\nLOCK TABLES \1/g' > ../../test/RBfiles/RB_"$T".sql
For more information:
https://www.shellcheck.net/wiki/SC2034 -- GIT_MYSQL appears unused. Verify ...
https://www.shellcheck.net/wiki/SC2125 -- Brace expansions and globs are li...
https://www.shellcheck.net/wiki/SC2016 -- Expressions don't expand in singl...
In ./tools/package_files.sh line 7:
eval $1=`sed -n -e "/$2/ { s/^[ \t\n]*//; s/[ \t\n]*$//; s#<[/]*$2>##gp }" ../project/config.xml`
^-- SC2086: Double quote to prevent globbing and word splitting.
^-- SC2046: Quote this to prevent word splitting.
^-- SC2006: Use $(...) notation instead of legacy backticked `...`.
Did you mean:
eval "$1"=$(sed -n -e "/$2/ { s/^[ \t\n]*//; s/[ \t\n]*$//; s#<[/]*$2>##gp }" ../project/config.xml)
In ./tools/package_files.sh line 12:
echo "Usage: $0 destination\n";
^-----------------------^ SC2028: echo may not expand escape sequences. Use printf.
In ./tools/package_files.sh line 15:
echo "$SavePath"
^-------^ SC2154: SavePath is referenced but not assigned.
In ./tools/package_files.sh line 16:
echo "$DownloadPath"
^-----------^ SC2154: DownloadPath is referenced but not assigned.
In ./tools/package_files.sh line 18:
cd $DownloadPath
^-----------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
cd "$DownloadPath"
In ./tools/package_files.sh line 19:
while read filename; do
^--^ SC2162: read without -r will mangle backslashes.
In ./tools/package_files.sh line 20:
tar rfv /tmp/$1.tar ./$filename
^-- SC2086: Double quote to prevent globbing and word splitting.
^-------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
tar rfv /tmp/"$1".tar ./"$filename"
In ./tools/package_files.sh line 26:
gzip -n /tmp/$1.tar;
^-- SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
gzip -n /tmp/"$1".tar;
In ./tools/package_files.sh line 27:
mv /tmp/$1.tar.gz $SavePath
^-- SC2086: Double quote to prevent globbing and word splitting.
^-------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
mv /tmp/"$1".tar.gz "$SavePath"
For more information:
https://www.shellcheck.net/wiki/SC2046 -- Quote this to prevent word splitt...
https://www.shellcheck.net/wiki/SC2154 -- DownloadPath is referenced but no...
https://www.shellcheck.net/wiki/SC2028 -- echo may not expand escape sequen...
In ./tools/install.sh line 21:
START=`date "+%Y-%m-%dT%H:%M:%S"`
^-------------------------^ SC2006: Use $(...) notation instead of legacy backticked `...`.
Did you mean:
START=$(date "+%Y-%m-%dT%H:%M:%S")
In ./tools/install.sh line 26:
trap "rm -f $LOGPIPE" EXIT
^------^ SC2064: Use single quotes, otherwise this expands now rather than when signalled.
In ./tools/install.sh line 27:
tee -a <$LOGPIPE $LOGFILE &
^------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
tee -a <$LOGPIPE "$LOGFILE" &
In ./tools/install.sh line 30:
CWD=`pwd`
^---^ SC2006: Use $(...) notation instead of legacy backticked `...`.
Did you mean:
CWD=$(pwd)
In ./tools/install.sh line 31:
RootDir=`dirname $CWD`
^------------^ SC2006: Use $(...) notation instead of legacy backticked `...`.
^--^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
RootDir=$(dirname "$CWD")
In ./tools/install.sh line 43:
read -p "Do you still want to continue? [yn] " yn
^--^ SC2162: read without -r will mangle backslashes.
In ./tools/install.sh line 44:
echo $yn | tee -a $LOGFILE > /dev/null
^-^ SC2086: Double quote to prevent globbing and word splitting.
^------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
echo "$yn" | tee -a "$LOGFILE" > /dev/null
In ./tools/install.sh line 67:
if ! [ $BASH ] ; then
^---^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
if ! [ "$BASH" ] ; then
In ./tools/install.sh line 72:
if [[ -n $(which php) ]]; then
^---^ SC2230: which is non-standard. Use builtin 'command -v' instead.
In ./tools/install.sh line 81:
if [[ -n $(which composer) ]]; then
^---^ SC2230: which is non-standard. Use builtin 'command -v' instead.
In ./tools/install.sh line 118:
read -p "Ready to continue? [yn] " yn
^--^ SC2162: read without -r will mangle backslashes.
In ./tools/install.sh line 119:
echo $yn | tee -a $LOGFILE > /dev/null
^-^ SC2086: Double quote to prevent globbing and word splitting.
^------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
echo "$yn" | tee -a "$LOGFILE" > /dev/null
In ./tools/install.sh line 133:
read -p "Enter project name: " projectname
^--^ SC2162: read without -r will mangle backslashes.
In ./tools/install.sh line 134:
echo $projectname | tee -a $LOGFILE > /dev/null
^----------^ SC2086: Double quote to prevent globbing and word splitting.
^------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
echo "$projectname" | tee -a "$LOGFILE" > /dev/null
In ./tools/install.sh line 137:
read -p "Enter project name: " projectname
^--^ SC2162: read without -r will mangle backslashes.
In ./tools/install.sh line 163:
if [[ " ${debian[*]} " =~ " $os_distro " ]]; then
^------------^ SC2076: Don't quote right-hand side of =~, it'll match literally rather than as a regex.
In ./tools/install.sh line 173:
elif [[ " ${redhat[*]} " =~ " $os_distro " ]]; then
^------------^ SC2076: Don't quote right-hand side of =~, it'll match literally rather than as a regex.
In ./tools/install.sh line 191:
if [[ " ${debian[*]} " =~ " $os_distro " ]]; then
^------------^ SC2076: Don't quote right-hand side of =~, it'll match literally rather than as a regex.
In ./tools/install.sh line 193:
elif [[ " ${redhat[*]} " =~ " $os_distro " ]]; then
^------------^ SC2076: Don't quote right-hand side of =~, it'll match literally rather than as a regex.
In ./tools/install.sh line 203:
eval $composer_scr
^-----------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
eval "$composer_scr"
In ./tools/install.sh line 207:
if [[ " ${debian[*]} " =~ " $os_distro " ]]; then
^------------^ SC2076: Don't quote right-hand side of =~, it'll match literally rather than as a regex.
In ./tools/install.sh line 212:
read -p "Would you like to automatically create/install apache config files? (Works for Ubuntu 14.04 or later default Apache installations) [yn] " yn
^--^ SC2162: read without -r will mangle backslashes.
In ./tools/install.sh line 213:
echo $yn | tee -a $LOGFILE > /dev/null
^-^ SC2086: Double quote to prevent globbing and word splitting.
^------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
echo "$yn" | tee -a "$LOGFILE" > /dev/null
In ./tools/install.sh line 216:
if [ -f /etc/apache2/sites-available/$projectname ]; then
^----------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
if [ -f /etc/apache2/sites-available/"$projectname" ]; then
In ./tools/install.sh line 217:
echo "Apache appears to already be configured for $projectname. Aborting\n"
^-- SC2028: echo may not expand escape sequences. Use printf.
In ./tools/install.sh line 224:
< ../docs/config/apache2-site | sudo tee /etc/apache2/sites-available/$projectname.conf > /dev/null
^----------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
< ../docs/config/apache2-site | sudo tee /etc/apache2/sites-available/"$projectname".conf > /dev/null
In ./tools/install.sh line 225:
sudo ln -s /etc/apache2/sites-available/$projectname.conf /etc/apache2/sites-enabled/$projectname.conf
^----------^ SC2086: Double quote to prevent globbing and word splitting.
^----------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
sudo ln -s /etc/apache2/sites-available/"$projectname".conf /etc/apache2/sites-enabled/"$projectname".conf
In ./tools/install.sh line 227:
sudo a2ensite $projectname.conf
^----------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
sudo a2ensite "$projectname".conf
In ./tools/install.sh line 237:
elif [[ " ${redhat[*]} " =~ " $os_distro " ]]; then
^------------^ SC2076: Don't quote right-hand side of =~, it'll match literally rather than as a regex.
In ./tools/install.sh line 242:
read -p "Would you like to automatically create/install apache config files? (In development for CentOS 6.5) [yn] " yn
^--^ SC2162: read without -r will mangle backslashes.
In ./tools/install.sh line 243:
echo $yn | tee -a $LOGFILE > /dev/null
^-^ SC2086: Double quote to prevent globbing and word splitting.
^------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
echo "$yn" | tee -a "$LOGFILE" > /dev/null
In ./tools/install.sh line 246:
if [ -f /etc/httpd/conf.d/$projectname ]; then
^----------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
if [ -f /etc/httpd/conf.d/"$projectname" ]; then
In ./tools/install.sh line 247:
echo "Apache appears to already be configured for $projectname. Aborting\n"
^-- SC2028: echo may not expand escape sequences. Use printf.
In ./tools/install.sh line 255:
< ../docs/config/apache2-site | sudo tee /etc/httpd/conf.d/$projectname.conf > /dev/null
^----------^ SC2086: Double quote to prevent globbing and word splitting.
Did you mean:
< ../docs/config/apache2-site | sudo tee /etc/httpd/conf.d/"$projectname".conf > /dev/null
For more information:
https://www.shellcheck.net/wiki/SC2076 -- Don't quote right-hand side of =~...
https://www.shellcheck.net/wiki/SC2064 -- Use single quotes, otherwise this...
https://www.shellcheck.net/wiki/SC2028 -- echo may not expand escape sequen...
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Shellcheck exposes a number of (possible) errors in shell scripts shipped with LORIS.