デフォルト
デフォルトの設定で利用してみます。
Rakefile
require 'bundler/gem_tasks'
require 'rubocop/rake_task'
RuboCop::RakeTask.new
task default: :spec
- 設定前
$ rake -T
rake build # Build sample-0.1.0.gem into the pkg directory
rake clean # Remove any temporary products
rake clobber # Remove any generated files
rake install # Build and install sample-0.1.0.gem into system gems
rake install:local # Build and install sample-0.1.0.gem into system gems without network access
rake release[remote] # Create tag v0.1.0 and build and push sample-0.1.0.gem to Rubygems
- 設定後
$ rake -T
rake build # Build sample-0.1.0.gem into the pkg directory
rake clean # Remove any temporary products
rake clobber # Remove any generated files
rake install # Build and install sample-0.1.0.gem into system gems
rake install:local # Build and install sample-0.1.0.gem into system gems without network access
rake release[remote] # Create tag v0.1.0 and build and push sample-0.1.0.gem to Rubygems
rake rubocop # Run RuboCop
rake rubocop:auto_correct # Auto-correct RuboCop offenses
rubocop と rubocop:auto_correct が追加された
- 実行結果
$ rake rubocop
Running RuboCop...
Inspecting 6 files
..C..C
Offenses:
# RuboCop comment
^^^^^^^^^^^^^^^^^^^^^^^^
lib/sample.rb:3:1: C: Missing top-level module documentation comment.
module Sample
^^^^^^
# 中略
6 files inspected, 7 offenses detected
RuboCop failed!
HTMLフォーマットを指定
HTMLフォーマットで利用してみます。
Rakefile
require 'bundler/gem_tasks'
require 'rubocop/rake_task'
RuboCop::RakeTask.new do |r|
r.formatters = ['html']
end
task default: :spec
- 実行結果
$ rake rubocop
Running RuboCop...
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8' />
中略
<footer>
Generated by <a href="https://github.com/bbatsov/rubocop">RuboCop</a>
<span class="version">0.43.0</span>
</footer>
</body>
</html>
RuboCop failed!