ruby-watchr 0.1.7.1 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/watchr/analyse.rb +3 -4
- data/lib/watchr/analysers/flog.rb +18 -12
- data/lib/watchr/analysers/reek.rb +4 -1
- data/lib/watchr/file_analyse.rb +0 -1
- data/lib/watchr/metrics/flay/diff.rb +1 -5
- data/lib/watchr/metrics/flay/diff_factory.rb +18 -0
- data/lib/watchr/metrics/flay/report.rb +2 -10
- data/lib/watchr/metrics/flog/class_report_factory.rb +26 -0
- data/lib/watchr/metrics/flog/report.rb +9 -22
- data/lib/watchr/rating.rb +3 -3
- data/lib/watchr/smell.rb +4 -4
- data/lib/watchr/version.rb +1 -1
- data/spec/watchr/analysers/flog_spec.rb +6 -3
- data/spec/watchr/{flay → metrics/flay}/report_spec.rb +0 -0
- data/spec/watchr/{flog_metric/flog_matric → metrics/flog}/flog_report_spec.rb +0 -0
- data/spec/watchr/rating_spec.rb +2 -2
- data/spec/watchr/smell_spec.rb +3 -3
- metadata +9 -8
data/lib/watchr/analyse.rb
CHANGED
@@ -31,10 +31,9 @@ module Watchr
|
|
31
31
|
|
32
32
|
# Create report for each file.
|
33
33
|
@files = files.map do |file|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
file_report
|
34
|
+
Watchr::FileAnalyse.new(file).tap { |file|
|
35
|
+
file.flay(flay.duplications_by_file(file))
|
36
|
+
}
|
38
37
|
end
|
39
38
|
end
|
40
39
|
end
|
@@ -11,7 +11,7 @@ module Watchr
|
|
11
11
|
|
12
12
|
VERY_COMPLEX_METHOD_THRESHOLD = 40
|
13
13
|
|
14
|
-
COMPLEX_METHOD_THRESHOLD =
|
14
|
+
COMPLEX_METHOD_THRESHOLD = 25
|
15
15
|
|
16
16
|
def analyse_flog(report)
|
17
17
|
report.classes.each do |klass|
|
@@ -34,27 +34,33 @@ module Watchr
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def analyse_complexity(target, type)
|
37
|
+
score = target.total_score
|
38
|
+
|
37
39
|
add_smell(
|
38
40
|
Watchr::Smell.new(
|
39
|
-
|
40
|
-
|
41
|
+
smell_type(score, type), target.name,
|
42
|
+
"complexity = #{score}", target.location,
|
43
|
+
{ :complexity => score }
|
41
44
|
)
|
42
|
-
) if
|
45
|
+
) if is_complex?(score, type)
|
43
46
|
end
|
44
47
|
|
45
|
-
def
|
46
|
-
|
47
|
-
complexity = target.total_score >= threshold ? :very_complex : :complex
|
48
|
+
def smell_type(score, type)
|
49
|
+
complexity = is_very_complex?(score, type) ? :very_complex : :complex
|
48
50
|
|
49
|
-
|
51
|
+
"#{complexity}_#{type}".to_sym
|
50
52
|
end
|
51
53
|
|
52
|
-
def
|
53
|
-
|
54
|
+
def is_complex?(score, type)
|
55
|
+
is_complex_by_level?(score, type, :complex)
|
54
56
|
end
|
55
57
|
|
56
|
-
def
|
57
|
-
|
58
|
+
def is_very_complex?(score, type)
|
59
|
+
is_complex_by_level?(score, type, :very_complex)
|
60
|
+
end
|
61
|
+
|
62
|
+
def is_complex_by_level?(score, type, level)
|
63
|
+
score >= Flog.const_get("#{level.upcase}_#{type.upcase}_THRESHOLD")
|
58
64
|
end
|
59
65
|
end
|
60
66
|
end
|
@@ -13,7 +13,10 @@ module Watchr
|
|
13
13
|
)
|
14
14
|
|
15
15
|
add_smell(Watchr::Smell.new(
|
16
|
-
underscore(smell.smell['subclass']).to_sym,
|
16
|
+
underscore(smell.smell['subclass']).to_sym,
|
17
|
+
smell.location['context'],
|
18
|
+
smell.smell['message'],
|
19
|
+
location
|
17
20
|
))
|
18
21
|
end
|
19
22
|
end
|
data/lib/watchr/file_analyse.rb
CHANGED
@@ -1,15 +1,11 @@
|
|
1
1
|
module Watchr
|
2
2
|
module FlayMetric
|
3
3
|
class Diff
|
4
|
-
IDENTICAL = :identical
|
5
|
-
|
6
|
-
SIMILAR = :similar
|
7
|
-
|
8
4
|
attr_reader :locations, :match, :nodes, :bonus, :mass, :code
|
9
5
|
|
10
6
|
def initialize(same, nodes, bonus, mass)
|
11
7
|
@locations = []
|
12
|
-
@match = same ?
|
8
|
+
@match = same ? :identical : :similar
|
13
9
|
@nodes = nodes
|
14
10
|
@bonus = bonus
|
15
11
|
@mass = mass
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Watchr
|
2
|
+
module FlayMetric
|
3
|
+
class DiffFactory
|
4
|
+
def self.build(same, nodes, bonus, mass)
|
5
|
+
diff = Diff.new(same, nodes, bonus, mass)
|
6
|
+
|
7
|
+
nodes.each do |x|
|
8
|
+
diff.add_location(Location.new(x.file, x.line))
|
9
|
+
end
|
10
|
+
|
11
|
+
#r2r = Ruby2Ruby.new
|
12
|
+
#diff.code = n_way_diff(*nodes.map { |s| r2r.process(s.deep_clone) })
|
13
|
+
|
14
|
+
diff
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'flay'
|
2
2
|
require 'watchr/metrics/flay/diff'
|
3
|
+
require 'watchr/metrics/flay/diff_factory'
|
3
4
|
require 'watchr/location'
|
4
5
|
|
5
6
|
module Watchr
|
@@ -37,16 +38,7 @@ module Watchr
|
|
37
38
|
node = nodes.first
|
38
39
|
bonus = same ? nodes.size : 0
|
39
40
|
|
40
|
-
|
41
|
-
|
42
|
-
nodes.each do |x|
|
43
|
-
diff.add_location(Location.new(x.file, x.line))
|
44
|
-
end
|
45
|
-
|
46
|
-
r2r = Ruby2Ruby.new
|
47
|
-
diff.code = n_way_diff(*nodes.map { |s| r2r.process(s.deep_clone) })
|
48
|
-
|
49
|
-
@duplications << diff
|
41
|
+
@duplications << DiffFactory.build(same, nodes, bonus, mass)
|
50
42
|
end
|
51
43
|
end
|
52
44
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'watchr/metrics/flog/class'
|
2
|
+
require 'watchr/metrics/flog/method'
|
3
|
+
require 'watchr/location'
|
4
|
+
|
5
|
+
module Watchr
|
6
|
+
module FlogMetric
|
7
|
+
class ClassReportFactory
|
8
|
+
def self.build(klass, total, methods, method_locations)
|
9
|
+
clazz = FlogReportClass.new(klass, total)
|
10
|
+
|
11
|
+
methods.each do |name, score|
|
12
|
+
next if name =~ /#none/
|
13
|
+
|
14
|
+
clazz.add_method(
|
15
|
+
FlogReportMethod.new(
|
16
|
+
clazz, name, score,
|
17
|
+
Location.from_path(method_locations[name])
|
18
|
+
)
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
clazz
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,7 +1,5 @@
|
|
1
1
|
require 'flog'
|
2
|
-
require 'watchr/metrics/flog/
|
3
|
-
require 'watchr/metrics/flog/method'
|
4
|
-
require 'watchr/location'
|
2
|
+
require 'watchr/metrics/flog/class_report_factory'
|
5
3
|
|
6
4
|
module Watchr
|
7
5
|
module FlogMetric
|
@@ -47,11 +45,9 @@ module Watchr
|
|
47
45
|
|
48
46
|
private
|
49
47
|
|
50
|
-
def
|
51
|
-
@classes = []
|
52
|
-
|
48
|
+
def process_scores
|
53
49
|
scores = Hash.new 0
|
54
|
-
methods = Hash.new { |
|
50
|
+
methods = Hash.new { |hash,key| hash[key] = [] }
|
55
51
|
|
56
52
|
each_by_score(nil) do |class_method, score, call_list|
|
57
53
|
klass = class_method.split(/#|::/)[0..-2].join('::')
|
@@ -60,23 +56,14 @@ module Watchr
|
|
60
56
|
scores[klass] += score
|
61
57
|
end
|
62
58
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
methods[klass].each do |name, score|
|
67
|
-
next if name =~ /#none/
|
59
|
+
return methods, scores
|
60
|
+
end
|
68
61
|
|
69
|
-
|
70
|
-
|
71
|
-
clazz,
|
72
|
-
name,
|
73
|
-
score,
|
74
|
-
Location.from_path(method_locations[name])
|
75
|
-
)
|
76
|
-
)
|
77
|
-
end
|
62
|
+
def process_result
|
63
|
+
methods, scores = process_scores
|
78
64
|
|
79
|
-
|
65
|
+
@classes = scores.map do |klass, total|
|
66
|
+
ClassReportFactory.build(klass, total, methods[klass], method_locations)
|
80
67
|
end
|
81
68
|
end
|
82
69
|
end
|
data/lib/watchr/rating.rb
CHANGED
@@ -18,15 +18,15 @@ module Watchr
|
|
18
18
|
case smell.type
|
19
19
|
when :complex_method,
|
20
20
|
:very_complex_method
|
21
|
-
0.45 * smell.
|
21
|
+
0.45 * smell.details[:complexity]
|
22
22
|
|
23
23
|
when :complex_object,
|
24
24
|
:very_complex_object
|
25
|
-
0.65 * smell.
|
25
|
+
0.65 * smell.details[:complexity]
|
26
26
|
|
27
27
|
when :identical_code,
|
28
28
|
:similar_code
|
29
|
-
smell.
|
29
|
+
smell.details[:mass]
|
30
30
|
else
|
31
31
|
0
|
32
32
|
end
|
data/lib/watchr/smell.rb
CHANGED
@@ -4,12 +4,12 @@ module Watchr
|
|
4
4
|
class Smell
|
5
5
|
include SmellTypes
|
6
6
|
|
7
|
-
def initialize(type, context, description, locations,
|
7
|
+
def initialize(type, context, description, locations, details = {})
|
8
8
|
@type = type
|
9
9
|
@context = context
|
10
10
|
@description = description
|
11
11
|
@locations = []
|
12
|
-
@
|
12
|
+
@details = details
|
13
13
|
|
14
14
|
Array(locations).each {|l| add_location(l)}
|
15
15
|
end
|
@@ -30,8 +30,8 @@ module Watchr
|
|
30
30
|
@context
|
31
31
|
end
|
32
32
|
|
33
|
-
def
|
34
|
-
@
|
33
|
+
def details
|
34
|
+
@details
|
35
35
|
end
|
36
36
|
|
37
37
|
def add_location(location)
|
data/lib/watchr/version.rb
CHANGED
@@ -50,7 +50,8 @@ describe Watchr::Analysers::Flog do
|
|
50
50
|
:complex_method,
|
51
51
|
complex_method.name,
|
52
52
|
"complexity = #{complex_method.total_score}",
|
53
|
-
complex_method.location
|
53
|
+
complex_method.location,
|
54
|
+
{ :complexity => complex_method.total_score }
|
54
55
|
)
|
55
56
|
|
56
57
|
analyse.expects(:add_smell).returns(smell)
|
@@ -63,7 +64,8 @@ describe Watchr::Analysers::Flog do
|
|
63
64
|
:very_complex_method,
|
64
65
|
very_complex_method.name,
|
65
66
|
"complexity = #{very_complex_method.total_score}",
|
66
|
-
very_complex_method.location
|
67
|
+
very_complex_method.location,
|
68
|
+
{ :complexity => very_complex_method.total_score }
|
67
69
|
)
|
68
70
|
|
69
71
|
analyse.expects(:add_smell).returns(smell)
|
@@ -76,7 +78,8 @@ describe Watchr::Analysers::Flog do
|
|
76
78
|
:very_complex_object,
|
77
79
|
clazz.name,
|
78
80
|
"complexity = #{clazz.total_score}",
|
79
|
-
clazz.location
|
81
|
+
clazz.location,
|
82
|
+
{ :complexity => clazz.total_score }
|
80
83
|
)
|
81
84
|
|
82
85
|
analyse.expects(:add_smell).returns(smell)
|
File without changes
|
File without changes
|
data/spec/watchr/rating_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe Watchr::Rating do
|
|
6
6
|
let(:complexity_smell) {
|
7
7
|
stub('smell',
|
8
8
|
:type => :complex_method,
|
9
|
-
:
|
9
|
+
:details => {:complexity => 29.3}
|
10
10
|
)
|
11
11
|
}
|
12
12
|
|
@@ -19,7 +19,7 @@ describe Watchr::Rating do
|
|
19
19
|
let(:duplication_smell) {
|
20
20
|
stub('smell',
|
21
21
|
:type => :identical_code,
|
22
|
-
:
|
22
|
+
:details => {:mass => 72})
|
23
23
|
}
|
24
24
|
|
25
25
|
let(:smells) { [complexity_smell, other_smell, duplication_smell] }
|
data/spec/watchr/smell_spec.rb
CHANGED
@@ -13,9 +13,9 @@ describe Watchr::Smell do
|
|
13
13
|
|
14
14
|
let(:context) { 'context' }
|
15
15
|
|
16
|
-
let(:
|
16
|
+
let(:details) { stub('details') }
|
17
17
|
|
18
|
-
let(:smell) { Watchr::Smell.new(type, context, description, locations,
|
18
|
+
let(:smell) { Watchr::Smell.new(type, context, description, locations, details) }
|
19
19
|
|
20
20
|
subject { smell }
|
21
21
|
|
@@ -39,7 +39,7 @@ describe Watchr::Smell do
|
|
39
39
|
|
40
40
|
its(:description) { should == description }
|
41
41
|
|
42
|
-
its(:
|
42
|
+
its(:details) { should == details }
|
43
43
|
|
44
44
|
its(:context) { should == context }
|
45
45
|
end
|
metadata
CHANGED
@@ -5,9 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.1.7.1
|
8
|
+
- 8
|
9
|
+
version: 0.1.8
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Petr Janda
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2012-07-
|
17
|
+
date: 2012-07-28 00:00:00 +02:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -92,8 +91,10 @@ files:
|
|
92
91
|
- lib/watchr/file_analyse.rb
|
93
92
|
- lib/watchr/location.rb
|
94
93
|
- lib/watchr/metrics/flay/diff.rb
|
94
|
+
- lib/watchr/metrics/flay/diff_factory.rb
|
95
95
|
- lib/watchr/metrics/flay/report.rb
|
96
96
|
- lib/watchr/metrics/flog/class.rb
|
97
|
+
- lib/watchr/metrics/flog/class_report_factory.rb
|
97
98
|
- lib/watchr/metrics/flog/method.rb
|
98
99
|
- lib/watchr/metrics/flog/report.rb
|
99
100
|
- lib/watchr/metrics/reek/report.rb
|
@@ -109,9 +110,9 @@ files:
|
|
109
110
|
- spec/watchr/analyse_spec.rb
|
110
111
|
- spec/watchr/analysers/flog_spec.rb
|
111
112
|
- spec/watchr/file_analyse_spec.rb
|
112
|
-
- spec/watchr/flay/report_spec.rb
|
113
|
-
- spec/watchr/flog_metric/flog_matric/flog_report_spec.rb
|
114
113
|
- spec/watchr/location_spec.rb
|
114
|
+
- spec/watchr/metrics/flay/report_spec.rb
|
115
|
+
- spec/watchr/metrics/flog/flog_report_spec.rb
|
115
116
|
- spec/watchr/paths_spec.rb
|
116
117
|
- spec/watchr/rating_spec.rb
|
117
118
|
- spec/watchr/smell_spec.rb
|
@@ -156,9 +157,9 @@ test_files:
|
|
156
157
|
- spec/watchr/analyse_spec.rb
|
157
158
|
- spec/watchr/analysers/flog_spec.rb
|
158
159
|
- spec/watchr/file_analyse_spec.rb
|
159
|
-
- spec/watchr/flay/report_spec.rb
|
160
|
-
- spec/watchr/flog_metric/flog_matric/flog_report_spec.rb
|
161
160
|
- spec/watchr/location_spec.rb
|
161
|
+
- spec/watchr/metrics/flay/report_spec.rb
|
162
|
+
- spec/watchr/metrics/flog/flog_report_spec.rb
|
162
163
|
- spec/watchr/paths_spec.rb
|
163
164
|
- spec/watchr/rating_spec.rb
|
164
165
|
- spec/watchr/smell_spec.rb
|