style-guide snippets

How to introduce Rubocop in your project

Tagged rubocop, style-guide, ruby  Languages ruby

Installation

Edit Gemfile:

group :development do
  gem 'rubocop' # Style guide checker
  gem 'guard-rubocop' # Rubocop plugin for Guard
end

Install:

$ bundle

Usage

Run Rubocop:

$ rubocop --auto-gen-config

Tweaking

Edit .rubocop.yml:

inherit_from: .rubocop_todo.yml

Introduce new rules gradually in priority order by enabling and moving rules from .rubocop_todo.yml to .rubocop.yml.

You can also use the Ruby style-guide's rubocop configuration: https://github.com/bbatsov/rubocop/blob/master/config/default.yml

Workflow integration

Run:

$ guard init rubocop

Edit Guardfile:

guard :rubocop, all_on_start: false, cli: ['--format', 'clang', '--rails'] do
  watch(%r{.+\.rb$})
  watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
end

Editor Integration

Optionally, integrate Rubocop with your editor: * Textmate * Vim

CI integration

See How to introduce rubocop and integrate into Jenkins.