simplabs-excellent 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/VERSION.yml +1 -1
- data/lib/simplabs/excellent.rb +1 -1
- data/lib/simplabs/excellent/checks.rb +0 -2
- data/lib/simplabs/excellent/runner.rb +2 -3
- metadata +1 -5
- data/lib/simplabs/excellent/checks/block_duplication_check.rb +0 -49
- data/lib/simplabs/excellent/checks/method_duplication_check.rb +0 -49
- data/spec/checks/block_duplication_check_spec.rb +0 -95
- data/spec/checks/method_duplication_check_spec.rb +0 -127
data/History.txt
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
= 1.5.1
|
2
|
+
|
3
|
+
* removed duplication checks (they are just too coarse for dynamic languages like Ruby and especially Rails apps where you would call e.g. params all over the place)
|
4
|
+
* added Rails::ValidationsCheck to the default checks
|
5
|
+
|
1
6
|
= 1.5.0
|
2
7
|
|
3
8
|
* new check Rails::ValidationsCheck that reports ActiveRecord models that do not validate anything
|
data/VERSION.yml
CHANGED
data/lib/simplabs/excellent.rb
CHANGED
@@ -25,8 +25,6 @@ require 'simplabs/excellent/checks/method_name_check'
|
|
25
25
|
require 'simplabs/excellent/checks/module_line_count_check'
|
26
26
|
require 'simplabs/excellent/checks/module_name_check'
|
27
27
|
require 'simplabs/excellent/checks/parameter_number_check'
|
28
|
-
require 'simplabs/excellent/checks/method_duplication_check'
|
29
|
-
require 'simplabs/excellent/checks/block_duplication_check'
|
30
28
|
require 'simplabs/excellent/checks/nested_iterators_check'
|
31
29
|
require 'simplabs/excellent/checks/flog_method_check'
|
32
30
|
require 'simplabs/excellent/checks/flog_block_check'
|
@@ -29,11 +29,10 @@ module Simplabs
|
|
29
29
|
:FlogMethodCheck => { },
|
30
30
|
:FlogBlockCheck => { },
|
31
31
|
:FlogClassCheck => { },
|
32
|
-
:BlockDuplicationCheck => { },
|
33
|
-
:MethodDuplicationCheck => { },
|
34
32
|
:'Rails::AttrProtectedCheck' => { },
|
35
33
|
:'Rails::AttrAccessibleCheck' => { },
|
36
|
-
:'Rails::InstanceVarInPartialCheck' => { }
|
34
|
+
:'Rails::InstanceVarInPartialCheck' => { },
|
35
|
+
:'Rails::ValidationsCheck' => { }
|
37
36
|
}
|
38
37
|
|
39
38
|
attr_accessor :config #:nodoc:
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simplabs-excellent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marco Otte-Witte
|
@@ -48,7 +48,6 @@ files:
|
|
48
48
|
- lib/simplabs/excellent/checks/abc_metric_method_check.rb
|
49
49
|
- lib/simplabs/excellent/checks/assignment_in_conditional_check.rb
|
50
50
|
- lib/simplabs/excellent/checks/base.rb
|
51
|
-
- lib/simplabs/excellent/checks/block_duplication_check.rb
|
52
51
|
- lib/simplabs/excellent/checks/case_missing_else_check.rb
|
53
52
|
- lib/simplabs/excellent/checks/class_line_count_check.rb
|
54
53
|
- lib/simplabs/excellent/checks/class_name_check.rb
|
@@ -63,7 +62,6 @@ files:
|
|
63
62
|
- lib/simplabs/excellent/checks/flog_method_check.rb
|
64
63
|
- lib/simplabs/excellent/checks/for_loop_check.rb
|
65
64
|
- lib/simplabs/excellent/checks/line_count_check.rb
|
66
|
-
- lib/simplabs/excellent/checks/method_duplication_check.rb
|
67
65
|
- lib/simplabs/excellent/checks/method_line_count_check.rb
|
68
66
|
- lib/simplabs/excellent/checks/method_name_check.rb
|
69
67
|
- lib/simplabs/excellent/checks/module_line_count_check.rb
|
@@ -115,7 +113,6 @@ files:
|
|
115
113
|
- lib/simplabs/excellent.rb
|
116
114
|
- spec/checks/abc_metric_method_check_spec.rb
|
117
115
|
- spec/checks/assignment_in_conditional_check_spec.rb
|
118
|
-
- spec/checks/block_duplication_check_spec.rb
|
119
116
|
- spec/checks/case_missing_else_check_spec.rb
|
120
117
|
- spec/checks/class_line_count_check_spec.rb
|
121
118
|
- spec/checks/class_name_check_spec.rb
|
@@ -127,7 +124,6 @@ files:
|
|
127
124
|
- spec/checks/flog_class_check_spec.rb
|
128
125
|
- spec/checks/flog_method_check_spec.rb
|
129
126
|
- spec/checks/for_loop_check_spec.rb
|
130
|
-
- spec/checks/method_duplication_check_spec.rb
|
131
127
|
- spec/checks/method_line_count_check_spec.rb
|
132
128
|
- spec/checks/method_name_check_spec.rb
|
133
129
|
- spec/checks/module_line_count_check_spec.rb
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'simplabs/excellent/checks/base'
|
2
|
-
|
3
|
-
module Simplabs
|
4
|
-
|
5
|
-
module Excellent
|
6
|
-
|
7
|
-
module Checks
|
8
|
-
|
9
|
-
# This check reports duplicated code. It currently finds repeated identical method calls such as:
|
10
|
-
#
|
11
|
-
# def method
|
12
|
-
# other_method + other_method
|
13
|
-
# end
|
14
|
-
#
|
15
|
-
# ==== Applies to
|
16
|
-
#
|
17
|
-
# * blocks
|
18
|
-
class BlockDuplicationCheck < Base
|
19
|
-
|
20
|
-
DEFAULT_THRESHOLD = 1
|
21
|
-
|
22
|
-
def initialize(options = {}) #:nodoc:
|
23
|
-
super()
|
24
|
-
@threshold = options[:threshold] || DEFAULT_THRESHOLD
|
25
|
-
@interesting_nodes = [:iter]
|
26
|
-
end
|
27
|
-
|
28
|
-
def evaluate(context) #:nodoc:
|
29
|
-
context.calls.each do |call, number|
|
30
|
-
if number > @threshold && call.method != 'new'
|
31
|
-
add_warning(
|
32
|
-
context,
|
33
|
-
'{{block}} calls {{statement}} {{duplication_number}} times.', {
|
34
|
-
:block => context.full_name,
|
35
|
-
:statement => call.full_name,
|
36
|
-
:duplication_number => number
|
37
|
-
}
|
38
|
-
)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require 'simplabs/excellent/checks/base'
|
2
|
-
|
3
|
-
module Simplabs
|
4
|
-
|
5
|
-
module Excellent
|
6
|
-
|
7
|
-
module Checks
|
8
|
-
|
9
|
-
# This check reports duplicated code. It currently finds repeated identical method calls such as:
|
10
|
-
#
|
11
|
-
# def method
|
12
|
-
# other_method + other_method
|
13
|
-
# end
|
14
|
-
#
|
15
|
-
# ==== Applies to
|
16
|
-
#
|
17
|
-
# * methods
|
18
|
-
class MethodDuplicationCheck < Base
|
19
|
-
|
20
|
-
DEFAULT_THRESHOLD = 1
|
21
|
-
|
22
|
-
def initialize(options = {}) #:nodoc:
|
23
|
-
super()
|
24
|
-
@threshold = options[:threshold] || DEFAULT_THRESHOLD
|
25
|
-
@interesting_nodes = [:defn, :defs]
|
26
|
-
end
|
27
|
-
|
28
|
-
def evaluate(context) #:nodoc:
|
29
|
-
context.calls.each do |call, number|
|
30
|
-
if number > @threshold && call.method != 'new'
|
31
|
-
add_warning(
|
32
|
-
context,
|
33
|
-
'{{method}} calls {{statement}} {{duplication_number}} times.', {
|
34
|
-
:method => context.full_name,
|
35
|
-
:statement => call.full_name,
|
36
|
-
:duplication_number => number
|
37
|
-
}
|
38
|
-
)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe Simplabs::Excellent::Checks::BlockDuplicationCheck do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::BlockDuplicationCheck.new({ :threshold => 1 }))
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '#evaluate' do
|
10
|
-
|
11
|
-
it 'should accept multiple calls to new' do
|
12
|
-
code = <<-END
|
13
|
-
double_thing do
|
14
|
-
@thing.new + @thing.new
|
15
|
-
end
|
16
|
-
END
|
17
|
-
@excellent.check_code(code)
|
18
|
-
warnings = @excellent.warnings
|
19
|
-
|
20
|
-
warnings.should be_empty
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should reject multiple calls to the same method and receiver' do
|
24
|
-
code = <<-END
|
25
|
-
double_thing do
|
26
|
-
@other.thing + @other.thing
|
27
|
-
end
|
28
|
-
END
|
29
|
-
|
30
|
-
verify_warning_found(code, '@other.thing')
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should reject multiple calls to the same lvar' do
|
34
|
-
code = <<-END
|
35
|
-
double_thing do
|
36
|
-
thing[1] + thing[2]
|
37
|
-
end
|
38
|
-
END
|
39
|
-
|
40
|
-
verify_warning_found(code, 'thing.[]')
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should reject multiple calls to the same singleton method' do
|
44
|
-
code = <<-END
|
45
|
-
double_thing do
|
46
|
-
Class.thing[1] + Class.thing[2]
|
47
|
-
end
|
48
|
-
END
|
49
|
-
|
50
|
-
verify_warning_found(code, 'Class.thing')
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should reject multiple calls to the same method without a receiver' do
|
54
|
-
code = <<-END
|
55
|
-
double_thing do
|
56
|
-
thing + thing
|
57
|
-
end
|
58
|
-
END
|
59
|
-
|
60
|
-
verify_warning_found(code, 'thing')
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should reject multiple calls to the same method with the same parameters' do
|
64
|
-
code = <<-END
|
65
|
-
double_thing do
|
66
|
-
thing(1) + thing(1)
|
67
|
-
end
|
68
|
-
END
|
69
|
-
|
70
|
-
verify_warning_found(code, 'thing')
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'should reject multiple calls to the same method with different parameters' do
|
74
|
-
code = <<-END
|
75
|
-
double_thing do
|
76
|
-
thing(1) + thing(2)
|
77
|
-
end
|
78
|
-
END
|
79
|
-
|
80
|
-
verify_warning_found(code, 'thing')
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
def verify_warning_found(code, statement)
|
86
|
-
@excellent.check_code(code)
|
87
|
-
warnings = @excellent.warnings
|
88
|
-
|
89
|
-
warnings.should_not be_empty
|
90
|
-
warnings[0].info.should == { :block => 'block', :statement => statement, :duplication_number => 2 }
|
91
|
-
warnings[0].line_number.should == 1
|
92
|
-
warnings[0].message.should == "block calls #{statement} 2 times."
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
@@ -1,127 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
-
|
3
|
-
describe Simplabs::Excellent::Checks::MethodDuplicationCheck do
|
4
|
-
|
5
|
-
before do
|
6
|
-
@excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::MethodDuplicationCheck.new({ :threshold => 1 }))
|
7
|
-
end
|
8
|
-
|
9
|
-
describe '#evaluate' do
|
10
|
-
|
11
|
-
it 'should accept multiple calls to new' do
|
12
|
-
code = <<-END
|
13
|
-
def double_thing
|
14
|
-
@thing.new + @thing.new
|
15
|
-
end
|
16
|
-
END
|
17
|
-
@excellent.check_code(code)
|
18
|
-
warnings = @excellent.warnings
|
19
|
-
|
20
|
-
warnings.should be_empty
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'should reject multiple calls to the same method and receiver' do
|
24
|
-
code = <<-END
|
25
|
-
def double_thing
|
26
|
-
@other.thing + @other.thing
|
27
|
-
end
|
28
|
-
END
|
29
|
-
|
30
|
-
verify_warning_found(code, '@other.thing')
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'should reject multiple calls to the same lvar' do
|
34
|
-
code = <<-END
|
35
|
-
def double_thing
|
36
|
-
thing[1] + thing[2]
|
37
|
-
end
|
38
|
-
END
|
39
|
-
|
40
|
-
verify_warning_found(code, 'thing.[]')
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'should reject multiple calls to the same singleton method' do
|
44
|
-
code = <<-END
|
45
|
-
def double_thing
|
46
|
-
Class.thing[1] + Class.thing[2]
|
47
|
-
end
|
48
|
-
END
|
49
|
-
|
50
|
-
verify_warning_found(code, 'Class.thing')
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'should reject multiple calls to the same method without a receiver' do
|
54
|
-
code = <<-END
|
55
|
-
def double_thing
|
56
|
-
thing + thing
|
57
|
-
end
|
58
|
-
END
|
59
|
-
|
60
|
-
verify_warning_found(code, 'thing')
|
61
|
-
end
|
62
|
-
|
63
|
-
it 'should reject multiple calls to the same method with the same parameters' do
|
64
|
-
code = <<-END
|
65
|
-
def double_thing
|
66
|
-
thing(1) + thing(1)
|
67
|
-
end
|
68
|
-
END
|
69
|
-
|
70
|
-
verify_warning_found(code, 'thing')
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'should reject multiple calls to the same method with different parameters' do
|
74
|
-
code = <<-END
|
75
|
-
def double_thing
|
76
|
-
thing(1) + thing(2)
|
77
|
-
end
|
78
|
-
END
|
79
|
-
|
80
|
-
verify_warning_found(code, 'thing')
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'should work with singleton methods on objects' do
|
84
|
-
code = <<-END
|
85
|
-
def object.double_thing
|
86
|
-
thing(1) + thing(2)
|
87
|
-
end
|
88
|
-
END
|
89
|
-
|
90
|
-
verify_warning_found(code, 'thing', 'object.double_thing')
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'should work with singleton methods on classes' do
|
94
|
-
code = <<-END
|
95
|
-
def Class.double_thing
|
96
|
-
thing(1) + thing(2)
|
97
|
-
end
|
98
|
-
END
|
99
|
-
|
100
|
-
verify_warning_found(code, 'thing', 'Class.double_thing')
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'should work with singleton methods on classes' do
|
104
|
-
code = <<-END
|
105
|
-
class Class
|
106
|
-
def self.double_thing
|
107
|
-
thing(1) + thing(2)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
END
|
111
|
-
|
112
|
-
verify_warning_found(code, 'thing', 'Class.double_thing', 2)
|
113
|
-
end
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
def verify_warning_found(code, statement, method = 'double_thing', line = 1)
|
118
|
-
@excellent.check_code(code)
|
119
|
-
warnings = @excellent.warnings
|
120
|
-
|
121
|
-
warnings.should_not be_empty
|
122
|
-
warnings[0].info.should == { :method => method, :statement => statement, :duplication_number => 2 }
|
123
|
-
warnings[0].line_number.should == line
|
124
|
-
warnings[0].message.should == "#{method} calls #{statement} 2 times."
|
125
|
-
end
|
126
|
-
|
127
|
-
end
|