Skip to content
Snippets Groups Projects
Commit 8146dbc1 authored by wkwk's avatar wkwk
Browse files

Do a shellcheck / shfmt run on shellscripts

Fix SC2145: Argument mixes string and array. Use * or separate argument.
Fix SC2162: read without -r will mangle backslashes.
Fix SC2086: Double quote to prevent globbing and word splitting.
Fix SC2164: Use 'cd ... || exit' or 'cd ... || return' in case cd fails.
parent 6d5fce27
No related branches found
No related tags found
No related merge requests found
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
output=/dev/stdout output=/dev/stdout
# displays help text # displays help text
function displayHelp { function displayHelp() {
cat << HelpText cat <<HelpText
Usage: compile.sh [OPTION]... Usage: compile.sh [OPTION]...
Options: Options:
...@@ -17,17 +17,17 @@ HelpText ...@@ -17,17 +17,17 @@ HelpText
} }
#display an error message #display an error message
function echoError { function echoError() {
echo -e "\033[0;31m$@\033[0m" echo -e "\033[0;31m$*\033[0m"
} }
#display message #display message
function echoMessage { function echoMessage() {
echo "$1" > "${output}" echo "$1" >"${output}"
} }
#compile the HTML file #compile the HTML file
function compile { function compile() {
mkdir -p bin/resources mkdir -p bin/resources
export TWEEGO_PATH=devTools/tweeGo/storyFormats export TWEEGO_PATH=devTools/tweeGo/storyFormats
TWEEGO_EXE="tweego" TWEEGO_EXE="tweego"
...@@ -36,30 +36,31 @@ function compile { ...@@ -36,30 +36,31 @@ function compile {
echoMessage "system tweego binary" echoMessage "system tweego binary"
else else
case "$(uname -m)" in case "$(uname -m)" in
x86_64|amd64) x86_64 | amd64)
echoMessage "x64 arch" echoMessage "x64 arch"
if [ "$(uname -s)" = "Darwin" ]; then if [ "$(uname -s)" = "Darwin" ]; then
TWEEGO_EXE="./devTools/tweeGo/tweego_osx64" TWEEGO_EXE="./devTools/tweeGo/tweego_osx64"
elif [ $OSTYPE = "msys" ]; then elif [ "$OSTYPE" = "msys" ]; then
TWEEGO_EXE="./devTools/tweeGo/tweego_win64" TWEEGO_EXE="./devTools/tweeGo/tweego_win64"
else else
TWEEGO_EXE="./devTools/tweeGo/tweego_nix64" TWEEGO_EXE="./devTools/tweeGo/tweego_nix64"
fi fi
;; ;;
x86|i[3-6]86) x86 | i[3-6]86)
echoMessage "x86 arch" echoMessage "x86 arch"
if [ "$(uname -s)" = "Darwin" ]; then if [ "$(uname -s)" = "Darwin" ]; then
TWEEGO_EXE="./devTools/tweeGo/tweego_osx86" TWEEGO_EXE="./devTools/tweeGo/tweego_osx86"
elif [ $OSTYPE = "msys" ]; then elif [ "$OSTYPE" = "msys" ]; then
TWEEGO_EXE="./devTools/tweeGo/tweego_win86" TWEEGO_EXE="./devTools/tweeGo/tweego_win86"
else else
TWEEGO_EXE="./devTools/tweeGo/tweego_nix86" TWEEGO_EXE="./devTools/tweeGo/tweego_nix86"
fi fi
;; ;;
*) *)
echoError "No system tweego binary found, and no precompiled binary for your platform available." echoError "No system tweego binary found, and no precompiled binary for your platform available."
echoError "Please compile tweego and put the executable in PATH." echoError "Please compile tweego and put the executable in PATH."
exit 2 exit 2
;;
esac esac
fi fi
...@@ -78,8 +79,7 @@ function compile { ...@@ -78,8 +79,7 @@ function compile {
devTools/concatFiles.sh js/ '*.js' bin/fc.js devTools/concatFiles.sh js/ '*.js' bin/fc.js
$TWEEGO_EXE -o $file --module=bin/fc.js --head devTools/head.html src/ || build_failed="true" $TWEEGO_EXE -o $file --module=bin/fc.js --head devTools/head.html src/ || build_failed="true"
rm -f bin/fc.js rm -f bin/fc.js
if [ "$build_failed" = "true" ] if [ "$build_failed" = "true" ]; then
then
echoError "Build failed." echoError "Build failed."
exit 1 exit 1
fi fi
...@@ -97,29 +97,29 @@ if [[ "$1" == "" ]]; then ...@@ -97,29 +97,29 @@ if [[ "$1" == "" ]]; then
echoMessage "For more options see compile.sh -h." echoMessage "For more options see compile.sh -h."
else else
#parse options #parse options
while [[ "$1" ]] while [[ "$1" ]]; do
do
case $1 in case $1 in
-d|--dry) -d | --dry)
dry="true" dry="true"
;; ;;
-g|--git) -g | --git)
usehash="true" usehash="true"
;; ;;
-h|--help) -h | --help)
displayHelp displayHelp
exit 0 exit 0
;; ;;
-s|--sanity) -s | --sanity)
sanity="true" sanity="true"
;; ;;
-q|--quiet) -q | --quiet)
output=/dev/null output=/dev/null
;; ;;
*) *)
echoError "Unknown argument $1." echoError "Unknown argument $1."
displayHelp displayHelp
exit 1 exit 1
;;
esac esac
shift shift
done done
......
...@@ -8,7 +8,7 @@ fi ...@@ -8,7 +8,7 @@ fi
WARNING='\033[93m' WARNING='\033[93m'
myprint() { myprint() {
while read data; do while read -r data; do
echo -n -e "[$1]$WARNING" echo -n -e "[$1]$WARNING"
echo "$data" echo "$data"
done done
...@@ -25,17 +25,17 @@ $GREP "<<[^\"<>]*\"[^\"<>]*>>" -- 'src/*' | myprint "MissingSpeechMark" ...@@ -25,17 +25,17 @@ $GREP "<<[^\"<>]*\"[^\"<>]*>>" -- 'src/*' | myprint "MissingSpeechMark"
# Check for missing ". e.g.: <<if $foo = "hello) # Check for missing ". e.g.: <<if $foo = "hello)
$GREP -e "<<[^\"<>]*\([^\"<>]*\"[^><\"]*\"\| [<>] \)*\"\([^\"<>]*\"[^><\"]*\"\| [<>] \)*\([^\"<>]\| [<>] \)*>>" --and --not -e "*[^']*" -- 'src/*' | myprint "MissingSpeechMark2" $GREP -e "<<[^\"<>]*\([^\"<>]*\"[^><\"]*\"\| [<>] \)*\"\([^\"<>]*\"[^><\"]*\"\| [<>] \)*\([^\"<>]\| [<>] \)*>>" --and --not -e "*[^']*" -- 'src/*' | myprint "MissingSpeechMark2"
# Check for colors like: @@color:red - should be @@.red # Check for colors like: @@color:red - should be @@.red
$GREP -e "@@color:" --and --not -e "@@color:rgb([0-9 ]\+,[0-9 ]\+,[0-9 ]\+)" -- "src/*" | myprint "UseCSSColors" $GREP -e "@@color:" --and --not -e "@@color:rgb([0-9 ]\+,[0-9 ]\+,[0-9 ]\+)" -- "src/*" | myprint "UseCSSColors"
# Check for missing $ in activeSlave or PC # Check for missing $ in activeSlave or PC
$GREP "<<[ ]*[^\$><_\[]*\(activeSlave\|PC\)[.]" -- "src/*" | myprint "MissingDollar" $GREP "<<[ ]*[^\$><_\[]*\(activeSlave\|PC\)[.]" -- "src/*" | myprint "MissingDollar"
# Check for closing bracket without opening bracket. e.g.: <<if foo)>> (but <<case "foo")>> is valid, so ignore those # Check for closing bracket without opening bracket. e.g.: <<if foo)>> (but <<case "foo")>> is valid, so ignore those
$GREP -e "<<[ a-zA-Z]\+\([^()<>]\|[^()<>][<>][^()<>]\)*)" --and --not -e "<< *case" -- "src/*" | myprint "MissingOpeningBracket" $GREP -e "<<[ a-zA-Z]\+\([^()<>]\|[^()<>][<>][^()<>]\)*)" --and --not -e "<< *case" -- "src/*" | myprint "MissingOpeningBracket"
# Check for opening bracket without closing bracket. e.g.: <<if (foo>> # Check for opening bracket without closing bracket. e.g.: <<if (foo>>
$GREP -e "<<[ a-zA-Z]\([^<>]\|[^<>][<>][^<>]\)\+(\([^()<>]\|[^<>()][<>][^<>()]\|([^<>()]*])\)*>>" -- "src/*" | myprint "MissingClosingBracket" $GREP -e "<<[ a-zA-Z]\([^<>]\|[^<>][<>][^<>]\)\+(\([^()<>]\|[^<>()][<>][^<>()]\|([^<>()]*])\)*>>" -- "src/*" | myprint "MissingClosingBracket"
# Check for two closing brackets but one opening bracket. e.g.: <<if (foo))>> # Check for two closing brackets but one opening bracket. e.g.: <<if (foo))>>
$GREP -e "<<[ a-zA-Z]\+[^()<>]*([^()]*)[^()]*)[^()<>]*>>" -- "src/*" | myprint "MissingOpeningBracket2" $GREP -e "<<[ a-zA-Z]\+[^()<>]*([^()]*)[^()]*)[^()<>]*>>" -- "src/*" | myprint "MissingOpeningBracket2"
# Check for one closing bracket but two opening brackets. e.g.: <<if ((foo)>> # Check for one closing bracket but two opening brackets. e.g.: <<if ((foo)>>
$GREP -e "<<[ a-zA-Z]\+[^()<>]*([^()]*([^()]*)[^()<>]*>>" -- "src/*" | myprint "MissingClosingBracket2" $GREP -e "<<[ a-zA-Z]\+[^()<>]*([^()]*([^()]*)[^()<>]*>>" -- "src/*" | myprint "MissingClosingBracket2"
$GREP -e "<<.*[(][^<>)]*[(][^<>)]*)\?[^<>)]*>>" -- "src/*" | myprint "MissingClosingBracket3" $GREP -e "<<.*[(][^<>)]*[(][^<>)]*)\?[^<>)]*>>" -- "src/*" | myprint "MissingClosingBracket3"
# Check for too many >>>. e.g.: <</if>>> # Check for too many >>>. e.g.: <</if>>>
$GREP "<<[^<>]*[<>]\?[^<>]*>>>" -- "src/*.tw" | myprint "TooManyAngleBrackets" $GREP "<<[^<>]*[<>]\?[^<>]*>>>" -- "src/*.tw" | myprint "TooManyAngleBrackets"
...@@ -50,7 +50,7 @@ $GREP "<<else >\?[^>]" -- 'src/*' | myprint "ShouldBeElseIf" ...@@ -50,7 +50,7 @@ $GREP "<<else >\?[^>]" -- 'src/*' | myprint "ShouldBeElseIf"
# Check, e.g., =to # Check, e.g., =to
$GREP "=to" -- 'src/*' | myprint "EqualAndTo" $GREP "=to" -- 'src/*' | myprint "EqualAndTo"
# Check doing $slaves.foo instead of $slaves[i].foo # Check doing $slaves.foo instead of $slaves[i].foo
$GREP -e "[$]slaves[.]" --and --not -e '[$]slaves[.]\(length\|random\|map\|filter\|deleteAt\|push\|find\|includes\|delete\|forEach\)' -- 'src/*' | myprint "MissingSlavesIndex" $GREP -e "[$]slaves[.]" --and --not -e '[$]slaves[.]\(length\|random\|map\|filter\|deleteAt\|push\|find\|includes\|delete\|forEach\)' -- 'src/*' | myprint "MissingSlavesIndex"
# Try to check for accidentally mixing slaves[] and activeSlave. This can have a lot of false matches, but has caught a lot of bugs so it's worth the pain # Try to check for accidentally mixing slaves[] and activeSlave. This can have a lot of false matches, but has caught a lot of bugs so it's worth the pain
$GREP -e "activeSlave[.]" --and -e "slaves\[..\?\][.]" --and --not -e '[.]ID' --and --not -e 'slaves\[..\?\][.]\(slaveName\|slaveSurname\|actualAge\|relation\|assignment\|age\|devotion\|trust\|vagina\|mother\|father\|training\)' -- 'src/*' | myprint "MaybeAccidentalMixingOfSlavesAndActiveSlave" $GREP -e "activeSlave[.]" --and -e "slaves\[..\?\][.]" --and --not -e '[.]ID' --and --not -e 'slaves\[..\?\][.]\(slaveName\|slaveSurname\|actualAge\|relation\|assignment\|age\|devotion\|trust\|vagina\|mother\|father\|training\)' -- 'src/*' | myprint "MaybeAccidentalMixingOfSlavesAndActiveSlave"
# Check, e.g. <<set foo == 4>> # Check, e.g. <<set foo == 4>>
...@@ -62,7 +62,7 @@ $GREP -e "<<[a-zA-Z]\([^>\"]\|[^>]>[^>]\|\"[^\"]*\"\)* [a-zA-Z]\+ * =" -- src/*. ...@@ -62,7 +62,7 @@ $GREP -e "<<[a-zA-Z]\([^>\"]\|[^>]>[^>]\|\"[^\"]*\"\)* [a-zA-Z]\+ * =" -- src/*.
# Check for missing command, e.g. <<foo = # Check for missing command, e.g. <<foo =
$GREP -e "<<[a-zA-Z]* = *" -- src/*.tw | myprint "BadCommand" $GREP -e "<<[a-zA-Z]* = *" -- src/*.tw | myprint "BadCommand"
# Check for duplicate words, e.g. with with # Check for duplicate words, e.g. with with
$GREP -e " \(\b[a-zA-Z][a-zA-Z]\+\) \1\b " --and --not -e " her her " --and --not -e " you you " --and --not -e " New New " --and --not -e "Slave Slave " --and --not -e " that that " --and --not -e " in in " --and --not -e " is is " -- 'src/*' | myprint "Duplicate words" $GREP -e " \(\b[a-zA-Z][a-zA-Z]\+\) \1\b " --and --not -e " her her " --and --not -e " you you " --and --not -e " New New " --and --not -e "Slave Slave " --and --not -e " that that " --and --not -e " in in " --and --not -e " is is " -- 'src/*' | myprint "Duplicate words"
# Check for obsolete SugarCube macros # Check for obsolete SugarCube macros
$GREP -E "<<display |<<click|<<.*\.contains" -- src/*.tw | myprint "ObsoleteMacro" $GREP -E "<<display |<<click|<<.*\.contains" -- src/*.tw | myprint "ObsoleteMacro"
# Check for double articles # Check for double articles
...@@ -73,9 +73,9 @@ $GREP -i -E "\Wan (b|c|d|f|g|j|k|l|m|n|p|q|r|s|t|v|w|x|y|z)\w." -- src/*.tw | gr ...@@ -73,9 +73,9 @@ $GREP -i -E "\Wan (b|c|d|f|g|j|k|l|m|n|p|q|r|s|t|v|w|x|y|z)\w." -- src/*.tw | gr
# Check for $ sign mid-word # Check for $ sign mid-word
$GREP -i "\w$\w" -- src/*.tw | myprint "VarSignMidWord" $GREP -i "\w$\w" -- src/*.tw | myprint "VarSignMidWord"
# check for $ sign at beginning of macro # check for $ sign at beginning of macro
$GREP '<<\s*\$' -- 'src/*' | myprint "VarSignAtMacroStart" $GREP '<<\s*\$' -- 'src/*' | myprint "VarSignAtMacroStart"
# check our custom option macro is either options,option,optionlt,optionlte,optiongt,optiongte,optiondefault,optionstyle,optionif # check our custom option macro is either options,option,optionlt,optionlte,optiongt,optiongte,optiondefault,optionstyle,optionif
$GREP -e '<<option' --and --not -e "<<option\(\|s\|lt\|lte\|gt\|gte\|default\|style\|if\)[ >]" -- 'src/*' | myprint "OptionUnrecognized" $GREP -e '<<option' --and --not -e "<<option\(\|s\|lt\|lte\|gt\|gte\|default\|style\|if\)[ >]" -- 'src/*' | myprint "OptionUnrecognized"
# check our custom option macro is: <<option variable "somestring" # check our custom option macro is: <<option variable "somestring"
$GREP -e "<<option[lg]te\? " --and --not -e "<<option[lg]te\?\s\+-\?[0-9]\+\s\+-\?[0-9]\+\s\+[\'\"].*[\'\"]" -- 'src/*' | grep -v src/js | myprint "OptionBadArguments1" $GREP -e "<<option[lg]te\? " --and --not -e "<<option[lg]te\?\s\+-\?[0-9]\+\s\+-\?[0-9]\+\s\+[\'\"].*[\'\"]" -- 'src/*' | grep -v src/js | myprint "OptionBadArguments1"
$GREP -e "<<optiondefault " --and --not -e "<<optiondefault\s\+\(-\?[0-9]\+\|[\'\"].*[\'\"]\|false\|true\)\s\+[\'\"].*[\'\"]" -- 'src/*' | grep -v src/js | myprint "OptionBadArguments2" $GREP -e "<<optiondefault " --and --not -e "<<optiondefault\s\+\(-\?[0-9]\+\|[\'\"].*[\'\"]\|false\|true\)\s\+[\'\"].*[\'\"]" -- 'src/*' | grep -v src/js | myprint "OptionBadArguments2"
...@@ -83,8 +83,8 @@ $GREP -e "<<option\([lg]t\?\|default\) *>" -- 'src/*' | grep -v src/js | myprint ...@@ -83,8 +83,8 @@ $GREP -e "<<option\([lg]t\?\|default\) *>" -- 'src/*' | grep -v src/js | myprint
#$GREP -e "<<option " --and --not -e "<<option\s\+\(-\?[0-9]\+\|[\'\"].*[\'\"]\|false\|true\)\s\+[\`\'\"].*[\'\"\`]" -- 'src/*' | grep -v src/js | myprint "OptionBadArguments4" # too many false positives #$GREP -e "<<option " --and --not -e "<<option\s\+\(-\?[0-9]\+\|[\'\"].*[\'\"]\|false\|true\)\s\+[\`\'\"].*[\'\"\`]" -- 'src/*' | grep -v src/js | myprint "OptionBadArguments4" # too many false positives
$GREP -e "<<if def [^(>]*[&|]" -- 'src/*' | myprint "AddBracketsAroundDef2" $GREP -e "<<if def [^(>]*[&|]" -- 'src/*' | myprint "AddBracketsAroundDef2"
# check for missing ; before statement # check for missing ; before statement
$GREP 'if $ ' -- 'src/*' | myprint "Missing ; before statement" $GREP 'if $ ' -- 'src/*' | myprint "Missing ; before statement"
$GREP 'elseif $ ' -- 'src/*' | myprint "Missing ; before statement" $GREP 'elseif $ ' -- 'src/*' | myprint "Missing ; before statement"
# Check for an unrecognized letter before >> # Check for an unrecognized letter before >>
$GREP "[^]a-zA-Z0-9 \")}'+-\*\`] *>>" -- 'src/*' | myprint "StrangeCharacterAtEndOfCommand" $GREP "[^]a-zA-Z0-9 \")}'+-\*\`] *>>" -- 'src/*' | myprint "StrangeCharacterAtEndOfCommand"
# Check for a . inside a <<>> # Check for a . inside a <<>>
...@@ -110,10 +110,9 @@ $GREP -i "non.lethal" -- 'src/*' | myprint "ShouldBeNonlethal" ...@@ -110,10 +110,9 @@ $GREP -i "non.lethal" -- 'src/*' | myprint "ShouldBeNonlethal"
#$GREP "span class=[^\"]" -- src/*.js --exclude 'src/001-lib/Jquery/Jquery.js' | myprint "MissingQuotes" disabled until I can figure out how to exclude files #$GREP "span class=[^\"]" -- src/*.js --exclude 'src/001-lib/Jquery/Jquery.js' | myprint "MissingQuotes" disabled until I can figure out how to exclude files
( (
cd src/ cd src/ || exit
$GREP "\$\(PC\|activeSlave\|slaves\|tanks\)[.][^a-zA-Z]" | myprint "UnexpectedCharAfterDot" $GREP "\$\(PC\|activeSlave\|slaves\|tanks\)[.][^a-zA-Z]" | myprint "UnexpectedCharAfterDot"
) )
# Check that all the tags are properly opened and closed & a lot of other stuff # Check that all the tags are properly opened and closed & a lot of other stuff
java -jar devTools/javaSanityCheck/SanityCheck.jar java -jar devTools/javaSanityCheck/SanityCheck.jar
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment