A RuboCop extension focused on enforcing Rails best practices and coding conventions.
Note: This repository manages rubocop-rails gem (>= 2.0.0). rubocop-rails gem (<= 1.5.0) has been renamed to rubocop-rails_config gem.
Just install the rubocop-rails gem
gem install rubocop-railsor if you use bundler put this in your Gemfile
gem 'rubocop-rails'You need to tell RuboCop to load the Rails extension. There are three ways to do this:
Put this into your .rubocop.yml.
require: rubocop-railsAlternatively, use the following array notation when specifying multiple extensions.
require:
  - rubocop-other-extension
  - rubocop-railsNow you can run rubocop and it will automatically load the RuboCop Rails
cops together with the standard cops.
rubocop --require rubocop-railsNote: --rails option is required while rubocop command supports --rails option.
RuboCop::RakeTask.new do |task|
  task.requires << 'rubocop-rails'
endAll cops are located under
lib/rubocop/cop/rails, and contain
examples/documentation.
In your .rubocop.yml, you may treat the Rails cops just like any other
cop. For example:
Rails/FindBy:
  Exclude:
    - lib/example.rbRails cops support the following versions:
- Rails 4.0+
Checkout the contribution guidelines.
rubocop-rails is MIT licensed. See the accompanying file for
the full text.