A Ruby gem to analyze Stimulus.js controller usage in your Rails application. Find unused controllers, undefined controllers, and audit your Stimulus controller usage.
Add this line to your application's Gemfile:
gem 'ordit'
And then execute:
bundle install
Run an audit to see all defined and used controllers in your application:
rails ordit:stimulus
This will show:
- Controllers that are defined but never used
- Controllers that are used but don't have corresponding files
- Summary statistics
Example output:
📊 Stimulus Controller Audit
❌ Controllers not defined in any views:
unused-feature
users--edit-password
⚠️ Used but undefined controllers:
missing-controller
└─ 📁 app/views/products/show.html.erb
📁 app/views/users/edit.html.erb
You can customize the paths that are scanned in an initializer (config/initializers/ordit.rb
):
Ordit.configure do |config|
config.view_paths = [
Rails.root.join('app/views/**/*.{html,erb,haml}'),
Rails.root.join('app/javascript/**/*.{js,jsx}'),
Rails.root.join('app/components/**/*.{html,erb,haml,rb}')
]
config.controller_paths = [
Rails.root.join('app/javascript/controllers/**/*.{js,ts}')
]
end
- Finds unused Stimulus controllers
- Detects controllers used in views but missing controller files
- Supports namespaced controllers (e.g.,
users--name
) - Handles multiple syntax styles:
# HTML attribute syntax <div data-controller="products"> # Ruby hash syntax <%= f.submit 'Save', data: { controller: 'products' } %> # Hash rocket syntax <%= f.submit 'Save', data: { :controller => 'products' } %> # Hash rocket string syntax <%= f.submit 'Save', 'data' => { 'controller' => 'products' } %>
- Scans ERB, HTML, and HAML files
- Works with both JavaScript and TypeScript controller files
- Supports component-based architectures
After checking out the repo:
- Run
bundle install
to install dependencies - Run
rake test
to run the tests - Create a branch for your changes (
git checkout -b my-new-feature
) - Make your changes and add tests
- Ensure tests pass
Bug reports and pull requests are welcome on GitHub. This project is intended to be a safe, welcoming space for collaboration.
The gem is available as open source under the terms of the MIT License.