Permalink
Browse files

Update metrics tasks and config

  • Loading branch information...
dkubb committed Nov 25, 2012
1 parent 74677fa commit 870c2513d5d7c7cc4e1eb539e0b6d0286f47f2fd
View
@@ -1,3 +1,3 @@
---
threshold: 6
total_score: 8
threshold: 15
total_score: 32
View
@@ -0,0 +1,3 @@
--color
--loadby random
--format profile
@@ -0,0 +1,3 @@
require 'rbconfig'
::Config = RbConfig unless defined?(::Config)
View
@@ -1,7 +1,9 @@
# encoding: utf-8
desc 'Run metrics with Heckle'
task :ci => %w[ ci:metrics heckle ]
task :ci => %w[ ci:metrics metrics:heckle ]
namespace :ci do
desc 'Run metrics'
task :metrics => %w[ verify_measurements flog flay reek roodi metrics:all ]
desc 'Run metrics (except heckle) and spec'
task :metrics => %w[ spec metrics:verify_measurements metrics:flog metrics:flay metrics:reek metrics:roodi metrics:all ]
end
View
@@ -1,13 +1,15 @@
# encoding: utf-8
begin
if RUBY_VERSION == '1.8.7'
require 'flay'
require 'yaml'
require 'flay'
require 'yaml'
config = YAML.load_file(File.expand_path('../../../config/flay.yml', __FILE__)).freeze
threshold = config.fetch('threshold').to_i
total_score = config.fetch('total_score').to_f
files = Flay.expand_dirs_to_files(config.fetch('path', 'lib'))
config = YAML.load_file(File.expand_path('../../../config/flay.yml', __FILE__)).freeze
threshold = config.fetch('threshold').to_i
total_score = config.fetch('total_score').to_f
files = Flay.expand_dirs_to_files(config.fetch('path', 'lib')).sort
namespace :metrics do
# original code by Marty Andrews:
# http://blog.martyandrews.net/2009/05/enforcing-ruby-code-quality.html
desc 'Analyze for code duplication'
@@ -16,7 +18,7 @@ begin
flay = Flay.new(:fuzzy => false, :verbose => false, :mass => 0)
flay.process(*files)
max = flay.masses.map { |hash, mass| mass.to_f / flay.hashes[hash].size }.max
max = (flay.masses.map { |hash, mass| mass.to_f / flay.hashes[hash].size }.max) || 0
unless max >= threshold
raise "Adjust flay threshold down to #{max}"
end
@@ -35,13 +37,9 @@ begin
raise "#{flay.masses.size} chunks of code have a duplicate mass > #{threshold}"
end
end
else
task :flay do
$stderr.puts 'Flay has inconsistend results accros ruby implementations. It is only enabled on 1.8.7, fix and remove guard'
end
end
rescue LoadError
task :flay do
abort 'Flay is not available. In order to run flay, you must: gem install flay'
$stderr.puts 'Flay is not available. In order to run flay, you must: gem install flay'
end
end
View
@@ -1,3 +1,5 @@
# encoding: utf-8
begin
require 'flog'
require 'yaml'
@@ -11,33 +13,37 @@ begin
config = YAML.load_file(File.expand_path('../../../config/flog.yml', __FILE__)).freeze
threshold = config.fetch('threshold').to_f.round_to(1)
# original code by Marty Andrews:
# http://blog.martyandrews.net/2009/05/enforcing-ruby-code-quality.html
desc 'Analyze for code complexity'
task :flog do
flog = Flog.new
flog.flog Array(config.fetch('path', 'lib'))
totals = flog.totals.select { |name, score| name[-5, 5] != '#none' }.
map { |name, score| [ name, score.round_to(1) ] }.
sort_by { |name, score| score }
namespace :metrics do
# original code by Marty Andrews:
# http://blog.martyandrews.net/2009/05/enforcing-ruby-code-quality.html
desc 'Analyze for code complexity'
task :flog do
flog = Flog.new
flog.flog Array(config.fetch('path', 'lib'))
max = totals.last[1]
unless max >= threshold
raise "Adjust flog score down to #{max}"
end
totals = flog.totals.select { |name, score| name[-5, 5] != '#none' }.
map { |name, score| [ name, score.round_to(1) ] }.
sort_by { |name, score| score }
bad_methods = totals.select { |name, score| score > threshold }
if bad_methods.any?
bad_methods.reverse_each do |name, score|
puts '%8.1f: %s' % [ score, name ]
if totals.any?
max = totals.last[1]
unless max >= threshold
raise "Adjust flog score down to #{max}"
end
end
raise "#{bad_methods.size} methods have a flog complexity > #{threshold}"
bad_methods = totals.select { |name, score| score > threshold }
if bad_methods.any?
bad_methods.reverse_each do |name, score|
puts '%8.1f: %s' % [ score, name ]
end
raise "#{bad_methods.size} methods have a flog complexity > #{threshold}"
end
end
end
rescue LoadError
task :flog do
abort 'Flog is not available. In order to run flog, you must: gem install flog'
$stderr.puts 'Flog is not available. In order to run flog, you must: gem install flog'
end
end
Oops, something went wrong.

0 comments on commit 870c251

Please sign in to comment.