excellent 1.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. data/History.txt +69 -0
  2. data/README.rdoc +72 -0
  3. data/VERSION.yml +4 -0
  4. data/bin/excellent +34 -0
  5. data/lib/simplabs/excellent.rb +16 -0
  6. data/lib/simplabs/excellent/checks.rb +33 -0
  7. data/lib/simplabs/excellent/checks/abc_metric_method_check.rb +43 -0
  8. data/lib/simplabs/excellent/checks/assignment_in_conditional_check.rb +39 -0
  9. data/lib/simplabs/excellent/checks/base.rb +62 -0
  10. data/lib/simplabs/excellent/checks/case_missing_else_check.rb +34 -0
  11. data/lib/simplabs/excellent/checks/class_line_count_check.rb +36 -0
  12. data/lib/simplabs/excellent/checks/class_name_check.rb +38 -0
  13. data/lib/simplabs/excellent/checks/control_coupling_check.rb +35 -0
  14. data/lib/simplabs/excellent/checks/cyclomatic_complexity_block_check.rb +48 -0
  15. data/lib/simplabs/excellent/checks/cyclomatic_complexity_check.rb +23 -0
  16. data/lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb +48 -0
  17. data/lib/simplabs/excellent/checks/empty_rescue_body_check.rb +31 -0
  18. data/lib/simplabs/excellent/checks/flog_block_check.rb +40 -0
  19. data/lib/simplabs/excellent/checks/flog_check.rb +27 -0
  20. data/lib/simplabs/excellent/checks/flog_class_check.rb +40 -0
  21. data/lib/simplabs/excellent/checks/flog_method_check.rb +40 -0
  22. data/lib/simplabs/excellent/checks/for_loop_check.rb +42 -0
  23. data/lib/simplabs/excellent/checks/global_variable_check.rb +33 -0
  24. data/lib/simplabs/excellent/checks/line_count_check.rb +27 -0
  25. data/lib/simplabs/excellent/checks/method_line_count_check.rb +36 -0
  26. data/lib/simplabs/excellent/checks/method_name_check.rb +38 -0
  27. data/lib/simplabs/excellent/checks/module_line_count_check.rb +36 -0
  28. data/lib/simplabs/excellent/checks/module_name_check.rb +38 -0
  29. data/lib/simplabs/excellent/checks/name_check.rb +27 -0
  30. data/lib/simplabs/excellent/checks/nested_iterators_check.rb +34 -0
  31. data/lib/simplabs/excellent/checks/parameter_number_check.rb +38 -0
  32. data/lib/simplabs/excellent/checks/rails.rb +22 -0
  33. data/lib/simplabs/excellent/checks/rails/attr_accessible_check.rb +38 -0
  34. data/lib/simplabs/excellent/checks/rails/attr_protected_check.rb +39 -0
  35. data/lib/simplabs/excellent/checks/rails/custom_initialize_method_check.rb +37 -0
  36. data/lib/simplabs/excellent/checks/rails/instance_var_in_partial_check.rb +37 -0
  37. data/lib/simplabs/excellent/checks/rails/params_hash_in_view_check.rb +38 -0
  38. data/lib/simplabs/excellent/checks/rails/session_hash_in_view_check.rb +38 -0
  39. data/lib/simplabs/excellent/checks/rails/validations_check.rb +36 -0
  40. data/lib/simplabs/excellent/checks/singleton_variable_check.rb +33 -0
  41. data/lib/simplabs/excellent/command_line_runner.rb +37 -0
  42. data/lib/simplabs/excellent/extensions/sexp.rb +21 -0
  43. data/lib/simplabs/excellent/extensions/string.rb +28 -0
  44. data/lib/simplabs/excellent/formatters.rb +13 -0
  45. data/lib/simplabs/excellent/formatters/base.rb +49 -0
  46. data/lib/simplabs/excellent/formatters/html.rb +153 -0
  47. data/lib/simplabs/excellent/formatters/text.rb +40 -0
  48. data/lib/simplabs/excellent/parsing.rb +10 -0
  49. data/lib/simplabs/excellent/parsing/abc_measure.rb +52 -0
  50. data/lib/simplabs/excellent/parsing/block_context.rb +43 -0
  51. data/lib/simplabs/excellent/parsing/call_context.rb +52 -0
  52. data/lib/simplabs/excellent/parsing/case_context.rb +31 -0
  53. data/lib/simplabs/excellent/parsing/class_context.rb +99 -0
  54. data/lib/simplabs/excellent/parsing/code_processor.rb +165 -0
  55. data/lib/simplabs/excellent/parsing/conditional_context.rb +25 -0
  56. data/lib/simplabs/excellent/parsing/cvar_context.rb +28 -0
  57. data/lib/simplabs/excellent/parsing/cyclomatic_complexity_measure.rb +73 -0
  58. data/lib/simplabs/excellent/parsing/flog_measure.rb +192 -0
  59. data/lib/simplabs/excellent/parsing/for_loop_context.rb +15 -0
  60. data/lib/simplabs/excellent/parsing/gvar_context.rb +21 -0
  61. data/lib/simplabs/excellent/parsing/if_context.rb +38 -0
  62. data/lib/simplabs/excellent/parsing/ivar_context.rb +32 -0
  63. data/lib/simplabs/excellent/parsing/method_context.rb +50 -0
  64. data/lib/simplabs/excellent/parsing/module_context.rb +29 -0
  65. data/lib/simplabs/excellent/parsing/parser.rb +35 -0
  66. data/lib/simplabs/excellent/parsing/resbody_context.rb +39 -0
  67. data/lib/simplabs/excellent/parsing/scopeable.rb +34 -0
  68. data/lib/simplabs/excellent/parsing/sexp_context.rb +125 -0
  69. data/lib/simplabs/excellent/parsing/singleton_method_context.rb +55 -0
  70. data/lib/simplabs/excellent/parsing/until_context.rb +24 -0
  71. data/lib/simplabs/excellent/parsing/while_context.rb +24 -0
  72. data/lib/simplabs/excellent/rake.rb +1 -0
  73. data/lib/simplabs/excellent/rake/excellent_task.rb +61 -0
  74. data/lib/simplabs/excellent/runner.rb +143 -0
  75. data/lib/simplabs/excellent/warning.rb +53 -0
  76. data/spec/checks/abc_metric_method_check_spec.rb +122 -0
  77. data/spec/checks/assignment_in_conditional_check_spec.rb +90 -0
  78. data/spec/checks/case_missing_else_check_spec.rb +42 -0
  79. data/spec/checks/class_line_count_check_spec.rb +62 -0
  80. data/spec/checks/class_name_check_spec.rb +48 -0
  81. data/spec/checks/control_coupling_check_spec.rb +103 -0
  82. data/spec/checks/cyclomatic_complexity_block_check_spec.rb +47 -0
  83. data/spec/checks/cyclomatic_complexity_method_check_spec.rb +210 -0
  84. data/spec/checks/empty_rescue_body_check_spec.rb +170 -0
  85. data/spec/checks/flog_block_check_spec.rb +28 -0
  86. data/spec/checks/flog_class_check_spec.rb +28 -0
  87. data/spec/checks/flog_method_check_spec.rb +46 -0
  88. data/spec/checks/for_loop_check_spec.rb +52 -0
  89. data/spec/checks/global_variable_check_spec.rb +66 -0
  90. data/spec/checks/method_line_count_check_spec.rb +49 -0
  91. data/spec/checks/method_name_check_spec.rb +112 -0
  92. data/spec/checks/module_line_count_check_spec.rb +48 -0
  93. data/spec/checks/module_name_check_spec.rb +61 -0
  94. data/spec/checks/nested_iterators_check_spec.rb +44 -0
  95. data/spec/checks/parameter_number_check_spec.rb +97 -0
  96. data/spec/checks/rails/attr_accessible_check_spec.rb +79 -0
  97. data/spec/checks/rails/attr_protected_check_spec.rb +77 -0
  98. data/spec/checks/rails/custom_initialize_method_check_spec.rb +58 -0
  99. data/spec/checks/rails/instance_var_in_partial_check_spec.rb +40 -0
  100. data/spec/checks/rails/params_hash_in_view_check_spec.rb +40 -0
  101. data/spec/checks/rails/session_hash_in_view_check_spec.rb +40 -0
  102. data/spec/checks/rails/validations_check_spec.rb +81 -0
  103. data/spec/checks/singleton_variable_check_spec.rb +66 -0
  104. data/spec/extensions/string_spec.rb +13 -0
  105. data/spec/spec_helper.rb +13 -0
  106. metadata +189 -0
@@ -0,0 +1,81 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe Simplabs::Excellent::Checks::Rails::ValidationsCheck do
4
+
5
+ before do
6
+ @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::Rails::ValidationsCheck.new)
7
+ end
8
+
9
+ describe '#evaluate' do
10
+
11
+ it 'should ignore classes that are not active record models' do
12
+ code = <<-END
13
+ class Test
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 an active record model that does not validate anything' do
23
+ code = <<-END
24
+ class User < ActiveRecord::Base
25
+ end
26
+ END
27
+ @excellent.check_code(code)
28
+ warnings = @excellent.warnings
29
+
30
+ warnings.should_not be_empty
31
+ warnings[0].info.should == { :class => 'User' }
32
+ warnings[0].line_number.should == 1
33
+ warnings[0].message.should == 'User does not validate any attributes.'
34
+ end
35
+
36
+ it 'should accept an active record model that validates attributes using a macro method' do
37
+ code = <<-END
38
+ class User < ActiveRecord::Base
39
+ validates_presence_of :login
40
+ end
41
+ END
42
+ @excellent.check_code(code)
43
+ warnings = @excellent.warnings
44
+
45
+ warnings.should be_empty
46
+ end
47
+
48
+ %(validate validate_on_create validate_on_update).each do |method|
49
+
50
+ it "should accept an active record model that validates attribute by overriding #{method}" do
51
+ code = <<-END
52
+ class User < ActiveRecord::Base
53
+ def #{method}
54
+ end
55
+ end
56
+ END
57
+ @excellent.check_code(code)
58
+ warnings = @excellent.warnings
59
+
60
+ warnings.should be_empty
61
+ end
62
+
63
+ end
64
+
65
+ it 'should also work with namespaced models' do
66
+ code = <<-END
67
+ class Backend::User < ActiveRecord::Base
68
+ end
69
+ END
70
+ @excellent.check_code(code)
71
+ warnings = @excellent.warnings
72
+
73
+ warnings.should_not be_empty
74
+ warnings[0].info.should == { :class => 'Backend::User' }
75
+ warnings[0].line_number.should == 1
76
+ warnings[0].message.should == 'Backend::User does not validate any attributes.'
77
+ end
78
+
79
+ end
80
+
81
+ end
@@ -0,0 +1,66 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe Simplabs::Excellent::Checks::SingletonVariableCheck do
4
+
5
+ before(:each) do
6
+ @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::SingletonVariableCheck.new)
7
+ end
8
+
9
+ describe '#evaluate' do
10
+
11
+ it 'should reject singleton variables' do
12
+ code = <<-END
13
+ @@foo
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 == 2
21
+ warnings[0].message.should == 'Singleton variable foo used.'
22
+ end
23
+
24
+ it 'should also work for namespaced classes' do
25
+ code = <<-END
26
+ module Outer
27
+ module Inner
28
+ class Class
29
+ @@foo
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 => 'Outer::Inner::Class.foo' }
39
+ warnings[0].line_number.should == 5
40
+ warnings[0].message.should == 'Singleton variable Outer::Inner::Class.foo used.'
41
+ end
42
+
43
+ it 'should also work for singleton variables that occur within methods' do
44
+ code = <<-END
45
+ module Outer
46
+ module Inner
47
+ class Class
48
+ def method
49
+ @@foo
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 => 'Outer::Inner::Class.foo' }
60
+ warnings[0].line_number.should == 6
61
+ warnings[0].message.should == 'Singleton variable Outer::Inner::Class.foo used.'
62
+ end
63
+
64
+ end
65
+
66
+ end
@@ -0,0 +1,13 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe String do
4
+
5
+ describe '#underscore' do
6
+
7
+ it 'should correctly add underscores to "AbcMetricMethodCheck"' do
8
+ 'AbcMetricMethodCheck'.underscore.should == 'abc_metric_method_check'
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
2
+
3
+ require 'rubygems'
4
+ require 'spec'
5
+ require 'simplabs/excellent'
6
+
7
+ begin
8
+ require 'ruby-debug'
9
+ Debugger.start
10
+ Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings)
11
+ rescue LoadError
12
+ # ruby-debug wasn't available so neither can the debugging be
13
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: excellent
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.5.4
5
+ platform: ruby
6
+ authors:
7
+ - Marco Otte-Witte
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-05 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ruby_parser
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "2.0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: sexp_processor
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "3.0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: facets
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "2.7"
44
+ version:
45
+ description:
46
+ email: marco.otte-witte@simplabs.com
47
+ executables:
48
+ - excellent
49
+ extensions: []
50
+
51
+ extra_rdoc_files: []
52
+
53
+ files:
54
+ - History.txt
55
+ - README.rdoc
56
+ - VERSION.yml
57
+ - bin/excellent
58
+ - lib/simplabs/excellent/checks/abc_metric_method_check.rb
59
+ - lib/simplabs/excellent/checks/assignment_in_conditional_check.rb
60
+ - lib/simplabs/excellent/checks/base.rb
61
+ - lib/simplabs/excellent/checks/case_missing_else_check.rb
62
+ - lib/simplabs/excellent/checks/class_line_count_check.rb
63
+ - lib/simplabs/excellent/checks/class_name_check.rb
64
+ - lib/simplabs/excellent/checks/control_coupling_check.rb
65
+ - lib/simplabs/excellent/checks/cyclomatic_complexity_block_check.rb
66
+ - lib/simplabs/excellent/checks/cyclomatic_complexity_check.rb
67
+ - lib/simplabs/excellent/checks/cyclomatic_complexity_method_check.rb
68
+ - lib/simplabs/excellent/checks/empty_rescue_body_check.rb
69
+ - lib/simplabs/excellent/checks/flog_block_check.rb
70
+ - lib/simplabs/excellent/checks/flog_check.rb
71
+ - lib/simplabs/excellent/checks/flog_class_check.rb
72
+ - lib/simplabs/excellent/checks/flog_method_check.rb
73
+ - lib/simplabs/excellent/checks/for_loop_check.rb
74
+ - lib/simplabs/excellent/checks/global_variable_check.rb
75
+ - lib/simplabs/excellent/checks/line_count_check.rb
76
+ - lib/simplabs/excellent/checks/method_line_count_check.rb
77
+ - lib/simplabs/excellent/checks/method_name_check.rb
78
+ - lib/simplabs/excellent/checks/module_line_count_check.rb
79
+ - lib/simplabs/excellent/checks/module_name_check.rb
80
+ - lib/simplabs/excellent/checks/name_check.rb
81
+ - lib/simplabs/excellent/checks/nested_iterators_check.rb
82
+ - lib/simplabs/excellent/checks/parameter_number_check.rb
83
+ - lib/simplabs/excellent/checks/rails/attr_accessible_check.rb
84
+ - lib/simplabs/excellent/checks/rails/attr_protected_check.rb
85
+ - lib/simplabs/excellent/checks/rails/custom_initialize_method_check.rb
86
+ - lib/simplabs/excellent/checks/rails/instance_var_in_partial_check.rb
87
+ - lib/simplabs/excellent/checks/rails/params_hash_in_view_check.rb
88
+ - lib/simplabs/excellent/checks/rails/session_hash_in_view_check.rb
89
+ - lib/simplabs/excellent/checks/rails/validations_check.rb
90
+ - lib/simplabs/excellent/checks/rails.rb
91
+ - lib/simplabs/excellent/checks/singleton_variable_check.rb
92
+ - lib/simplabs/excellent/checks.rb
93
+ - lib/simplabs/excellent/command_line_runner.rb
94
+ - lib/simplabs/excellent/extensions/sexp.rb
95
+ - lib/simplabs/excellent/extensions/string.rb
96
+ - lib/simplabs/excellent/formatters/base.rb
97
+ - lib/simplabs/excellent/formatters/html.rb
98
+ - lib/simplabs/excellent/formatters/text.rb
99
+ - lib/simplabs/excellent/formatters.rb
100
+ - lib/simplabs/excellent/parsing/abc_measure.rb
101
+ - lib/simplabs/excellent/parsing/block_context.rb
102
+ - lib/simplabs/excellent/parsing/call_context.rb
103
+ - lib/simplabs/excellent/parsing/case_context.rb
104
+ - lib/simplabs/excellent/parsing/class_context.rb
105
+ - lib/simplabs/excellent/parsing/code_processor.rb
106
+ - lib/simplabs/excellent/parsing/conditional_context.rb
107
+ - lib/simplabs/excellent/parsing/cvar_context.rb
108
+ - lib/simplabs/excellent/parsing/cyclomatic_complexity_measure.rb
109
+ - lib/simplabs/excellent/parsing/flog_measure.rb
110
+ - lib/simplabs/excellent/parsing/for_loop_context.rb
111
+ - lib/simplabs/excellent/parsing/gvar_context.rb
112
+ - lib/simplabs/excellent/parsing/if_context.rb
113
+ - lib/simplabs/excellent/parsing/ivar_context.rb
114
+ - lib/simplabs/excellent/parsing/method_context.rb
115
+ - lib/simplabs/excellent/parsing/module_context.rb
116
+ - lib/simplabs/excellent/parsing/parser.rb
117
+ - lib/simplabs/excellent/parsing/resbody_context.rb
118
+ - lib/simplabs/excellent/parsing/scopeable.rb
119
+ - lib/simplabs/excellent/parsing/sexp_context.rb
120
+ - lib/simplabs/excellent/parsing/singleton_method_context.rb
121
+ - lib/simplabs/excellent/parsing/until_context.rb
122
+ - lib/simplabs/excellent/parsing/while_context.rb
123
+ - lib/simplabs/excellent/parsing.rb
124
+ - lib/simplabs/excellent/rake/excellent_task.rb
125
+ - lib/simplabs/excellent/rake.rb
126
+ - lib/simplabs/excellent/runner.rb
127
+ - lib/simplabs/excellent/warning.rb
128
+ - lib/simplabs/excellent.rb
129
+ - spec/checks/abc_metric_method_check_spec.rb
130
+ - spec/checks/assignment_in_conditional_check_spec.rb
131
+ - spec/checks/case_missing_else_check_spec.rb
132
+ - spec/checks/class_line_count_check_spec.rb
133
+ - spec/checks/class_name_check_spec.rb
134
+ - spec/checks/control_coupling_check_spec.rb
135
+ - spec/checks/cyclomatic_complexity_block_check_spec.rb
136
+ - spec/checks/cyclomatic_complexity_method_check_spec.rb
137
+ - spec/checks/empty_rescue_body_check_spec.rb
138
+ - spec/checks/flog_block_check_spec.rb
139
+ - spec/checks/flog_class_check_spec.rb
140
+ - spec/checks/flog_method_check_spec.rb
141
+ - spec/checks/for_loop_check_spec.rb
142
+ - spec/checks/global_variable_check_spec.rb
143
+ - spec/checks/method_line_count_check_spec.rb
144
+ - spec/checks/method_name_check_spec.rb
145
+ - spec/checks/module_line_count_check_spec.rb
146
+ - spec/checks/module_name_check_spec.rb
147
+ - spec/checks/nested_iterators_check_spec.rb
148
+ - spec/checks/parameter_number_check_spec.rb
149
+ - spec/checks/rails/attr_accessible_check_spec.rb
150
+ - spec/checks/rails/attr_protected_check_spec.rb
151
+ - spec/checks/rails/custom_initialize_method_check_spec.rb
152
+ - spec/checks/rails/instance_var_in_partial_check_spec.rb
153
+ - spec/checks/rails/params_hash_in_view_check_spec.rb
154
+ - spec/checks/rails/session_hash_in_view_check_spec.rb
155
+ - spec/checks/rails/validations_check_spec.rb
156
+ - spec/checks/singleton_variable_check_spec.rb
157
+ - spec/extensions/string_spec.rb
158
+ - spec/spec_helper.rb
159
+ has_rdoc: true
160
+ homepage: http://github.com/simplabs/excellent
161
+ licenses: []
162
+
163
+ post_install_message:
164
+ rdoc_options:
165
+ - --inline-source
166
+ - --charset=UTF-8
167
+ require_paths:
168
+ - lib
169
+ required_ruby_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: "0"
174
+ version:
175
+ required_rubygems_version: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - ">="
178
+ - !ruby/object:Gem::Version
179
+ version: "0"
180
+ version:
181
+ requirements: []
182
+
183
+ rubyforge_project:
184
+ rubygems_version: 1.3.5
185
+ signing_key:
186
+ specification_version: 2
187
+ summary: Source Code analysis gem for Ruby and Rails
188
+ test_files: []
189
+