Skip to content

Instantly share code, notes, and snippets.

@daisy1754
Created December 4, 2017 16:50
Show Gist options
  • Select an option

  • Save daisy1754/7297ef559e556b9404beb321a098698f to your computer and use it in GitHub Desktop.

Select an option

Save daisy1754/7297ef559e556b9404beb321a098698f to your computer and use it in GitHub Desktop.
Script to find unused JS/JSX file
start_time = Time.now
files = Dir.glob("./**/*.{js,jsx}").reject do |path|
path.include?("node_modules") || path.include?("khan-linter") || path.include?("tests")
end
files_to_delete = files.select do |f|
basename = File.basename(f)
result = `grep --exclude-dir={node_modules,khan-linter,\.git} --exclude=#{basename} -rlw '.' -e #{basename.split(".")[0]}`
result.empty?
end
p "#{files.length} js/jsx files are checked. #{files_to_delete.length} potentially unused files found:"
files_to_delete.each do |f|
p f
`git rm #{f}`
end
p "Execution took #{Time.now - start_time} seconds"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment