excellent 1.7.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. data/History.txt +9 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +123 -0
  4. data/bin/excellent +49 -12
  5. data/lib/simplabs/excellent.rb +2 -2
  6. data/lib/simplabs/excellent/checks.rb +1 -1
  7. data/lib/simplabs/excellent/checks/abc_metric_method_check.rb +1 -1
  8. data/lib/simplabs/excellent/checks/assignment_in_conditional_check.rb +1 -1
  9. data/lib/simplabs/excellent/checks/base.rb +12 -9
  10. data/lib/simplabs/excellent/checks/case_missing_else_check.rb +1 -1
  11. data/lib/simplabs/excellent/checks/class_line_count_check.rb +3 -3
  12. data/lib/simplabs/excellent/checks/class_name_check.rb +5 -5
  13. data/lib/simplabs/excellent/checks/{singleton_variable_check.rb → class_variable_check.rb} +3 -3
  14. data/lib/simplabs/excellent/checks/control_coupling_check.rb +1 -1
  15. data/lib/simplabs/excellent/checks/cyclomatic_complexity_block_check.rb +4 -4
  16. data/lib/simplabs/excellent/checks/cyclomatic_complexity_check.rb +3 -3
  17. data/lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb +2 -2
  18. data/lib/simplabs/excellent/checks/empty_rescue_body_check.rb +1 -1
  19. data/lib/simplabs/excellent/checks/flog_block_check.rb +2 -2
  20. data/lib/simplabs/excellent/checks/flog_check.rb +3 -3
  21. data/lib/simplabs/excellent/checks/flog_class_check.rb +2 -2
  22. data/lib/simplabs/excellent/checks/flog_method_check.rb +2 -2
  23. data/lib/simplabs/excellent/checks/for_loop_check.rb +1 -1
  24. data/lib/simplabs/excellent/checks/global_variable_check.rb +5 -2
  25. data/lib/simplabs/excellent/checks/line_count_check.rb +3 -3
  26. data/lib/simplabs/excellent/checks/method_line_count_check.rb +2 -2
  27. data/lib/simplabs/excellent/checks/method_name_check.rb +5 -4
  28. data/lib/simplabs/excellent/checks/module_line_count_check.rb +2 -2
  29. data/lib/simplabs/excellent/checks/module_name_check.rb +3 -3
  30. data/lib/simplabs/excellent/checks/name_check.rb +4 -4
  31. data/lib/simplabs/excellent/checks/nested_iterators_check.rb +2 -2
  32. data/lib/simplabs/excellent/checks/parameter_number_check.rb +1 -1
  33. data/lib/simplabs/excellent/checks/rails/attr_accessible_check.rb +1 -1
  34. data/lib/simplabs/excellent/checks/rails/attr_protected_check.rb +1 -1
  35. data/lib/simplabs/excellent/checks/rails/custom_initialize_method_check.rb +1 -1
  36. data/lib/simplabs/excellent/checks/rails/instance_var_in_partial_check.rb +1 -1
  37. data/lib/simplabs/excellent/checks/rails/params_hash_in_view_check.rb +1 -1
  38. data/lib/simplabs/excellent/checks/rails/session_hash_in_view_check.rb +1 -1
  39. data/lib/simplabs/excellent/checks/rails/validations_check.rb +1 -1
  40. data/lib/simplabs/excellent/formatters/text.rb +7 -1
  41. data/lib/simplabs/excellent/parsing/gvar_context.rb +0 -8
  42. data/lib/simplabs/excellent/parsing/loc_parser.rb +94 -0
  43. data/lib/simplabs/excellent/parsing/resbody_context.rb +0 -6
  44. data/lib/simplabs/excellent/runner.rb +49 -32
  45. data/lib/simplabs/excellent/warning.rb +1 -4
  46. metadata +23 -49
  47. data/README.rdoc +0 -72
  48. data/VERSION.yml +0 -4
  49. data/lib/simplabs/excellent/extensions/string.rb +0 -28
  50. data/spec/checks/abc_metric_method_check_spec.rb +0 -122
  51. data/spec/checks/assignment_in_conditional_check_spec.rb +0 -90
  52. data/spec/checks/case_missing_else_check_spec.rb +0 -46
  53. data/spec/checks/class_line_count_check_spec.rb +0 -62
  54. data/spec/checks/class_name_check_spec.rb +0 -48
  55. data/spec/checks/control_coupling_check_spec.rb +0 -103
  56. data/spec/checks/cyclomatic_complexity_block_check_spec.rb +0 -47
  57. data/spec/checks/cyclomatic_complexity_method_check_spec.rb +0 -210
  58. data/spec/checks/empty_rescue_body_check_spec.rb +0 -170
  59. data/spec/checks/flog_block_check_spec.rb +0 -28
  60. data/spec/checks/flog_class_check_spec.rb +0 -28
  61. data/spec/checks/flog_method_check_spec.rb +0 -46
  62. data/spec/checks/for_loop_check_spec.rb +0 -52
  63. data/spec/checks/global_variable_check_spec.rb +0 -66
  64. data/spec/checks/method_line_count_check_spec.rb +0 -49
  65. data/spec/checks/method_name_check_spec.rb +0 -112
  66. data/spec/checks/module_line_count_check_spec.rb +0 -48
  67. data/spec/checks/module_name_check_spec.rb +0 -61
  68. data/spec/checks/nested_iterators_check_spec.rb +0 -44
  69. data/spec/checks/parameter_number_check_spec.rb +0 -97
  70. data/spec/checks/rails/attr_accessible_check_spec.rb +0 -79
  71. data/spec/checks/rails/attr_protected_check_spec.rb +0 -77
  72. data/spec/checks/rails/custom_initialize_method_check_spec.rb +0 -58
  73. data/spec/checks/rails/instance_var_in_partial_check_spec.rb +0 -40
  74. data/spec/checks/rails/params_hash_in_view_check_spec.rb +0 -40
  75. data/spec/checks/rails/session_hash_in_view_check_spec.rb +0 -40
  76. data/spec/checks/rails/validations_check_spec.rb +0 -81
  77. data/spec/checks/singleton_variable_check_spec.rb +0 -66
  78. data/spec/extensions/string_spec.rb +0 -13
  79. data/spec/spec_helper.rb +0 -13
@@ -1,170 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Simplabs::Excellent::Checks::EmptyRescueBodyCheck do
4
-
5
- before do
6
- @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::EmptyRescueBodyCheck.new)
7
- end
8
-
9
- describe '#evaluate' do
10
-
11
- it 'should accept a rescue body with content and no parameter' do
12
- code = <<-END
13
- begin
14
- call_method
15
- rescue
16
- puts "Recover from the call"
17
- end
18
- END
19
- @excellent.check_code(code)
20
-
21
- @excellent.warnings.should be_empty
22
- end
23
-
24
- it 'should accept a rescue body with a return' do
25
- code = <<-END
26
- begin
27
- call_method
28
- rescue
29
- return true
30
- end
31
- END
32
- @excellent.check_code(code)
33
-
34
- @excellent.warnings.should be_empty
35
- end
36
-
37
- it "should accept a virtual method call" do
38
- code = <<-END
39
- begin
40
- call_method
41
- rescue
42
- show_error
43
- end
44
- END
45
- @excellent.check_code(code)
46
-
47
- @excellent.warnings.should be_empty
48
- end
49
-
50
- it 'should accept a rescue body with code and a parameter' do
51
- code = <<-END
52
- begin
53
- call_method
54
- rescue Exception => e
55
- puts "Recover from the call"
56
- end
57
- END
58
- @excellent.check_code(code)
59
-
60
- @excellent.warnings.should be_empty
61
- end
62
-
63
- it 'should accept a rescue body with an assignment' do
64
- code = <<-END
65
- begin
66
- call_method
67
- rescue Exception => e
68
- my_var = 1
69
- end
70
- END
71
- @excellent.check_code(code)
72
-
73
- @excellent.warnings.should be_empty
74
- end
75
-
76
- it 'should accept a rescue body with an attribute assignment' do
77
- code = <<-END
78
- begin
79
- call_method
80
- rescue Exception => e
81
- self.var = 1
82
- end
83
- END
84
- @excellent.check_code(code)
85
-
86
- @excellent.warnings.should be_empty
87
- end
88
-
89
- it 'should accept an inline rescue statement' do
90
- code = <<-END
91
- value = call_method rescue 1
92
- END
93
- @excellent.check_code(code)
94
-
95
- @excellent.warnings.should be_empty
96
- end
97
-
98
- it 'should accept an empty array as a statement' do
99
- code = <<-END
100
- value = call_method rescue []
101
- END
102
-
103
- @excellent.check_code(code)
104
-
105
- @excellent.warnings.should be_empty
106
- end
107
-
108
- it 'should accept an empty hash as a statement' do
109
- code = <<-END
110
- value = call_method rescue {}
111
- END
112
-
113
- @excellent.check_code(code)
114
-
115
- @excellent.warnings.should be_empty
116
- end
117
-
118
- it 'should accept a boolean as a statement' do
119
- code = <<-END
120
- value = call_method rescue false
121
- END
122
- @excellent.check_code(code)
123
-
124
- @excellent.warnings.should be_empty
125
- end
126
-
127
- it 'should accept nil as a statement' do
128
- code = <<-END
129
- value = call_method rescue nil
130
- END
131
- @excellent.check_code(code)
132
-
133
- @excellent.warnings.should be_empty
134
- end
135
-
136
- it 'should reject an empty rescue block with no parameter' do
137
- code = <<-END
138
- begin
139
- call_method
140
- rescue
141
- end
142
- END
143
-
144
- verify_warning_found(code)
145
- end
146
-
147
- it 'should reject an empty rescue block with a parameter' do
148
- code = <<-END
149
- begin
150
- call_method
151
- rescue Exception => e
152
- end
153
- END
154
-
155
- verify_warning_found(code)
156
- end
157
-
158
- end
159
-
160
- def verify_warning_found(code)
161
- @excellent.check_code(code)
162
- warnings = @excellent.warnings
163
-
164
- warnings.should_not be_empty
165
- warnings[0].info.should == {}
166
- warnings[0].line_number.should == 3
167
- warnings[0].message.should == 'Rescue block is empty.'
168
- end
169
-
170
- end
@@ -1,28 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Simplabs::Excellent::Checks::FlogBlockCheck do
4
-
5
- before do
6
- @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::FlogBlockCheck.new({ :threshold => 0 }))
7
- end
8
-
9
- describe '#evaluate' do
10
-
11
- it 'should calculate the score correctly' do
12
- code = <<-END
13
- method_name do
14
- puts 'test'
15
- end
16
- END
17
- @excellent.check_code(code)
18
- warnings = @excellent.warnings
19
-
20
- warnings.should_not be_empty
21
- warnings[0].info.should == { :block => 'block', :score => 3 }
22
- warnings[0].line_number.should == 1
23
- warnings[0].message.should == "block has flog score of 3."
24
- end
25
-
26
- end
27
-
28
- end
@@ -1,28 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Simplabs::Excellent::Checks::FlogClassCheck do
4
-
5
- before do
6
- @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::FlogClassCheck.new({ :threshold => 0 }))
7
- end
8
-
9
- describe '#evaluate' do
10
-
11
- it 'should calculate the score correctly' do
12
- code = <<-END
13
- class User < ActiveRecord::Base
14
- has_many :projects
15
- end
16
- END
17
- @excellent.check_code(code)
18
- warnings = @excellent.warnings
19
-
20
- warnings.should_not be_empty
21
- warnings[0].info.should == { :class => 'User', :score => 1 }
22
- warnings[0].line_number.should == 1
23
- warnings[0].message.should == "User has flog score of 1."
24
- end
25
-
26
- end
27
-
28
- end
@@ -1,46 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Simplabs::Excellent::Checks::FlogMethodCheck do
4
-
5
- before do
6
- @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::FlogMethodCheck.new({ :threshold => 0 }))
7
- end
8
-
9
- describe '#evaluate' do
10
-
11
- it 'should calculate the score correctly' do
12
- code = <<-END
13
- def method_name
14
- puts 'test'
15
- end
16
- END
17
-
18
- verify_code_score(code, 1)
19
- end
20
-
21
- it 'should calculate the score that uses special metaprogramming methods correctly' do
22
- code = <<-END
23
- def method_name
24
- @instance.instance_eval do
25
- def some_method
26
- end
27
- end
28
- end
29
- END
30
-
31
- verify_code_score(code, 6)
32
- end
33
-
34
- end
35
-
36
- def verify_code_score(code, score)
37
- @excellent.check_code(code)
38
- warnings = @excellent.warnings
39
-
40
- warnings.should_not be_empty
41
- warnings[0].info.should == { :method => 'method_name', :score => score }
42
- warnings[0].line_number.should == 1
43
- warnings[0].message.should == "method_name has flog score of #{score}."
44
- end
45
-
46
- end
@@ -1,52 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Simplabs::Excellent::Checks::ForLoopCheck do
4
-
5
- before do
6
- @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::ForLoopCheck.new)
7
- end
8
-
9
- describe '#evaluate' do
10
-
11
- it 'should accept iterators' do
12
- code = <<-END
13
- [:sym1, :sym2].each do |sym|
14
- end
15
- END
16
- @excellent.check_code(code)
17
- warnings = @excellent.warnings
18
-
19
- warnings.should be_empty
20
- end
21
-
22
- it 'should reject for loops on ranges' do
23
- code = <<-END
24
- for i in 1..2
25
- end
26
- END
27
-
28
- verify_warning_found(code)
29
- end
30
-
31
- it 'should reject for loops on enumerations' do
32
- code = <<-END
33
- for symbol in [:sym1, :sym2]
34
- end
35
- END
36
-
37
- verify_warning_found(code)
38
- end
39
-
40
- end
41
-
42
- def verify_warning_found(code)
43
- @excellent.check_code(code)
44
- warnings = @excellent.warnings
45
-
46
- warnings.should_not be_empty
47
- warnings[0].info.should == {}
48
- warnings[0].line_number.should == 1
49
- warnings[0].message.should == 'For loop used.'
50
- end
51
-
52
- end
@@ -1,66 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Simplabs::Excellent::Checks::GlobalVariableCheck do
4
-
5
- before(:each) do
6
- @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::GlobalVariableCheck.new)
7
- end
8
-
9
- describe '#evaluate' do
10
-
11
- it 'should reject global variables' do
12
- code = <<-END
13
- $foo = 'bar'
14
- END
15
- @excellent.check_code(code)
16
- warnings = @excellent.warnings
17
-
18
- warnings.should_not be_empty
19
- warnings[0].info.should == { :variable => 'foo' }
20
- warnings[0].line_number.should == 1
21
- warnings[0].message.should == 'Global variable foo used.'
22
- end
23
-
24
- it 'should also work in modules' do
25
- code = <<-END
26
- module Outer
27
- module Inner
28
- class Class
29
- $foo = 'bar'
30
- end
31
- end
32
- end
33
- END
34
- @excellent.check_code(code)
35
- warnings = @excellent.warnings
36
-
37
- warnings.should_not be_empty
38
- warnings[0].info.should == { :variable => 'foo' }
39
- warnings[0].line_number.should == 4
40
- warnings[0].message.should == 'Global variable foo used.'
41
- end
42
-
43
- it 'should also work for global variables that occur within methods' do
44
- code = <<-END
45
- module Outer
46
- module Inner
47
- class Class
48
- def method
49
- $foo == 'bar'
50
- end
51
- end
52
- end
53
- end
54
- END
55
- @excellent.check_code(code)
56
- warnings = @excellent.warnings
57
-
58
- warnings.should_not be_empty
59
- warnings[0].info.should == { :variable => 'foo' }
60
- warnings[0].line_number.should == 5
61
- warnings[0].message.should == 'Global variable foo used.'
62
- end
63
-
64
- end
65
-
66
- end
@@ -1,49 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Simplabs::Excellent::Checks::MethodLineCountCheck do
4
-
5
- before do
6
- @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::MethodLineCountCheck.new({ :threshold => 2 }))
7
- end
8
-
9
- describe '#evaluate' do
10
-
11
- it 'should accept methods with less lines than the threshold' do
12
- code = <<-END
13
- def one_line_method
14
- end
15
- END
16
- @excellent.check_code(code)
17
-
18
- @excellent.warnings.should be_empty
19
- end
20
-
21
- it 'should accept methods with the same number of lines as the threshold' do
22
- code = <<-END
23
- def two_line_method
24
- end
25
- END
26
- @excellent.check_code(code)
27
-
28
- @excellent.warnings.should be_empty
29
- end
30
-
31
- it 'should reject methods with more lines than the threshold' do
32
- code = <<-END
33
- def four_line_method
34
- puts 1
35
- puts 2
36
- end
37
- END
38
- @excellent.check_code(code)
39
- warnings = @excellent.warnings
40
-
41
- warnings.should_not be_empty
42
- warnings[0].info.should == { :method => 'four_line_method', :count => 4 }
43
- warnings[0].line_number.should == 1
44
- warnings[0].message.should == 'four_line_method has 4 lines.'
45
- end
46
-
47
- end
48
-
49
- end