Created
April 24, 2020 09:06
-
-
Save Anthchirp/e926d72ef4f9cfaf0ae578d0973bc197 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# find python classes that are declared once and then list files where the name is referenced | |
for candidate in \ | |
$(grep --exclude-dir=".git" --exclude-dir="__pycache__" -hoPR '^ *class \K[a-zA-Z0-9_]*' . | \ | |
sort | uniq -c | grep " 1 " | cut -c 9-) | |
do | |
REFERENCES=$(grep --exclude-dir=".git" --exclude-dir="__pycache__" -c -cR $candidate . | grep -v ":0") | |
if [ "$(wc -l <<< "$REFERENCES")" -eq "1" ]; then | |
if [[ $REFERENCES == *":1" ]]; then | |
echo class $candidate is an unused declaration in ${REFERENCES%:*} | |
elif [[ $candidate != "_"* ]]; then | |
echo class $candidate is a public name only referred to in ${REFERENCES%:*} | |
fi | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment