Skip to content

Add a data structure that contains the data generated by flay.report #32

@bf4

Description

@bf4

Given

Total score (lower is better) = 494

1) IDENTICAL code found in :defn (mass*2 = 196)
  app/models/template_demo.rb:61
  app/models/template_purchase.rb:58

2) IDENTICAL code found in :defn (mass*2 = 144)
  app/models/template_demo.rb:16
  app/models/template_purchase.rb:25

3) Similar code found in :resbody (mass = 58)
  app/models/template.rb:80
  app/models/template.rb:125

4) Similar code found in :defn (mass = 50)
  app/controllers/my_templates_git_controller.rb:4
  app/controllers/my_templates_git_controller.rb:10

5) Similar code found in :call (mass = 46)
  app/inputs/checkbox_list_input.rb:25
  app/inputs/screenshots_input.rb:22

metric_fu, for example, parses this text report to yield (admittedly, not the most rigorous analysis)

{:total_score=>"494",
 :matches=>
  [{:reason=>"1) IDENTICAL code found in :defn (mass*2 = 196)",
    :matches=>
     [{:name=>"app/models/template_demo.rb", :line=>"61"},
      {:name=>"app/models/template_purchase.rb", :line=>"58"}]},
   {:reason=>"2) IDENTICAL code found in :defn (mass*2 = 144)",
    :matches=>
     [{:name=>"app/models/template_demo.rb", :line=>"16"},
      {:name=>"app/models/template_purchase.rb", :line=>"25"}]},
   {:reason=>"3) Similar code found in :resbody (mass = 58)",
    :matches=>
     [{:name=>"app/models/template.rb", :line=>"80"},
      {:name=>"app/models/template.rb", :line=>"125"}]},
   {:reason=>"4) Similar code found in :defn (mass = 50)",
    :matches=>
     [{:name=>"app/controllers/my_templates_git_controller.rb", :line=>"4"},
      {:name=>"app/controllers/my_templates_git_controller.rb", :line=>"10"}]},
   {:reason=>"5) Similar code found in :call (mass = 46)",
    :matches=>
     [{:name=>"app/inputs/checkbox_list_input.rb", :line=>"25"},
      {:name=>"app/inputs/screenshots_input.rb", :line=>"22"}]}]}

The problem, is that it is not easily possible to reproduce the results of this report without either reproducing most of the code in 'report' or changing the meaning of puts and warn on the flay instance.

Now, if I were to run ruby -rpp -rflay -e "flay = Flay.new(Flay.default_options); files = Flay.expand_dirs_to_files(%w[app lib]); flay.process(*files); flay.analyze; pp [flay.total, flay.summary, flay.masses, flay.identical]" I get

[494,
 {"app/controllers/my_templates_git_controller.rb"=>50.0,
  "app/inputs/checkbox_list_input.rb"=>23.0,
  "app/inputs/screenshots_input.rb"=>23.0,
  "app/models/template.rb"=>58.0,
  "app/models/template_demo.rb"=>170.0,
  "app/models/template_purchase.rb"=>170.0},
 {-3749969949219652095=>50,
  1606873373262129863=>46,
  1034993600789789894=>58,
  -4553549444874076191=>144,
  3143048742042231397=>196},
 {-3749969949219652095=>false,
  1606873373262129863=>false,
  1034993600789789894=>false,
  -4553549444874076191=>true,
  3143048742042231397=>true}]

Per discussion in

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions