Created
May 6, 2024 00:58
-
-
Save LindseyB/d659fee213ca515a9356b05db6a4b914 to your computer and use it in GitHub Desktop.
Finds specifically unused views in a rails project (skips partials in favor of the unused partials gem)
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
#!/usr/bin/env ruby | |
require './config/environment' | |
(Dir.glob("./app/views/**/*.html.erb")).each do |v| | |
next if v.include?('components') || v.include?('layouts') || v.include?('mailer') || v.include?('errors') || v.include?('static_pages') || v.include?('partials') | |
match = /app\/views\/(.*)\/(.+)\.html\.erb/.match(v) | |
klass = "#{match[1].camelize}Controller".constantize rescue nil | |
action = match[2] | |
# skip partials because we can use the `discover-unused-partials` gem | |
next if action[0] == "_" | |
if klass.nil? | |
puts "Unused view: #{v}" | |
next | |
end | |
unless klass.new.public_methods.include?(action.to_sym) | |
puts "Unused view: #{v}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment