Sha256: e6e8b2fc2577bf1c871691d3b021c1031cededdd74838e725800dd2f8224e684

Contents?: true

Size: 934 Bytes

Versions: 1

Compression:

Stored size: 934 Bytes

Contents

# frozen_string_literal: true

unless 'production' == ENV['RACK_ENV']
  require 'flay'
  desc 'Analyze code for structural similarities'
  task :flay do
    flay = Flay.new
    files = FileList['app.rb', 'app/**/*.rb']
    flay.process(*files)
    threshold = 200

    if flay.total > threshold
      puts flay.report
      raise "Flay total too high! #{flay.total} > #{threshold}"
    end
  end

  require 'flog'
  desc 'Analyze code complexity'
  task :flog do
    flog = Flog.new
    files = FileList['app.rb', 'app/**/*.rb']
    flog.flog(*files)
    threshold = 50

    bad_methods = flog.totals.select do |_name, score|
      score > threshold
    end

    bad_methods.sort { |a, b| a[1] <=> b[1] }.each do |name, score|
      puts format('%<score>8.1f: %<name>s', score: score, name: name)
    end

    unless bad_methods.empty?
      raise "#{bad_methods.size} methods have a flog complexity > #{threshold}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hoboken-0.9.0 lib/hoboken/templates/metrics.rake.tt