Skip to content

Instantly share code, notes, and snippets.

@scriptype
Last active September 5, 2020 12:09
Show Gist options
  • Save scriptype/d1dc28bddfca0f79f557c6df1428c8f6 to your computer and use it in GitHub Desktop.
Save scriptype/d1dc28bddfca0f79f557c6df1428c8f6 to your computer and use it in GitHub Desktop.
Find unused tsx files
# It will print all file names (without extension)
# and list all files (their full paths) that reference those files inside an import statement
#
# It may and most likely will find false negatives (files that are actually used),
# so double-checking those files before deleting them is needed.
find src -name '*.tsx' \
| awk -F/ '{print $NF}' \
| awk -F. '{print $1}' \
| xargs -I _ sh -c "echo '\nFile: _' && grep --recursive --include='*.tsx' -isw 'from .\+_\"' src | awk '{ print $1 }' | cut -d':' -f1 | uniq" \
| less
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment