Skip to content

Instantly share code, notes, and snippets.

@aslushnikov
Last active August 29, 2015 13:56
Show Gist options
  • Save aslushnikov/9208534 to your computer and use it in GitHub Desktop.
Save aslushnikov/9208534 to your computer and use it in GitHub Desktop.
Find private functions that have never been used in inspector front-end
#!/bin/bash
set -e
if (( $# < 1 )); then
echo "Specify filename to analyze"
exit 1
fi
fileName=$1
for i in $(grep -o '_[a-zA-Z0-9_]*:\s\+fun' $fileName | cut -d':' -f1); do
# count number of occurences in file
num=$(grep $i $fileName | wc -l)
if (( $num == 1 )); then
# if declaration only found in file, then try to search whole repo
num=$(git grep $i | wc -l)
if (( $num == 1 )); then
if [[ -z $shownFileName ]]; then
echo "Processing $fileName"
shownFileName="yes"
fi
echo " WARN: $i is only one time used (in declaration)"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment