Sha256: 43e6bac5b418b7bfa0f020c14b5eee848bf692d2a6a9c5f75e21e3f17eb0f9e0
Contents?: true
Size: 1.11 KB
Versions: 10
Compression:
Stored size: 1.11 KB
Contents
namespace :metrics do require 'flog' require 'flog_cli' project = Devtools.project config = project.flog # Original code by Marty Andrews: # http://blog.martyandrews.net/2009/05/enforcing-ruby-code-quality.html desc 'Measure code complexity' task :flog do threshold = config.threshold.to_f.round(1) flog = Flog.new flog.flog(*PathExpander.new(config.lib_dirs.dup, '**/*.rb').process) totals = flog.totals.select { |name, score| name[-5, 5] != '#none' } .map { |name, score| [name, score.round(1)] } .sort_by { |name, score| score } if totals.any? max = totals.last[1] unless max >= threshold Devtools.notify_metric_violation "Adjust flog score down to #{max}" end end bad_methods = totals.select { |name, score| score > threshold } if bad_methods.any? bad_methods.reverse_each do |name, score| printf "%8.1f: %s\n", score, name end Devtools.notify_metric_violation( "#{bad_methods.size} methods have a flog complexity > #{threshold}" ) end end end
Version data entries
10 entries across 10 versions & 1 rubygems