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.
@@ -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.upcase)
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
- Watchr::SmellTypes.const_get("#{complexity.upcase}_#{type.upcase}")
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
- type, smell.location['context'], smell.smell['message'], location, {}
27
- )) unless type.nil?
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 COMPLEX_METHOD,
20
- VERY_COMPLEX_METHOD
19
+ when :complex_method,
20
+ :very_complex_method
21
21
  0.45 * smell.options[:score]
22
22
 
23
- when COMPLEX_OBJECT,
24
- VERY_COMPLEX_OBJECT
23
+ when :complex_object,
24
+ :very_complex_object
25
25
  0.65 * smell.options[:score]
26
26
 
27
- when IDENTICAL_CODE,
28
- SIMILAR_CODE
27
+ when :identical_code,
28
+ :similar_code
29
29
  smell.options[:mass]
30
30
  else
31
31
  0
@@ -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
- COMPLEX_METHOD,
43
- VERY_COMPLEX_METHOD,
44
- COMPLEX_OBJECT,
45
- VERY_COMPLEX_OBJECT,
46
- IDENTICAL_CODE,
47
- SIMILAR_CODE,
48
- IRRESPONSIBLE_MODULE,
49
- DUPLICATE_METHOD_CALL,
50
- NESTED_ITERATORS,
51
- TOO_MANY_STATEMENTS,
52
- FEATURE_ENVY,
53
- UTILITY_FUNCTION
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
@@ -1,3 +1,3 @@
1
1
  module Watchr
2
- VERSION = "0.1.6.4"
2
+ VERSION = "0.1.6.5"
3
3
  end
@@ -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
- Watchr::Smell::COMPLEX_METHOD,
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
- Watchr::Smell::VERY_COMPLEX_METHOD,
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
- Watchr::Smell::VERY_COMPLEX_OBJECT,
78
+ :very_complex_object,
79
79
  clazz.name,
80
80
  '',
81
81
  clazz.location,
@@ -5,7 +5,7 @@ describe Watchr::Rating do
5
5
 
6
6
  let(:complexity_smell) {
7
7
  stub('smell',
8
- :type => Watchr::SmellTypes::COMPLEX_METHOD,
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 => Watchr::SmellTypes::IDENTICAL_CODE,
21
+ :type => :identical_code,
22
22
  :options => {:mass => 72})
23
23
  }
24
24
 
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 0
7
7
  - 1
8
8
  - 6
9
- - 4
10
- version: 0.1.6.4
9
+ - 5
10
+ version: 0.1.6.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Petr Janda