[Ruby] rake task に Rubocop を追加する
あわせて default task に追加しておく。
[markdown]
[こちら](https://www.d-wood.com/blog/2016/10/20_8500.html)の続き。
“`prettyprinted
% rake –version
rake, version 10.5.0
“`
用意されている rake_task を require して new する。
> * [Integration with other tools – RuboCop: The Ruby Linter that Serves and Protects](http://rubocop.readthedocs.io/en/latest/integration_with_other_tools/#rake-integration)
“`ruby:Rakefile
require ‘bundler/gem_tasks’
require ‘rspec/core/rake_task’
require ‘rubocop/rake_task’
RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new
task default: [:rubocop, :spec]
“`
`rake -T` でタスクが追加されていることを確認する。
“`prettyprinted
% rake -T
rake build # Build bcupgrade-0.1.1.gem into the pkg directory
rake clean # Remove any temporary products
rake clobber # Remove any generated files
rake install # Build and install bcupgrade-0.1.1.gem into system gems
rake install:local # Build and install bcupgrade-0.1.1.gem into system gems without network access
rake release[remote] # Create tag v0.1.1 and build and push bcupgrade-0.1.1.gem to Rubygems
rake rubocop # Run RuboCop
rake rubocop:auto_correct # Auto-correct RuboCop offenses
rake spec # Run RSpec code examples
“`
## 補遺
> * [ruby – How to integrate rubocop with Rake? – Stack Overflow](http://stackoverflow.com/questions/15008751/how-to-integrate-rubocop-with-rake)
> * [Railsで開発しているときにrakeのデフォルトタスクを [:rubocop, :rspec] にする – アジャイルSEの憂鬱](http://sinsoku.hatenablog.com/entry/2016/01/04/090000)
[/markdown]