How can we found unused code in Rails?
We can found unused code using rails_best_practices
Using Bundler:
group :development do
gem 'rails_best_practices'
end
-
First install brakeman gem in project
gem install rails_best_practices
-
Then run the below comments
rails_best_practices . | grep 'remove unused methods' < output.txt
-
Please check your
output.txt
file. you will get all unused methods like below
app/controllers/aaaa/xxx_bbb_controller.rb:32 - remove unused methods (Aaa::XxxBbbController#get_yyyy_zzzz_location) app/controllers/aaa/xxx_yyyy_controller.rb:32 - remove unused methods (Aaaa::XxxYyyController#yyyy_zzzz_location)
-
Run My class. Now, go and check your directory. The unwanted methods will comment out.
CommentUnusedMethod.new.comment('output.txt')