1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RuboCopのrake taskを使う

Posted at

デフォルト

デフォルトの設定で利用してみます。

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!

外部資料

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?