spiff-arena/spiffworkflow-backend/bin/codemod/remove_all_unused_functions

31 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
function error_handler() {
>&2 echo "Exited with BAD EXIT CODE '${2}' in ${0} script at line: ${1}."
exit "$2"
}
trap 'error_handler ${LINENO} $?' ERR
set -o errtrace -o errexit -o nounset
# HELP: remove all unused functions from python files
if ! command -v dead >/dev/null 2>&1; then
echo "dead is not installed. installing..."
echo "pip install dead"
fi
list_of_unused_things="$(dead | grep -E '^[a-z].*is never read')"
while read -r line; do
function_name="$(echo "$line" | awk '{print $1}')"
echo "function_name: ${function_name}"
file_name_and_line_number="$(echo "$line" | perl -p -e "s/.*is never read, defined in //g")"
file_name="$(echo "$file_name_and_line_number" | awk -F ':' '{print $1}')"
echo "trying to remove $function_name from: ${file_name}"
if python bin/codemod/update_file_to_remove_function.py "$file_name" "$function_name"; then
# TODO: run exhaustive tests, and if they pass, report success
echo "function ${function_name} removed from ${file_name}. yay!"
exit 0
fi
done <<< "$list_of_unused_things"