RubocopRunner

This gem provides means of running rubocop including auto-correct on all files which are currently staged in git. This can be easily used as pre-commit hook with the included template.

If rubocop can fix all detected issues itself via autocorrect it will will do so. The commit will abort in this situation. In case rubocop accepts all code changes the commit continues.

Although this gem has no tests it's pretty battle tested and is in use internally since years.

Installation

Add these lines to your application's Gemfile:

group :development do
  gem 'rubocop_runner', '~> 2.0', require: false
end

And then execute:

$ bundle

Usage

To create a rubocop runner pre-commit hook once just run

ruby -rrubocop_runner -e "RubocopRunner.install"

To make it easy for every developer on the project you can also add the following rake task

begin
  require 'rubocop/rake_task'
  RuboCop::RakeTask.new
  namespace :rubocop do
    desc 'Install Rubocop as pre-commit hook'
    task :install do
      require 'rubocop_runner'
      RubocopRunner.install
    end
  end
rescue LoadError
  p 'rubocop not installed'
end

ToDo

  • add the install rake task itself to the gem
  • add tests
  • improve gem structure

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/runtastic/rubocop_runner.

License

The gem is available as open source under the terms of the MIT License.