Last active
August 29, 2015 14:22
-
-
Save omegahm/2b92bb0fa1e92ef07017 to your computer and use it in GitHub Desktop.
Find unused Ruby methods in current project
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
skip_methods = %w(new create edit update destroy index show initialize to_s call as_json page per_page build up down change) | |
output = `grep -hir "^\s*def\s" *` | |
methods = output.split("\n") | |
puts "Found #{methods.size} methods." | |
ununsed_methods = [] | |
methods.each_with_index do |line, i| | |
line = line.gsub(/^\s*/, '') | |
.gsub(/\(.*/, '') | |
.gsub(/def /, '') | |
.gsub(/self\./, '') | |
next if skip_methods.include?(line) | |
next if line[-1] == '=' | |
puts "(#{i}) Looking for #{line}." | |
if `grep -hir "#{line}" *`.split("\n").size == 1 | |
puts "\tFound unused: #{line}" | |
ununsed_methods << line | |
end | |
end | |
puts "UNUSED METHODS:\n" | |
p ununsed_methods |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment