Skip to content

Instantly share code, notes, and snippets.

@algomaster99
Created September 27, 2021 11:44
Show Gist options
  • Save algomaster99/780d02507ef9dcd5129316582786ff56 to your computer and use it in GitHub Desktop.
Save algomaster99/780d02507ef9dcd5129316582786ff56 to your computer and use it in GitHub Desktop.
Script for running sorald
#!/usr/bin/bash
PATH_TO_SORALD="/home/aman/kth/sorald/target/sorald-0.3.1-SNAPSHOT-jar-with-dependencies.jar"
declare -a rules=("S1068"
"S1118"
"S1132"
"S1155"
"S1217"
"S1444"
"S1481"
"S1596"
"S1656"
"S1854"
"S1860"
"S1948"
"S2057"
"S2095"
"S2097"
"S2111"
"S2116"
"S2142"
"S2164"
"S2167"
"S2184"
"S2204"
"S2225"
"S2272"
"S2755"
"S3032"
"S3067"
"S3984"
"S4973"
)
declare -A description=(["S1068"]="Unused \"private\" fields should be removed"
["S1118"]="Utility classes should not have public constructors (incomplete: Only handles implicit public constructor)"
["S1132"]="Strings literals should be placed on the left side when checking for equality"
["S1155"]="Collection.isEmpty() should be used to test for emptiness"
["S1217"]="\"Thread.run()\" should not be called directly"
["S1444"]="\"public static\" fields should be constant (incomplete: does not fix variable naming)"
["S1481"]="Unused local variables should be removed"
["S1596"]="\"Collections.EMPTY_LIST\", \"EMPTY_MAP\", and \"EMPTY_SET\" should not be used"
["S1656"]="Variables should not be self-assigned"
["S1854"]="Unused assignments should be removed"
["S1860"]="Synchronization should not be based on Strings or boxed primitives"
["S1948"]="Fields in a \"Serializable\" class should either be transient or serializable"
["S2057"]="Every class implementing Serializable should declare a static final serialVersionUID. (incomplete: This processor does not address the case where the class already has a serialVersionUID with a non long type.)"
["S2095"]="Resources should be closed"
["S2097"]="\"equals(Object obj)\" should test argument type"
["S2111"]="\"BigDecimal(double)\" should not be used"
["S2116"]="\"hashCode\" and \"toString\" should not be called on array instances"
["S2142"]="\"InterruptedException\" should not be ignored"
["S2164"]="Math should not be performed on floats"
["S2167"]="\"compareTo\" should not return \"Integer.MIN_VALUE\""
["S2184"]="Math operands should be cast before assignment"
["S2204"]="\".equals()\" should not be used to test the values of \"Atomic\" classes"
["S2225"]="\"toString()\" and \"clone()\" methods should not return null (incomplete: does not fix null returning clone())"
["S2272"]="\"Iterator.next()\" methods should throw \"NoSuchElementException\""
["S2755"]="XML parsers should not be vulnerable to XXE attacks (incomplete: This processor is a WIP and currently supports a subset of rule 2755. See Sorald's documentation for details.)"
["S3032"]="JEE applications should not \"getClassLoader\""
["S3067"]="\"getClass\" should not be used for synchronization"
["S3984"]="Exception should not be created without being thrown"
["S4973"]="Strings and Boxed types should be comparedusing \"equals()\""
)
mkdir -p output
core="output/README.md"
touch $core
for rule in "${rules[@]}"
do
echo $rule
description="${description[$rule]}"
rspec=$(echo "$rule" | cut -d "S" -f 2)
url="https://rules.sonarsource.com/java/RSPEC-$rspec"
printf "# ${rule}\n" >> $core
printf "> $description. Link: $url\n\n" >> $core
java -jar ${PATH_TO_SORALD} repair --source . --rule-key ${rule} | grep -P "^\w+:\s\d+" >> $core
printf "\n\n" >> $core
git diff >> "output/${rule}.diff"
git reset HEAD --hard
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment