analdiffist 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.3.0
data/analdiffist.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{analdiffist}
8
- s.version = "0.2.0"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Adam Pearson", "Dave Foley"]
@@ -35,6 +35,7 @@ Gem::Specification.new do |s|
35
35
  "lib/analdiffist/reek_metrics.rb",
36
36
  "lib/analdiffist/reek_parser.rb",
37
37
  "lib/analdiffist/standard_diffist.rb",
38
+ "lib/analdiffist/std_out_reporter.rb",
38
39
  "lib/analdiffist/target_finder.rb",
39
40
  "lib/analdiffist/text_based_diffist.rb",
40
41
  "spec/fixtures/other_smelly_file.rb",
@@ -44,6 +45,7 @@ Gem::Specification.new do |s|
44
45
  "spec/lib/analdiffist/reek_metrics_spec.rb",
45
46
  "spec/lib/analdiffist/reek_parser_spec.rb",
46
47
  "spec/lib/analdiffist/standard_diffist_spec.rb",
48
+ "spec/lib/analdiffist/std_out_reporter_spec.rb",
47
49
  "spec/lib/analdiffist/target_finder_spec.rb",
48
50
  "spec/spec_helper.rb"
49
51
  ]
@@ -60,6 +62,7 @@ Gem::Specification.new do |s|
60
62
  "spec/lib/analdiffist/reek_metrics_spec.rb",
61
63
  "spec/lib/analdiffist/reek_parser_spec.rb",
62
64
  "spec/lib/analdiffist/standard_diffist_spec.rb",
65
+ "spec/lib/analdiffist/std_out_reporter_spec.rb",
63
66
  "spec/lib/analdiffist/target_finder_spec.rb",
64
67
  "spec/spec_helper.rb"
65
68
  ]
data/lib/anal_diffist.rb CHANGED
@@ -4,8 +4,8 @@ module AnalDiffist
4
4
  require 'analdiffist/reek_parser'
5
5
  require 'analdiffist/flog_parser'
6
6
  require 'analdiffist/diff_set'
7
- require 'analdiffist/text_based_diffist'
8
7
  require 'analdiffist/standard_diffist'
8
+ require 'analdiffist/std_out_reporter'
9
9
 
10
10
  class Diffist
11
11
  end
@@ -10,16 +10,18 @@ module AnalDiffist
10
10
  f = Flog.new
11
11
  f.flog(@paths)
12
12
  problems = []
13
- f.each_by_score{|class_method, score, ignore_for_now| problems << FlogProblem.new(class_method, score)}
14
- problems.select {|p| p.score >= @flog_threshold}
13
+ f.each_by_score{|class_method, score, ignore_for_now| problems << FlogProblem.new(class_method, score, @flog_threshold)}
14
+ problems
15
+ #problems.select {|p| p.score >= @flog_threshold}
15
16
  end
16
17
  end
17
18
 
18
19
  class FlogProblem
19
20
  attr_accessor :context, :score
20
- def initialize class_method, score
21
+ def initialize class_method, score, threshold = 10
21
22
  @context = class_method || '(none)'
22
- @score = score
23
+ @score = score.round(1)
24
+ @flog_threshold = threshold
23
25
  end
24
26
 
25
27
  def type
@@ -27,15 +29,18 @@ module AnalDiffist
27
29
  end
28
30
 
29
31
  def diff other
30
- return self if other.nil?
32
+ return nil if score < @flog_threshold
33
+ return FlogDiff.new(@context, 0, score) if other.nil?
34
+
31
35
  return nil if other.score >= score
32
36
  FlogDiff.new(@context, other.score, score)
33
37
  end
34
38
 
35
39
  def description
36
- "Flog score: #{score}"
40
+ "Flog: #{score}"
37
41
  end
38
42
  end
43
+
39
44
  class FlogDiff
40
45
  attr_accessor :context, :score
41
46
  def initialize context, previous_score, current_score
@@ -48,8 +53,9 @@ module AnalDiffist
48
53
  (@current_score - @previous_score).round(1)
49
54
  end
50
55
 
51
- def description
52
- "Flog: #{@current_score.round(1)} (+#{(@current_score - @previous_score).round(1)})"
56
+ def description(mode = :added)
57
+ indicator = (mode == :added) ? "+" : "-"
58
+ "Flog: #{@current_score.round(1)} (#{indicator}#{(@current_score - @previous_score).round(1)})"
53
59
  end
54
60
  end
55
61
  end
@@ -30,9 +30,9 @@ module AnalDiffist
30
30
  self if other.nil?
31
31
  end
32
32
  def score
33
- 1
33
+ 2
34
34
  end
35
- def description
35
+ def description mode = :added
36
36
  "Reek: #{type}"
37
37
  end
38
38
  end
@@ -41,24 +41,4 @@ module AnalDiffist
41
41
  end
42
42
  end
43
43
 
44
- class StdOutReporter
45
- def report diff, from_rev, to_rev
46
- puts "\n\nAnaldifference between revisions: \n #{from_rev}\n #{to_rev}"
47
- puts "\nAdded:\n"
48
- puts describe(diff.added_problems)
49
- puts "\nRemoved:\n"
50
- puts describe(diff.removed_problems)
51
- puts "\n\n"
52
- end
53
-
54
- def describe(problems)
55
- by_context = problems.group_by {|prob| prob.context}
56
- results = []
57
- by_context.keys.sort.each do |k|
58
- results << " #{k}"
59
- results << by_context[k].map {|p| " #{p.description}"}.join("\n")
60
- end.collect
61
- results.join("\n")
62
- end
63
- end
64
44
  end
@@ -0,0 +1,34 @@
1
+ module AnalDiffist
2
+ class StdOutReporter
3
+ def report diff, from_rev, to_rev
4
+ puts "\n\nAnaldifference between revisions: \n #{from_rev}\n #{to_rev}"
5
+ puts "\nAdded:\n"
6
+ puts describe(diff.added_problems, :added).join("\n")
7
+ puts "\nRemoved:\n"
8
+ puts describe(diff.removed_problems, :removed).join("\n")
9
+ puts "\n\n"
10
+ end
11
+
12
+ def describe(problems, mode)
13
+ results = []
14
+ by_type = problems.group_by do |prob|
15
+ prob.context.split(/(\#|\.)/).first
16
+ end
17
+
18
+ by_type.keys.sort.each do |type_name|
19
+ results << " #{type_name}"
20
+ type_problems = by_type[type_name]
21
+ by_context = type_problems.group_by do |prob|
22
+ name = prob.context[type_name.length..-1]
23
+ end
24
+
25
+ by_context.keys.sort.each do |k|
26
+ results << " #{k == '' ? '(none)' : k}"
27
+ results += by_context[k].map {|p| " #{p.description(mode)}"}
28
+ end
29
+ end
30
+
31
+ results
32
+ end
33
+ end
34
+ end
@@ -55,8 +55,8 @@ describe 'diffing two files' do
55
55
 
56
56
  context 'when scores change' do
57
57
  before do
58
- before = [AnalDiffist::FlogProblem.new('bar', 7.1)]
59
- after = [AnalDiffist::FlogProblem.new('bar', 8.5)]
58
+ before = [AnalDiffist::FlogProblem.new('bar', 17.1)]
59
+ after = [AnalDiffist::FlogProblem.new('bar', 18.5)]
60
60
  @diff = AnalDiffist::DiffSet.new(before, after)
61
61
  end
62
62
 
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe AnalDiffist::StdOutReporter do
4
+ before do
5
+ problems = [
6
+ fake_problem('SomeType#foo', 1, 'A'),
7
+ fake_problem('SomeType#foo', 2, 'B'),
8
+ fake_problem('SomeType#bar', 3, 'C'),
9
+ fake_problem('XXXXSomeOtherType#foobar', 4, 'D'),
10
+ ]
11
+ @results = AnalDiffist::StdOutReporter.new.describe(problems, :added)
12
+ end
13
+
14
+ it 'should have a header for the type' do
15
+ @results.first.should == " SomeType"
16
+ end
17
+
18
+ it 'should have an entry for the method' do
19
+ @results[1].should == " #bar"
20
+ end
21
+
22
+ it 'should have an entry for each problem' do
23
+ @results[2].should == " C"
24
+ end
25
+
26
+ def fake_problem(context, score, description)
27
+ stub('fake problem').tap {|problem|
28
+ problem.stub(:context) {context}
29
+ problem.stub(:description) {description}
30
+ }
31
+ end
32
+ end
33
+
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: analdiffist
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.0
5
+ version: 0.3.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Adam Pearson
@@ -106,6 +106,7 @@ files:
106
106
  - lib/analdiffist/reek_metrics.rb
107
107
  - lib/analdiffist/reek_parser.rb
108
108
  - lib/analdiffist/standard_diffist.rb
109
+ - lib/analdiffist/std_out_reporter.rb
109
110
  - lib/analdiffist/target_finder.rb
110
111
  - lib/analdiffist/text_based_diffist.rb
111
112
  - spec/fixtures/other_smelly_file.rb
@@ -115,6 +116,7 @@ files:
115
116
  - spec/lib/analdiffist/reek_metrics_spec.rb
116
117
  - spec/lib/analdiffist/reek_parser_spec.rb
117
118
  - spec/lib/analdiffist/standard_diffist_spec.rb
119
+ - spec/lib/analdiffist/std_out_reporter_spec.rb
118
120
  - spec/lib/analdiffist/target_finder_spec.rb
119
121
  - spec/spec_helper.rb
120
122
  has_rdoc: true
@@ -131,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
131
133
  requirements:
132
134
  - - ">="
133
135
  - !ruby/object:Gem::Version
134
- hash: -4153762444283860543
136
+ hash: -1146240536421962276
135
137
  segments:
136
138
  - 0
137
139
  version: "0"
@@ -156,5 +158,6 @@ test_files:
156
158
  - spec/lib/analdiffist/reek_metrics_spec.rb
157
159
  - spec/lib/analdiffist/reek_parser_spec.rb
158
160
  - spec/lib/analdiffist/standard_diffist_spec.rb
161
+ - spec/lib/analdiffist/std_out_reporter_spec.rb
159
162
  - spec/lib/analdiffist/target_finder_spec.rb
160
163
  - spec/spec_helper.rb