Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use flay directly #231

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Use flay directly #231

wants to merge 1 commit into from

Conversation

bf4
Copy link
Member

@bf4 bf4 commented May 14, 2014

Implemented per https://github.com/seattlerb/flay/blob/master/bin/flay

We still have to use flay.report as getting the information in it without calling it would basically require duplicating the code in it and replacing warn/puts with a data structure. So, in the end, it is still MetricFu::Utility.capture_output { flay.report }

I suppose I could redefine def flay.puts(msg) and def flay.warn(msg)
i.e. bin/flay

require 'flay'

flay = Flay.new Flay.parse_options(ARGV)

files = Flay.expand_dirs_to_files(*ARGV)

flay.process(*files)
flay.report

flay.report

  def flay.report prune = nil
    analyze

    puts "Total score (lower is better) = #{self.total}"

    if option[:summary] then
      puts

      self.summary.sort_by { |_,v| -v }.each do |file, score|
        puts "%8.2f: %s" % [score, file]
      end

      return
    end

    count = 0
    sorted = masses.sort_by { |h,m|
      [-m,
       hashes[h].first.file,
       hashes[h].first.line,
       hashes[h].first.first.to_s]
    }
    sorted.each do |hash, mass|
      nodes = hashes[hash]
      next unless nodes.first.first == prune if prune
      puts

      same = identical[hash]
      node = nodes.first
      n = nodes.size
      match, bonus = if same then
                       ["IDENTICAL", "*#{n}"]
                     else
                       ["Similar",   ""]
                     end

      if option[:number] then
        count += 1

        puts "%d) %s code found in %p (mass%s = %d)" %
         [count, match, node.first, bonus, mass]
      else
        puts "%s code found in %p (mass%s = %d)" %
         [match, node.first, bonus, mass]
      end

      nodes.sort_by { |x| [x.file, x.line] }.each_with_index do |x, i|
        if option[:diff] then
          c = (?A.ord + i).chr
          extra = " (FUZZY)" if x.modified?
          puts "  #{c}: #{x.file}:#{x.line}#{extra}"
        else
          extra = " (FUZZY)" if x.modified?
          puts "  #{x.file}:#{x.line}#{extra}"
        end
      end

      if option[:diff] then
        puts
        sources = nodes.map do |s|
          msg = "sexp_to_#{File.extname(s.file).sub(/./, '')}"
          self.respond_to?(msg) ? self.send(msg, s) : sexp_to_rb(s)
        end
        puts n_way_diff(*sources)
      end
    end
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants