Forked from kennethkalmer/find_unused_helpers.rb
Last active
August 29, 2015 14:01
-
-
Save markoa/3518646a84589680f744 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
# | |
# Shotgun approach (read: slow and dirty hack) to help find unused helpers in a Rails application | |
# | |
puts "Loading all source files into memory :(" | |
source = {} | |
Dir["app/**/**/*.*"].each do |f| | |
next if f.include?("app/assets") | |
source[ f ] = File.readlines(f) | |
end | |
puts "#{source.size} files loaded into memory" | |
helpers = [] | |
source.keys.grep(/app\/helpers/).each do |f| | |
code = source[ f ] | |
code.each do |line| | |
if line =~ /def ([^\(\s]+)/ | |
helpers << $1.chomp | |
end | |
end | |
end | |
puts "Scanning for #{helpers.size} helpers" | |
# combine the source code | |
complete_code = source.values.flatten | |
# Find occurances | |
helpers.each do |name| | |
found = false | |
complete_code.each do |line| | |
next if line =~ /def #{name}/ | |
found = true if line =~ /#{name}/ | |
end | |
puts "No traces found of #{name}" unless found | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment