#!/bin/bash if [ ! -d ".git" ]; then #not running in git repo, so can't use git commands :-) echo "No .git repo found - skipping sanity checks" exit 0 fi WARNING='\033[93m' myprint() { while read data; do echo -n -e "[$1]$WARNING" echo "$data" done } #check if java version should be run if [[ "$1" == "java" ]]; then java="true" fi #for all that want to add new checks, just add them outside the java checks. GREP="git grep -n --color" if [[ ! "$java" ]]; then # Check for missing right angle bracket: <</if> $GREP "<</[^>]*>[^>]" -- 'src/*' | myprint "MissingClosingAngleBracket" $GREP "<<[^>()]*>[^()<>"$'\r]*\r'"\?$" -- 'src/*' | myprint "MissingClosingAngleBracket" # Check for missing left angle bracket: </if>> $GREP "\([^<]\|^\)</\?\(if\|else\|case\|set\|print\|elseif\)" -- 'src/*' | myprint "MissingOpeningAngleBracket2" fi # Check for accidental assignment. e.g.: <<if $foo = "hello">> $GREP "<<[ ]*if[^>=]*[^><\!=]=[^=][^>]*>>" -- 'src/*' | myprint "AccidentalAssignmentInIf" # Check for accidental assignment. e.g.: <<elseif $foo = "hello">> $GREP "<<[ ]*elseif[^>=]*[^><\!=]=[^=][^>]*>>" -- 'src/*' | myprint "AccidentalAssignmentInElseIf" # Check for missing ". e.g.: <<if $foo == "hello>> $GREP "<<[^\"<>]*\"[^\"<>]*>>" -- 'src/*' | myprint "MissingSpeechMark" # Check for missing ". e.g.: <<if $foo = "hello) $GREP -e "<<[^\"<>]*\([^\"<>]*\"[^><\"]*\"\| [<>] \)*\"\([^\"<>]*\"[^><\"]*\"\| [<>] \)*\([^\"<>]\| [<>] \)*>>" --and --not -e "*[^']*" -- 'src/*' | myprint "MissingSpeechMark2" # 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" # Check for missing $ in activeSlave or PC $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 $GREP -e "<<[ a-zA-Z]\+\([^()<>]\|[^()<>][<>][^()<>]\)*)" --and --not -e "<< *case" -- "src/*" | myprint "MissingOpeningBracket" # Check for opening bracket without closing bracket. e.g.: <<if (foo>> $GREP -e "<<[ a-zA-Z]\([^<>]\|[^<>][<>][^<>]\)\+(\([^()<>]\|[^<>()][<>][^<>()]\|([^<>()]*])\)*>>" -- "src/*" | myprint "MissingClosingBracket" # Check for two closing brackets but one opening bracket. e.g.: <<if (foo))>> $GREP -e "<<[ a-zA-Z]\+[^()<>]*([^()]*)[^()]*)[^()<>]*>>" -- "src/*" | myprint "MissingOpeningBracket2" # Check for one closing bracket but two opening brackets. e.g.: <<if ((foo)>> $GREP -e "<<[ a-zA-Z]\+[^()<>]*([^()]*([^()]*)[^()<>]*>>" -- "src/*" | myprint "MissingClosingBracket2" $GREP -e "<<.*[(][^<>)]*[(][^<>)]*)\?[^<>)]*>>" -- "src/*" | myprint "MissingClosingBracket3" if [[ ! "$java" ]]; then # Check for missing >>. e.g.: <<if $foo $GREP "<<[^<>]*[^,\"\[{"$'\r]\r'"\?$" -- 'src/*' | myprint "MissingClosingAngleBrackets" # Check for too many <<<. e.g.: <<</if>> $GREP "<<<[^<>]*[<>]\?[^<>]*>>" -- "src/*.tw" | myprint "TooManyAngleBrackets" fi # Check for too many >>>. e.g.: <</if>>> $GREP "<<[^<>]*[<>]\?[^<>]*>>>" -- "src/*.tw" | myprint "TooManyAngleBrackets" # Check for wrong capitalization on 'activeslave' and other common typos $GREP -e "\$act" --and --not -e "\$\(activeSlave\|activeChild\|activeArcology\|activeStandard\|activeOrgan\|activeLimbs\|activeUnits\|activeCanine\|activeHooved\|activeFeline\)" -- "src/*" | myprint "WrongCapitilization" $GREP "\(csae\|[a-z] She \|attepmts\|youreslf\|advnaces\|canAcheive\|setBellySize\|SetbellySize\|setbellySize\|bellypreg\|pregBelly\|bellyimplant\|bellyfluid\|pronounCaps\|carress\|hormonebalance\|fetishknown\)" -- 'src/*' | myprint "SpellCheck" $GREP "\(recieve\|recieves\)" -- 'src/*' | myprint "PregmodderCannotSpellReceive" $GREP "\$slave\[" -- 'src/*' | myprint "ShouldBeSlaves" # Check for strange spaces e.g. $slaves[$i]. lips $GREP "\$slaves\[\$i\]\. " -- 'src/*' | myprint "MissingPropertyAfterSlaves" # Check using refreshmentType instead of refreshment $GREP "\$PC.refreshmentType[^ =]" -- 'src/*' | grep -v src/events/intro/introSummary.tw | myprint "ShouldBeRefreshment" if [[ ! "$java" ]]; then # Check, e.g., <<//if>> $GREP "<</[a-zA-Z]*[^a-zA-Z<>]\+[a-zA-Z]*>>" -- 'src/*' | myprint "DoubleSlash" fi # Check, e.g. <<else $foo==4 $GREP "<<else >\?[^>]" -- 'src/*' | myprint "ShouldBeElseIf" # Check, e.g., =to $GREP "=to" -- 'src/*' | myprint "EqualAndTo" # 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" # 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" # Check, e.g. <<set foo == 4>> $GREP "<<set[^{>=]*==" -- 'src/*' | myprint "DoubleEqualsInSet" # Check for, e.g <<if slaves[foo]>> $GREP "<<\([^>]\|[^>]>[^>]\)*[^$]slaves\[" -- 'src/*' | myprint "MissingDollar" # Check for missing $ or _ in variable name: $GREP -e "<<[a-zA-Z]\([^>\"]\|[^>]>[^>]\|\"[^\"]*\"\)* [a-zA-Z]\+ * =" -- src/*.tw | myprint "MissingDollar2" # Check for missing command, e.g. <<foo = $GREP -e "<<[a-zA-Z]* = *" -- src/*.tw | myprint "BadCommand" # 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" # Check for obsolete SugarCube macros $GREP -E "<<display |<<click|<<.*\.contains" -- src/*.tw | myprint "ObsoleteMacro" # Check for double articles $GREP -E "\Wa an\W" -- src/*.tw | myprint "DoubleArticle" # Check for incorrect articles $GREP -i -E "\Wa (a|e|i|o|u)." -- src/*.tw | grep -a -i -vE "\Wa (un|eu|us|ut|on|ur|in)." | grep -a -i -vE "(&|<<s>>|UM)." | myprint "IncorrectArticle" $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 | grep -a -i -vE "[A-Z]{3}" | myprint "IncorrectArticle" # Check for $ sign mid-word $GREP -i "\w$\w" -- src/*.tw | myprint "VarSignMidWord" # check for $ sign at beginning of macro $GREP '<<\s*\$' -- 'src/*' | myprint "VarSignAtMacroStart" # 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" # 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 "<<optiondefault " --and --not -e "<<optiondefault\s\+\(-\?[0-9]\+\|[\'\"].*[\'\"]\|false\|true\)\s\+[\'\"].*[\'\"]" -- 'src/*' | grep -v src/js | myprint "OptionBadArguments2" $GREP -e "<<option\([lg]t\?\|default\) *>" -- 'src/*' | grep -v src/js | myprint "OptionBadArguments3" $GREP -e "<<option " --and --not -e "<<option\s\+\(-\?[0-9]\+\|[\'\"].*[\'\"]\|false\|true\)\s\+[\`\'\"].*[\'\"\`]" -- 'src/*' | grep -v src/js | myprint "OptionBadArguments4" $GREP -e "<<if def [^(>]*[&|]" -- 'src/*' | myprint "AddBracketsAroundDef2" # check for missing ; before statement $GREP 'if $ ' -- 'src/*' | myprint "missing ; before statement" $GREP 'elseif $ ' -- 'src/*' | myprint "missing ; before statement" # Check for an unrecognized letter before >> $GREP "[^]a-zA-Z0-9 \")}'+-\*\`] *>>" -- 'src/*' | myprint "StrangeCharacterAtEndOfCommand" # Check for a . inside a <<>> $GREP "<<[a-zA-Z]\([^\"'>]\|[^\"'>]>[^\"'>]\)*[a-zA-Z][.][^a-zA-Z]" | myprint "StrangeCharacterAfterDot" # Check for @@. instead of .@@ $GREP -E "@@(\.|,|;|:)\s" -- src/*.tw | myprint "WrongSelectorPunctuation" $GREP "@@[a-z]\+;" -- 'src/*' | myprint "SelectorMissingDot" # Check that we do not have any variables that we use only once. e.g. $onlyUsedOnce # Ignore *Nationalities ( cd src/ cat $(find . -name "*.tw" ) | tr -c '$a-zA-Z' '\n' | sed -n '/^[$]/p' | grep -v "Nationalities" | sort | uniq -u | sed 's/^[$]/-e[$]/' | sed 's/$/\\\\W/' | xargs -r git grep -n --color | myprint "OnlyUsedOnce" cat $(find . -name "*.tw" ) | tr -c '.$a-zA-Z[]_' '\n' | sed 's/SugarCube\.State\.variables\./$/g' | sed -n -e 's/^[$]\(PC\|activeSlave\|\(slaves\|tanks\)\[[^]]*\]*\)[.]\([a-zA-Z]\+\).*$/[.]\3/p' | sort | uniq -u |sed 's/^\(.*\)$/-e\1\\\\\b/' | xargs -r git grep -n --color | myprint "SlaveAttributeUsedOnce" $GREP "\$\(PC\|activeSlave\|slaves\|tanks\)[.][^a-zA-Z]" | myprint "UnexpectedCharAfterDot" ) # Check that all the tags are properly opened and closed if [[ "$java" ]]; then java -jar devTools/javaSanityCheck/SanityCheck.jar else git ls-files "src/*.tw" | xargs -d '\n' ./devTools/check.py fi