ruby-watchr 0.1.6.4 → 0.1.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/watchr/analysers/flog.rb +2 -2
- data/lib/watchr/analysers/reek.rb +12 -12
- data/lib/watchr/rating.rb +6 -6
- data/lib/watchr/smell_types.rb +27 -50
- data/lib/watchr/version.rb +1 -1
- data/spec/watchr/analysers/flog_spec.rb +3 -3
- data/spec/watchr/rating_spec.rb +2 -2
- metadata +2 -2
@@ -46,7 +46,7 @@ module Watchr
|
|
46
46
|
threshold = get_threshold(:very_complex, type)
|
47
47
|
complexity = target.total_score >= threshold ? :very_complex : :complex
|
48
48
|
|
49
|
-
get_smell_type(complexity, type
|
49
|
+
get_smell_type(complexity, type)
|
50
50
|
end
|
51
51
|
|
52
52
|
def get_threshold(complexity, type)
|
@@ -54,7 +54,7 @@ module Watchr
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def get_smell_type(complexity, type)
|
57
|
-
|
57
|
+
"#{complexity}_#{type}".to_sym
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -12,21 +12,21 @@ module Watchr
|
|
12
12
|
smell.location['lines'].first
|
13
13
|
)
|
14
14
|
|
15
|
-
type = case smell.smell['subclass']
|
16
|
-
when 'IrresponsibleModule' then IRRESPONSIBLE_MODULE
|
17
|
-
when 'DuplicateMethodCall' then DUPLICATE_METHOD_CALL
|
18
|
-
when 'NestedIterators' then NESTED_ITERATORS
|
19
|
-
when 'TooManyStatements' then TOO_MANY_STATEMENTS
|
20
|
-
when 'FeatureEnvy' then FEATURE_ENVY
|
21
|
-
when 'UtilityFunction' then UTILITY_FUNCTION
|
22
|
-
else nil
|
23
|
-
end
|
24
|
-
|
25
15
|
add_smell(Watchr::Smell.new(
|
26
|
-
|
27
|
-
))
|
16
|
+
underscore(smell.smell['subclass']).to_sym, smell.location['context'], smell.smell['message'], location, {}
|
17
|
+
))
|
28
18
|
end
|
29
19
|
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def underscore(text)
|
24
|
+
text.gsub(/::/, '/').
|
25
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
26
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
27
|
+
tr("-", "_").
|
28
|
+
downcase
|
29
|
+
end
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
data/lib/watchr/rating.rb
CHANGED
@@ -16,16 +16,16 @@ module Watchr
|
|
16
16
|
|
17
17
|
def rate(smell)
|
18
18
|
case smell.type
|
19
|
-
when
|
20
|
-
|
19
|
+
when :complex_method,
|
20
|
+
:very_complex_method
|
21
21
|
0.45 * smell.options[:score]
|
22
22
|
|
23
|
-
when
|
24
|
-
|
23
|
+
when :complex_object,
|
24
|
+
:very_complex_object
|
25
25
|
0.65 * smell.options[:score]
|
26
26
|
|
27
|
-
when
|
28
|
-
|
27
|
+
when :identical_code,
|
28
|
+
:similar_code
|
29
29
|
smell.options[:mass]
|
30
30
|
else
|
31
31
|
0
|
data/lib/watchr/smell_types.rb
CHANGED
@@ -1,56 +1,33 @@
|
|
1
1
|
module Watchr
|
2
2
|
module SmellTypes
|
3
|
-
#
|
4
|
-
# Method complexity is high.
|
5
|
-
#
|
6
|
-
COMPLEX_METHOD = :complex_method
|
7
|
-
|
8
|
-
#
|
9
|
-
# Method complexity is very high.
|
10
|
-
#
|
11
|
-
VERY_COMPLEX_METHOD = :very_complex_method
|
12
|
-
|
13
|
-
#
|
14
|
-
# Object (class / module) total complexity is high.
|
15
|
-
#
|
16
|
-
COMPLEX_OBJECT = :complex_object
|
17
|
-
|
18
|
-
#
|
19
|
-
# Object (class / module) total complexity is very high.
|
20
|
-
#
|
21
|
-
VERY_COMPLEX_OBJECT = :very_complex_object
|
22
|
-
|
23
|
-
#
|
24
|
-
# Code in multiple places is identical.
|
25
|
-
#
|
26
|
-
IDENTICAL_CODE = :identical_code
|
27
|
-
|
28
|
-
#
|
29
|
-
# Code in multiple places is similar (not identical).
|
30
|
-
#
|
31
|
-
SIMILAR_CODE = :similar_code
|
32
|
-
|
33
|
-
|
34
|
-
IRRESPONSIBLE_MODULE = :irresponsible_module
|
35
|
-
DUPLICATE_METHOD_CALL = :duplicate_method_call
|
36
|
-
NESTED_ITERATORS = :nested_iterators
|
37
|
-
TOO_MANY_STATEMENTS = :too_many_statements
|
38
|
-
FEATURE_ENVY = :feature_envy
|
39
|
-
UTILITY_FUNCTION = :utility_function
|
40
|
-
|
41
3
|
ALL_SMELLS = [
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
4
|
+
:complex_method,
|
5
|
+
:very_complex_method,
|
6
|
+
:complex_object,
|
7
|
+
:very_complex_object,
|
8
|
+
|
9
|
+
:identical_code,
|
10
|
+
:similar_code,
|
11
|
+
|
12
|
+
:attribute,
|
13
|
+
:boolean_parameter,
|
14
|
+
:class_variable,
|
15
|
+
:control_couple,
|
16
|
+
:data_clump,
|
17
|
+
:duplication,
|
18
|
+
:feature_envy,
|
19
|
+
:irresponsible_module,
|
20
|
+
:large_class,
|
21
|
+
:long_method,
|
22
|
+
:long_parameter_list,
|
23
|
+
:long_yield_list,
|
24
|
+
:nested_iterators,
|
25
|
+
:simulated_polymorphism,
|
26
|
+
:uncommunicative_method_name,
|
27
|
+
:uncommunicative_module_name,
|
28
|
+
:uncommunicative_parameter_name,
|
29
|
+
:uncommunicative_variable_name,
|
30
|
+
:utility_function
|
54
31
|
]
|
55
32
|
end
|
56
33
|
end
|
data/lib/watchr/version.rb
CHANGED
@@ -47,7 +47,7 @@ describe Watchr::Analysers::Flog do
|
|
47
47
|
|
48
48
|
it 'should add smell for complex method' do
|
49
49
|
Watchr::Smell.expects(:new).with(
|
50
|
-
|
50
|
+
:complex_method,
|
51
51
|
complex_method.name,
|
52
52
|
'',
|
53
53
|
complex_method.location,
|
@@ -61,7 +61,7 @@ describe Watchr::Analysers::Flog do
|
|
61
61
|
|
62
62
|
it 'should add smell for very complex method' do
|
63
63
|
Watchr::Smell.expects(:new).with(
|
64
|
-
|
64
|
+
:very_complex_method,
|
65
65
|
very_complex_method.name,
|
66
66
|
'',
|
67
67
|
very_complex_method.location,
|
@@ -75,7 +75,7 @@ describe Watchr::Analysers::Flog do
|
|
75
75
|
|
76
76
|
it 'should add smell for very complex object' do
|
77
77
|
Watchr::Smell.expects(:new).with(
|
78
|
-
|
78
|
+
:very_complex_object,
|
79
79
|
clazz.name,
|
80
80
|
'',
|
81
81
|
clazz.location,
|
data/spec/watchr/rating_spec.rb
CHANGED
@@ -5,7 +5,7 @@ describe Watchr::Rating do
|
|
5
5
|
|
6
6
|
let(:complexity_smell) {
|
7
7
|
stub('smell',
|
8
|
-
:type =>
|
8
|
+
:type => :complex_method,
|
9
9
|
:options => {:score => 29.3}
|
10
10
|
)
|
11
11
|
}
|
@@ -18,7 +18,7 @@ describe Watchr::Rating do
|
|
18
18
|
|
19
19
|
let(:duplication_smell) {
|
20
20
|
stub('smell',
|
21
|
-
:type =>
|
21
|
+
:type => :identical_code,
|
22
22
|
:options => {:mass => 72})
|
23
23
|
}
|
24
24
|
|