simplabs-excellent 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/VERSION.yml +1 -1
- data/lib/simplabs/excellent.rb +1 -1
- data/spec/checks/abc_metric_method_check_spec.rb +17 -17
- data/spec/checks/assignment_in_conditional_check_spec.rb +18 -18
- data/spec/checks/case_missing_else_check_spec.rb +4 -4
- data/spec/checks/class_line_count_check_spec.rb +8 -8
- data/spec/checks/class_name_check_spec.rb +7 -7
- data/spec/checks/control_coupling_check_spec.rb +14 -14
- data/spec/checks/cyclomatic_complexity_block_check_spec.rb +6 -6
- data/spec/checks/cyclomatic_complexity_method_check_spec.rb +28 -28
- data/spec/checks/duplication_check_spec.rb +24 -24
- data/spec/checks/empty_rescue_body_check_spec.rb +29 -29
- data/spec/checks/flog_block_check_spec.rb +2 -2
- data/spec/checks/flog_class_check_spec.rb +2 -2
- data/spec/checks/flog_method_check_spec.rb +6 -6
- data/spec/checks/for_loop_check_spec.rb +8 -8
- data/spec/checks/method_line_count_check_spec.rb +6 -6
- data/spec/checks/method_name_check_spec.rb +16 -16
- data/spec/checks/module_line_count_check_spec.rb +6 -6
- data/spec/checks/module_name_check_spec.rb +8 -8
- data/spec/checks/nested_iterators_check_spec.rb +4 -4
- data/spec/checks/parameter_number_check_spec.rb +18 -18
- data/spec/checks/rails/attr_accessible_check_spec.rb +10 -10
- data/spec/checks/rails/attr_protected_check_spec.rb +10 -10
- data/spec/checks/singleton_variable_check_spec.rb +6 -6
- metadata +1 -1
data/History.txt
CHANGED
data/VERSION.yml
CHANGED
data/lib/simplabs/excellent.rb
CHANGED
@@ -11,26 +11,26 @@ describe Simplabs::Excellent::Checks::AbcMetricMethodCheck do
|
|
11
11
|
describe 'when processing assignments' do
|
12
12
|
|
13
13
|
it "should find =" do
|
14
|
-
|
14
|
+
code = <<-END
|
15
15
|
def method_name
|
16
16
|
foo = 1
|
17
17
|
end
|
18
18
|
END
|
19
19
|
|
20
|
-
|
20
|
+
verify_code_score(code, 1, 0, 0)
|
21
21
|
end
|
22
22
|
|
23
23
|
['*=', '/=', '%=', '+=', '<<=', '>>=', '&=', '|=', '^=', '-=', '**='].each do |assignment|
|
24
24
|
|
25
25
|
it "should find #{assignment}" do
|
26
|
-
|
26
|
+
code = <<-END
|
27
27
|
def method_name
|
28
28
|
foo #{assignment} 1
|
29
29
|
end
|
30
30
|
END
|
31
31
|
|
32
32
|
# these special assignments have score 2 since before the value is assigned, a method is called on the old value
|
33
|
-
|
33
|
+
verify_code_score(code, 1, 0, 1)
|
34
34
|
end
|
35
35
|
|
36
36
|
end
|
@@ -40,33 +40,33 @@ describe Simplabs::Excellent::Checks::AbcMetricMethodCheck do
|
|
40
40
|
describe 'when processing branches' do
|
41
41
|
|
42
42
|
it 'should find a virtual method call' do
|
43
|
-
|
43
|
+
code = <<-END
|
44
44
|
def method_name
|
45
45
|
call_foo
|
46
46
|
end
|
47
47
|
END
|
48
48
|
|
49
|
-
|
49
|
+
verify_code_score(code, 0, 1, 0)
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'should find an explicit method call' do
|
53
|
-
|
53
|
+
code = <<-END
|
54
54
|
def method_name
|
55
55
|
@object.call_foo
|
56
56
|
end
|
57
57
|
END
|
58
58
|
|
59
|
-
|
59
|
+
verify_code_score(code, 0, 1, 0)
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'should exclude a condition' do
|
63
|
-
|
63
|
+
code = <<-END
|
64
64
|
def method_name
|
65
65
|
@object.call_foo < 10
|
66
66
|
end
|
67
67
|
END
|
68
68
|
|
69
|
-
|
69
|
+
verify_code_score(code, 0, 1, 1)
|
70
70
|
end
|
71
71
|
|
72
72
|
end
|
@@ -76,13 +76,13 @@ describe Simplabs::Excellent::Checks::AbcMetricMethodCheck do
|
|
76
76
|
['==', '!=', '<=', '>=', '<', '>', '<=>', '=~'].each do |conditional|
|
77
77
|
|
78
78
|
it "should find #{conditional}" do
|
79
|
-
|
79
|
+
code = <<-END
|
80
80
|
def method_name
|
81
81
|
@foo #{conditional} @bar
|
82
82
|
end
|
83
83
|
END
|
84
84
|
|
85
|
-
|
85
|
+
verify_code_score(code, 0, 0, 1)
|
86
86
|
end
|
87
87
|
|
88
88
|
end
|
@@ -90,27 +90,27 @@ describe Simplabs::Excellent::Checks::AbcMetricMethodCheck do
|
|
90
90
|
end
|
91
91
|
|
92
92
|
it 'should also work on singleton methods' do
|
93
|
-
|
93
|
+
code = <<-END
|
94
94
|
class Class
|
95
95
|
def self.method_name
|
96
96
|
foo = 1
|
97
97
|
end
|
98
98
|
end
|
99
99
|
END
|
100
|
-
@excellent.
|
100
|
+
@excellent.check_code(code)
|
101
101
|
warnings = @excellent.warnings
|
102
102
|
|
103
103
|
warnings.should_not be_empty
|
104
104
|
warnings[0].info.should == { :method => 'Class.method_name', :score => 1.0 }
|
105
105
|
warnings[0].line_number.should == 2
|
106
|
-
warnings[0].message.should ==
|
106
|
+
warnings[0].message.should == 'Class.method_name has abc score of 1.0.'
|
107
107
|
end
|
108
108
|
|
109
109
|
end
|
110
110
|
|
111
|
-
def
|
111
|
+
def verify_code_score(code, a, b, c)
|
112
112
|
score = Math.sqrt(a*a + b*b + c*c)
|
113
|
-
@excellent.
|
113
|
+
@excellent.check_code(code)
|
114
114
|
warnings = @excellent.warnings
|
115
115
|
|
116
116
|
warnings.should_not be_empty
|
@@ -9,76 +9,76 @@ describe Simplabs::Excellent::Checks::AssignmentInConditionalCheck do
|
|
9
9
|
describe '#evaluate' do
|
10
10
|
|
11
11
|
it 'should accept an assignment before an if clause' do
|
12
|
-
|
12
|
+
code = <<-END
|
13
13
|
count = count += 1 if @some_condition
|
14
14
|
END
|
15
|
-
@excellent.
|
15
|
+
@excellent.check_code(code)
|
16
16
|
|
17
17
|
@excellent.warnings.should be_empty
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should accept block parameters in an if clause' do
|
21
|
-
|
21
|
+
code = <<-END
|
22
22
|
return true if exp.children.any? { |child| contains_statements?(child) }
|
23
23
|
END
|
24
|
-
@excellent.
|
24
|
+
@excellent.check_code(code)
|
25
25
|
|
26
26
|
@excellent.warnings.should be_empty
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'should reject assignments of results of blocks in an if clause' do
|
30
|
-
|
30
|
+
code = <<-END
|
31
31
|
return true if value = exp.children.find { |child| contains_statements?(child) }
|
32
32
|
END
|
33
33
|
|
34
|
-
verify_warning_found(
|
34
|
+
verify_warning_found(code)
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'should reject an assignment inside an if clause' do
|
38
|
-
|
38
|
+
code = <<-END
|
39
39
|
call_foo if bar = bam
|
40
40
|
END
|
41
41
|
|
42
|
-
verify_warning_found(
|
42
|
+
verify_warning_found(code)
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'should reject an assignment inside an unless clause' do
|
46
|
-
|
46
|
+
code = <<-END
|
47
47
|
call_foo unless bar = bam
|
48
48
|
END
|
49
49
|
|
50
|
-
verify_warning_found(
|
50
|
+
verify_warning_found(code)
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'should reject an assignment inside a while clause' do
|
54
|
-
|
54
|
+
code = <<-END
|
55
55
|
call_foo while bar = bam
|
56
56
|
END
|
57
57
|
|
58
|
-
verify_warning_found(
|
58
|
+
verify_warning_found(code)
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'should reject an assignment inside an until clause' do
|
62
|
-
|
62
|
+
code = <<-END
|
63
63
|
call_foo until bar = bam
|
64
64
|
END
|
65
65
|
|
66
|
-
verify_warning_found(
|
66
|
+
verify_warning_found(code)
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'should reject an assignment inside a ternary operator check clause' do
|
70
|
-
|
70
|
+
code = <<-END
|
71
71
|
call_foo (bar = bam) ? baz : bad
|
72
72
|
END
|
73
73
|
|
74
74
|
#RubyParser sets line number 2 here
|
75
|
-
verify_warning_found(
|
75
|
+
verify_warning_found(code, 2)
|
76
76
|
end
|
77
77
|
|
78
78
|
end
|
79
79
|
|
80
|
-
def verify_warning_found(
|
81
|
-
@excellent.
|
80
|
+
def verify_warning_found(code, line_number = nil)
|
81
|
+
@excellent.check_code(code)
|
82
82
|
warnings = @excellent.warnings
|
83
83
|
|
84
84
|
warnings.should_not be_empty
|
@@ -9,26 +9,26 @@ describe Simplabs::Excellent::Checks::CaseMissingElseCheck do
|
|
9
9
|
describe '#evaluate' do
|
10
10
|
|
11
11
|
it 'should accept case statements that do have an else clause' do
|
12
|
-
|
12
|
+
code = <<-END
|
13
13
|
case foo
|
14
14
|
when "bar": "ok"
|
15
15
|
else "good"
|
16
16
|
end
|
17
17
|
END
|
18
|
-
@excellent.
|
18
|
+
@excellent.check_code(code)
|
19
19
|
warnings = @excellent.warnings
|
20
20
|
|
21
21
|
warnings.should be_empty
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'should reject case statements that do not have an else clause' do
|
25
|
-
|
25
|
+
code = <<-END
|
26
26
|
case foo
|
27
27
|
when "bar": "ok"
|
28
28
|
when "bar": "bad"
|
29
29
|
end
|
30
30
|
END
|
31
|
-
@excellent.
|
31
|
+
@excellent.check_code(code)
|
32
32
|
warnings = @excellent.warnings
|
33
33
|
|
34
34
|
warnings.should_not be_empty
|
@@ -9,46 +9,46 @@ describe Simplabs::Excellent::Checks::ClassLineCountCheck do
|
|
9
9
|
describe '#evaluate' do
|
10
10
|
|
11
11
|
it 'should accept classes with less lines than the threshold' do
|
12
|
-
|
12
|
+
code = <<-END
|
13
13
|
class OneLineClass; end
|
14
14
|
END
|
15
|
-
@excellent.
|
15
|
+
@excellent.check_code(code)
|
16
16
|
|
17
17
|
@excellent.warnings.should be_empty
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should accept classes with the same number of lines as the threshold' do
|
21
|
-
|
21
|
+
code = <<-END
|
22
22
|
class ThreeLineClass
|
23
23
|
@foo = 1
|
24
24
|
end
|
25
25
|
END
|
26
|
-
@excellent.
|
26
|
+
@excellent.check_code(code)
|
27
27
|
|
28
28
|
@excellent.warnings.should be_empty
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'should not count blank lines' do
|
32
|
-
|
32
|
+
code = <<-END
|
33
33
|
class ThreeLineClass
|
34
34
|
|
35
35
|
@foo = 1
|
36
36
|
|
37
37
|
end
|
38
38
|
END
|
39
|
-
@excellent.
|
39
|
+
@excellent.check_code(code)
|
40
40
|
|
41
41
|
@excellent.warnings.should be_empty
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should reject classes with more lines than the threshold' do
|
45
|
-
|
45
|
+
code = <<-END
|
46
46
|
class FourLineClass
|
47
47
|
@foo = 1
|
48
48
|
@bar = 2
|
49
49
|
end
|
50
50
|
END
|
51
|
-
@excellent.
|
51
|
+
@excellent.check_code(code)
|
52
52
|
warnings = @excellent.warnings
|
53
53
|
|
54
54
|
warnings.should_not be_empty
|
@@ -9,32 +9,32 @@ describe Simplabs::Excellent::Checks::ClassNameCheck do
|
|
9
9
|
describe '#evaluate' do
|
10
10
|
|
11
11
|
it 'should accept camel case class names starting in capitals' do
|
12
|
-
|
12
|
+
code = <<-END
|
13
13
|
class GoodClassName; end
|
14
14
|
END
|
15
|
-
@excellent.
|
15
|
+
@excellent.check_code(code)
|
16
16
|
|
17
17
|
@excellent.warnings.should be_empty
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should be able to parse scoped class names' do
|
21
|
-
|
21
|
+
code = <<-END
|
22
22
|
class Outer::Inner::GoodClassName
|
23
23
|
def method
|
24
24
|
end
|
25
25
|
end
|
26
26
|
END
|
27
|
-
@excellent.
|
28
|
-
|
27
|
+
@excellent.check_code(code)
|
28
|
+
s
|
29
29
|
@excellent.warnings.should be_empty
|
30
30
|
end
|
31
31
|
|
32
32
|
it 'should reject class names with underscores' do
|
33
|
-
|
33
|
+
code = <<-END
|
34
34
|
class Bad_ClassName
|
35
35
|
end
|
36
36
|
END
|
37
|
-
@excellent.
|
37
|
+
@excellent.check_code(code)
|
38
38
|
warnings = @excellent.warnings
|
39
39
|
|
40
40
|
warnings.should_not be_empty
|
@@ -9,39 +9,39 @@ describe Simplabs::Excellent::Checks::ControlCouplingCheck do
|
|
9
9
|
describe '#evaluate' do
|
10
10
|
|
11
11
|
it 'should accept methods that just print out the parameter' do
|
12
|
-
|
12
|
+
code = <<-END
|
13
13
|
def write(quoted)
|
14
14
|
pp quoted
|
15
15
|
end
|
16
16
|
END
|
17
|
-
@excellent.
|
17
|
+
@excellent.check_code(code)
|
18
18
|
warnings = @excellent.warnings
|
19
19
|
|
20
20
|
warnings.should be_empty
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should accept methods with ternary operators using an instance variable' do
|
24
|
-
|
24
|
+
code = <<-END
|
25
25
|
def write(quoted)
|
26
26
|
@quoted ? write_quoted('1') : write_quoted('2')
|
27
27
|
end
|
28
28
|
END
|
29
29
|
|
30
|
-
@excellent.
|
30
|
+
@excellent.check_code(code)
|
31
31
|
warnings = @excellent.warnings
|
32
32
|
|
33
33
|
warnings.should be_empty
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'should accept methods with ternary operators using a local variable' do
|
37
|
-
|
37
|
+
code = <<-END
|
38
38
|
def write(quoted)
|
39
39
|
test = false
|
40
40
|
test ? write_quoted('1') : write_quoted('2')
|
41
41
|
end
|
42
42
|
END
|
43
43
|
|
44
|
-
@excellent.
|
44
|
+
@excellent.check_code(code)
|
45
45
|
warnings = @excellent.warnings
|
46
46
|
|
47
47
|
warnings.should be_empty
|
@@ -50,7 +50,7 @@ describe Simplabs::Excellent::Checks::ControlCouplingCheck do
|
|
50
50
|
%w(if unless).each do |conditional|
|
51
51
|
|
52
52
|
it "should reject methods with #{conditional} checks using a parameter" do
|
53
|
-
|
53
|
+
code = <<-END
|
54
54
|
def write(quoted)
|
55
55
|
#{conditional} quoted
|
56
56
|
write_quoted('test')
|
@@ -58,23 +58,23 @@ describe Simplabs::Excellent::Checks::ControlCouplingCheck do
|
|
58
58
|
end
|
59
59
|
END
|
60
60
|
|
61
|
-
verify_warning_found(
|
61
|
+
verify_warning_found(code)
|
62
62
|
end
|
63
63
|
|
64
64
|
end
|
65
65
|
|
66
66
|
it 'should reject methods with ternary operators using a parameter' do
|
67
|
-
|
67
|
+
code = <<-END
|
68
68
|
def write(quoted)
|
69
69
|
quoted ? write_quoted('1') : write_quoted('2')
|
70
70
|
end
|
71
71
|
END
|
72
72
|
|
73
|
-
verify_warning_found(
|
73
|
+
verify_warning_found(code)
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should reject methods with case statements using a parameter" do
|
77
|
-
|
77
|
+
code = <<-END
|
78
78
|
def write(quoted)
|
79
79
|
case quoted
|
80
80
|
when 1
|
@@ -85,13 +85,13 @@ describe Simplabs::Excellent::Checks::ControlCouplingCheck do
|
|
85
85
|
end
|
86
86
|
END
|
87
87
|
|
88
|
-
verify_warning_found(
|
88
|
+
verify_warning_found(code)
|
89
89
|
end
|
90
90
|
|
91
91
|
end
|
92
92
|
|
93
|
-
def verify_warning_found(
|
94
|
-
@excellent.
|
93
|
+
def verify_warning_found(code)
|
94
|
+
@excellent.check_code(code)
|
95
95
|
warnings = @excellent.warnings
|
96
96
|
|
97
97
|
warnings.should_not be_empty
|