Tbpgr Blog

Ruby プログラマ tbpgr(てぃーびー) のブログ

RubyCriticのrake taskを使う

alt

RubyCriticをrake taskとして利用するための設定をします。

デフォルト

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

require 'bundler/gem_tasks'
require 'rubycritic/rake_task'
RubyCritic::RakeTask.new do |task|
  task.paths = FileList['lib/**/*.rb', 'spec/**/*.rb']
  task.options = '-f console'
end

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 rubycritic       # Run RubyCritic

rubycritic が追加された

  • 実行結果
$ rake rubycritic
running flay smells

running flog smells
..
running reek smells
..
running complexity
..
running attributes
..
running churn
fatal: your current branch 'master' does not have any commits yet
fatal: your current branch 'master' does not have any commits yet
.fatal: your current branch 'master' does not have any commits yet
fatal: your current branch 'master' does not have any commits yet
.
fatal: Needed a single revision
Sample:
  Rating:       A
  Churn:        0
  Complexity:   2
  Duplication:  0
  Smells:       2
    * (DuplicateMethodCall) Sample#hoge calls 'puts "hoge"' 2 times
      - lib/sample.rb:6
      - lib/sample.rb:7
    * (IrresponsibleModule) Sample has no descriptive comment
      - lib/sample.rb:3

Sample:
  Rating:       A
  Churn:        0
  Complexity:   0
  Duplication:  0
  Smells:       0
Score: 100.0

外部資料