Sha256: 030c6e9ed7c70b58e6b25f4a4979640737ae8f194b33d40600b015fdc88218af

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

# encoding: UTF-8

namespace :metrics do
  require 'flog'
  require 'flog_cli'

  project = Central::Devtools.project
  config = project.flog

  desc 'Measure code complexity'
  task :flog do
    threshold = config.threshold.to_f.round(1)
    flog = Flog.new
    flog.flog(*FlogCLI.expand_dirs_to_files(config.lib_dirs))

    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
        Central::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

      Central::Devtools.notify_metric_violation(
        "#{bad_methods.size} methods have a flog complexity > #{threshold}"
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
central-devtools-0.8.3 shared/tasks/metrics/flog.rake