Dead Code and Unused Asset Discovery
This app is large (~1,700+ partials, 1,000+ helper methods, 200+ routes). One-off manual checks only scratch the surface. Use the tools below for broader cleanup.
What Was Removed (Latest Pass)
Section titled “What Was Removed (Latest Pass)”- Dead partials:
app/views/opportunities/_opportunity.html.erb,app/views/stores/_warehouse_package.html.erb - Dead route:
GET /customers/view_by_rep(no controller action existed) - Orphan views:
customers/view_by_rep.js.erb,customers/_view_by_rep.html.erb - Dead helper methods:
ReportsHelper#opp_before,#opp_after,#order_before,#order_after,#first_order
Gems Already in the Stack
Section titled “Gems Already in the Stack”| Gem | Purpose | How to run |
|---|---|---|
| traceroute | Finds routes with no controller action (or no view) | Use the project script below; or mise exec -- bundle exec traceroute if the gem exposes a CLI |
Partials: No reliable gem for unused partials in this app (render partial: '/foo', dynamic names, and presenters produce huge false-positive lists). Use manual review, production render logging, or custom scripts if needed.
Unused Routes Script
Section titled “Unused Routes Script”script/unused_routes.rb uses traceroute-style logic and checks for presence of views. It requires a full Rails load (eager_load).
mise exec -- ruby script/unused_routes.rbNote: The script was updated to use require_relative '../config/environment'. If eager_load fails (e.g. missing constant in dev), run in an environment where the app loads cleanly or temporarily skip eager_load for a lighter check.
Optional / Deferred-Load Gems
Section titled “Optional / Deferred-Load Gems”Many gems in the Gemfile are require: false and only loaded when used. To find gems that are never required:
- bumbler (dev, optional): Uncomment
bumblerin the Gemfile, thenmise exec -- bundle exec bumbler— profiles gem load times. - Manual check: search the codebase for
require '<gem_name>'orrequire "<gem_name>"and for the gem’s main namespace (e.g.Crisp::forcrisp-api).
Possible unused gem (verify before removing): crisp-api — no require 'crisp_api' or Crisp:: usage found; Crisp chat is used via frontend JS and config only. Confirm in your codebase before dropping.
Broader Helper / Partial Audit
Section titled “Broader Helper / Partial Audit”- Helpers: There is no built-in “unused helper method” gem. Options: grep for each helper method name across
app/viewsandapp/helpers, or use a static analysis tool that understands Rails helpers. - Partials: Same—dynamic
renderand leading-slash paths defeat naive scanners; grep and feature-by-feature review are more trustworthy.
When to Run
Section titled “When to Run”- After large refactors or before a major release.
- Periodically (e.g. quarterly) to keep the codebase lean.
- Before removing a feature, run discovery to see related dead code.