Skip to content

Instantly share code, notes, and snippets.

@cherring07
Last active April 3, 2019 10:27
Show Gist options
  • Save cherring07/41acbda92f2b825ae07947f9a589b019 to your computer and use it in GitHub Desktop.
Save cherring07/41acbda92f2b825ae07947f9a589b019 to your computer and use it in GitHub Desktop.
Find any Javascript files which are never imported based upon parent folder name (React style)
# Place in directory of choice (normally root of the react project)
# chmod u+x find-unused-js-files-by-folder-name.sh
# sh ./find-unused-js-files-by-folder-name.sh
JS_FILES=$(find ./ -type f -name "*.tsx" ! -path "./node_modules/*" ! -path "*.test.tsx")
RED="\033[41m"
NC="\033[0m"
LIGHT_RED="\033[0;31m"
for FILE in $JS_FILES; do
REACT_CLASS_NAME_FROM_FOLDER="$(basename $(dirname $FILE))"
git grep --quiet $REACT_CLASS_NAME_FROM_FOLDER 1>/dev/null
if [ "$?" == "1" ]; then
echo "${RED}Unused file! Please check:${NC} ${LIGHT_RED}$FILE${NC}"
fi
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment