guard-rubocop allows you to automatically check Ruby code style with RuboCop when files are modified.
Tested on MRI 1.9, 2.0, 2.1, JRuby in 1.9 mode and Rubinius.
Please make sure to have Guard installed before continue.
guard-rubocop to your
group :development do gem 'guard-rubocop' end
and then execute:
$ bundle install
or install it yourself as:
$ gem install guard-rubocop
Add the default Guard::Rubocop definition to your
Guardfile by running:
$ guard init rubocop
Please read the Guard usage documentation.
You can pass some options in
Guardfile like the following example:
guard :rubocop, all_on_start: false, cli: ['--format', 'clang', '--rails'] do # ... end
all_on_start: true # Check all files at Guard startup. # default: true cli: '--rails' # Pass arbitrary RuboCop CLI arguments. # An array or string is acceptable. # default: nil hide_stdout: false # Do not display console output (in case outputting to file). # default: false keep_failed: true # Keep failed files until they pass. # default: true notification: :failed # Display Growl notification after each run. # true - Always notify # false - Never notify # :failed - Notify only when failed # default: :failed
If you're using a testing Guard plugin such as
guard-rspec together with
guard-rubocop in the TDD way (the red-green-refactor cycle),
you might be uncomfortable with the offense reports from RuboCop in the red-green phase:
- In the red-green phase, you're not necessarily required to write clean code – you just focus writing code to pass the test. It means, in this phase,
guard-rspecshould be run but
- In the refactor phase, you're required to make the code clean while keeping the test passing. In this phase, both
guard-rubocopshould be run.
In this case, you may think the following
Guardfile structure useful:
# This group allows to skip running RuboCop when RSpec failed. group :red_green_refactor, halt_on_fail: true do guard :rspec do # ... end guard :rubocop do # ... end end
Note: You need to use
guard-rspec 4.2.3 or later due to a bug where it unintentionally fails when there are no spec files to be run.
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request
Copyright (c) 2013–2014 Yuji Nakayama
See the LICENSE.txt for details.