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,5 +1,3 @@
1
- require 'simplabs/excellent/extensions/string'
2
-
3
1
  module Simplabs
4
2
 
5
3
  module Excellent
@@ -32,8 +30,7 @@ module Simplabs
32
30
  # The template used to produce the warning (see above)
33
31
  attr_reader :message_template
34
32
 
35
- def initialize(check, message, filename, line_number, info) #:nodoc:
36
- @check = check.to_s.underscore.to_sym
33
+ def initialize(message, filename, line_number, info) #:nodoc:
37
34
  @info = info
38
35
  @filename = filename
39
36
  @line_number = line_number.to_i
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: excellent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.2
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2009-08-05 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby_parser
16
- requirement: !ruby/object:Gem::Requirement
16
+ requirement: &70322483230640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,15 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '3.0'
24
+ version_requirements: *70322483230640
30
25
  - !ruby/object:Gem::Dependency
31
26
  name: sexp_processor
32
- requirement: !ruby/object:Gem::Requirement
27
+ requirement: &70322483229880 !ruby/object:Gem::Requirement
33
28
  none: false
34
29
  requirements:
35
30
  - - ! '>='
@@ -37,22 +32,30 @@ dependencies:
37
32
  version: '4.0'
38
33
  type: :runtime
39
34
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
35
+ version_requirements: *70322483229880
36
+ - !ruby/object:Gem::Dependency
37
+ name: hashr
38
+ requirement: &70322483228960 !ruby/object:Gem::Requirement
41
39
  none: false
42
40
  requirements:
43
41
  - - ! '>='
44
42
  - !ruby/object:Gem::Version
45
- version: '4.0'
46
- description:
43
+ version: 0.0.10
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70322483228960
47
+ description: Excellent finds the nasty lines in your code. It implements a comprehensive
48
+ set of checks for possibly buggy parts of your app that would otherwise make it
49
+ into your repo and eventually to the production server.
47
50
  email: marco.otte-witte@simplabs.com
48
51
  executables:
49
52
  - excellent
50
53
  extensions: []
51
54
  extra_rdoc_files: []
52
55
  files:
56
+ - MIT-LICENSE
57
+ - README.md
53
58
  - History.txt
54
- - README.rdoc
55
- - VERSION.yml
56
59
  - bin/excellent
57
60
  - lib/simplabs/excellent/checks/abc_metric_method_check.rb
58
61
  - lib/simplabs/excellent/checks/assignment_in_conditional_check.rb
@@ -60,6 +63,7 @@ files:
60
63
  - lib/simplabs/excellent/checks/case_missing_else_check.rb
61
64
  - lib/simplabs/excellent/checks/class_line_count_check.rb
62
65
  - lib/simplabs/excellent/checks/class_name_check.rb
66
+ - lib/simplabs/excellent/checks/class_variable_check.rb
63
67
  - lib/simplabs/excellent/checks/control_coupling_check.rb
64
68
  - lib/simplabs/excellent/checks/cyclomatic_complexity_block_check.rb
65
69
  - lib/simplabs/excellent/checks/cyclomatic_complexity_check.rb
@@ -87,10 +91,8 @@ files:
87
91
  - lib/simplabs/excellent/checks/rails/session_hash_in_view_check.rb
88
92
  - lib/simplabs/excellent/checks/rails/validations_check.rb
89
93
  - lib/simplabs/excellent/checks/rails.rb
90
- - lib/simplabs/excellent/checks/singleton_variable_check.rb
91
94
  - lib/simplabs/excellent/checks.rb
92
95
  - lib/simplabs/excellent/extensions/sexp.rb
93
- - lib/simplabs/excellent/extensions/string.rb
94
96
  - lib/simplabs/excellent/formatters/base.rb
95
97
  - lib/simplabs/excellent/formatters/html.rb
96
98
  - lib/simplabs/excellent/formatters/text.rb
@@ -107,10 +109,11 @@ files:
107
109
  - lib/simplabs/excellent/parsing/cyclomatic_complexity_measure.rb
108
110
  - lib/simplabs/excellent/parsing/flog_measure.rb
109
111
  - lib/simplabs/excellent/parsing/for_loop_context.rb
110
- - lib/simplabs/excellent/parsing/gvar_context.rb
111
112
  - lib/simplabs/excellent/parsing/gasgn_context.rb
113
+ - lib/simplabs/excellent/parsing/gvar_context.rb
112
114
  - lib/simplabs/excellent/parsing/if_context.rb
113
115
  - lib/simplabs/excellent/parsing/ivar_context.rb
116
+ - lib/simplabs/excellent/parsing/loc_parser.rb
114
117
  - lib/simplabs/excellent/parsing/method_context.rb
115
118
  - lib/simplabs/excellent/parsing/module_context.rb
116
119
  - lib/simplabs/excellent/parsing/parser.rb
@@ -126,38 +129,9 @@ files:
126
129
  - lib/simplabs/excellent/runner.rb
127
130
  - lib/simplabs/excellent/warning.rb
128
131
  - 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
132
  homepage: http://github.com/simplabs/excellent
160
- licenses: []
133
+ licenses:
134
+ - MIT
161
135
  post_install_message:
162
136
  rdoc_options:
163
137
  - --inline-source
@@ -178,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
152
  version: '0'
179
153
  requirements: []
180
154
  rubyforge_project:
181
- rubygems_version: 1.8.23
155
+ rubygems_version: 1.8.11
182
156
  signing_key:
183
157
  specification_version: 2
184
158
  summary: Source Code analysis gem for Ruby and Rails
data/README.rdoc DELETED
@@ -1,72 +0,0 @@
1
- = Excellent
2
-
3
- Excellent *finds the nasty lines in your code*. It implements a comprehensive set of checks for possibly buggy parts of your app that would *otherwise make it into your repo and eventually to the production server*.
4
-
5
- See the API documentation at http://docs.github.com/simplabs/excellent and the WIKI at http://wiki.github.com/simplabs/excellent.
6
- Join the Google Group and discuss about the future and possibilities of Excellent: http://groups.google.com/group/excellent-gem.
7
-
8
- Excellent also has a CI server set up at http://ci.simplabs.com/excellent.
9
-
10
- == Installation
11
-
12
- Simply install with Ruby Gems:
13
-
14
- gem sources -a http://gems.github.com
15
- sudo gem install simplabs-excellent
16
-
17
- == Example
18
-
19
- Assume you have the following class definition,
20
-
21
- class ShoppingBasket < ActiveRecord::Base
22
-
23
- def initialize(items = [])
24
- self.items = items
25
- end
26
-
27
- end
28
-
29
- then Excellent will report the problems in this piece of code:
30
-
31
- $ excellent shopping_basket.rb
32
-
33
- Excellent result:
34
-
35
- test.rb
36
- * Line 1: ShoppingBasket does not validate any attributes.
37
- * Line 1: ShoppingBasket defines initialize method.
38
- * Line 1: ShoppingBasket does not specify attr_accessible.
39
-
40
- Found 3 warnings.
41
-
42
- To analyse all the models in your Rails application, just do
43
-
44
- excellent app/models
45
-
46
- in your <tt>RAILS_ROOT</tt>. You can also invoke analysation through the Simplabs::Excellent::Runner class. Excellent can also produce HTML output. To
47
- get a formatted HTML report, just specify <tt>html:<filename></tt>:
48
-
49
- excellent -o out.html app/models
50
-
51
- You can also use Excellent in a Rake task:
52
-
53
- require 'simplabs/excellent/rake'
54
-
55
- Simplabs::Excellent::Rake::ExcellentTask.new(:excellent) do |t|
56
- t.html = 'doc/excellent.html' # optional, if you don't specify html, output will be written to $stdout
57
- t.paths = %w(app lib)
58
- end
59
-
60
- == Static analysis
61
-
62
- A few words regarding static code analysis: Static code analysis tools like Excellent can never really understand the code. They just search for patterns that *might* inidicate problematic code. The word *might* really has to be stressed here since static analysis will usually return a reasonable number of false positives. For example, there might be pretty good reasons for empty +rescue+ blocks that suppress all errors (Excellent itself does it). So, don't try and code with the aim of passing Excellent with zero warnings. That will most likely make your code a mess. Instead use Excellent as a helper to find *possibly* problematic code early.
63
-
64
- == Contribute
65
-
66
- If you want to contribute, just fork the repo. Also I would appretiate suggestions for more checks (especially Rails specific checks) - simply open a new issue: http://github.com/simplabs/excellent/issues.
67
-
68
- == Author
69
-
70
- Copyright (c) 2008-2010 Marco Otte-Witte (http://simplabs.com), released under the MIT license.
71
-
72
- Excellent was inspired by roodi (http://github.com/martinjandrews/roodi), reek (http://github.com/kevinrutherford/reek) and flog (http://github.com/seattlerb/flog).
data/VERSION.yml DELETED
@@ -1,4 +0,0 @@
1
- ---
2
- :major: 1
3
- :minor: 7
4
- :patch: 2
@@ -1,28 +0,0 @@
1
- module Simplabs
2
-
3
- module Excellent
4
-
5
- module Extensions #:nodoc:
6
-
7
- ::String.class_eval do
8
-
9
- def underscore
10
- to_s.gsub(/::/, '/').
11
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
12
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
13
- tr("-", "_").
14
- downcase
15
- end
16
-
17
- def lpad(to, with = ' ')
18
- return self if self.length >= to
19
- "#{with * (to - self.length)}#{self}"
20
- end
21
-
22
- end
23
-
24
- end
25
-
26
- end
27
-
28
- end
@@ -1,122 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Simplabs::Excellent::Checks::AbcMetricMethodCheck do
4
-
5
- before do
6
- @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::AbcMetricMethodCheck.new({ :threshold => 0 }))
7
- end
8
-
9
- describe '#evaluate' do
10
-
11
- describe 'when processing assignments' do
12
-
13
- it "should find =" do
14
- code = <<-END
15
- def method_name
16
- foo = 1
17
- end
18
- END
19
-
20
- verify_code_score(code, 1, 0, 0)
21
- end
22
-
23
- ['*=', '/=', '%=', '+=', '<<=', '>>=', '&=', '|=', '^=', '-=', '**='].each do |assignment|
24
-
25
- it "should find #{assignment}" do
26
- code = <<-END
27
- def method_name
28
- foo #{assignment} 1
29
- end
30
- END
31
-
32
- # these special assignments have score 2 since before the value is assigned, a method is called on the old value
33
- verify_code_score(code, 1, 0, 1)
34
- end
35
-
36
- end
37
-
38
- end
39
-
40
- describe 'when processing branches' do
41
-
42
- it 'should find a virtual method call' do
43
- code = <<-END
44
- def method_name
45
- call_foo
46
- end
47
- END
48
-
49
- verify_code_score(code, 0, 1, 0)
50
- end
51
-
52
- it 'should find an explicit method call' do
53
- code = <<-END
54
- def method_name
55
- @object.call_foo
56
- end
57
- END
58
-
59
- verify_code_score(code, 0, 1, 0)
60
- end
61
-
62
- it 'should exclude a condition' do
63
- code = <<-END
64
- def method_name
65
- @object.call_foo < 10
66
- end
67
- END
68
-
69
- verify_code_score(code, 0, 1, 1)
70
- end
71
-
72
- end
73
-
74
- describe 'when processing conditions' do
75
-
76
- ['==', '!=', '<=', '>=', '<', '>', '<=>', '=~'].each do |conditional|
77
-
78
- it "should find #{conditional}" do
79
- code = <<-END
80
- def method_name
81
- @foo #{conditional} @bar
82
- end
83
- END
84
-
85
- verify_code_score(code, 0, 0, 1)
86
- end
87
-
88
- end
89
-
90
- end
91
-
92
- it 'should also work on singleton methods' do
93
- code = <<-END
94
- class Class
95
- def self.method_name
96
- foo = 1
97
- end
98
- end
99
- END
100
- @excellent.check_code(code)
101
- warnings = @excellent.warnings
102
-
103
- warnings.should_not be_empty
104
- warnings[0].info.should == { :method => 'Class.method_name', :score => 1.0 }
105
- warnings[0].line_number.should == 2
106
- warnings[0].message.should == 'Class.method_name has abc score of 1.0.'
107
- end
108
-
109
- end
110
-
111
- def verify_code_score(code, a, b, c)
112
- score = Math.sqrt(a*a + b*b + c*c)
113
- @excellent.check_code(code)
114
- warnings = @excellent.warnings
115
-
116
- warnings.should_not be_empty
117
- warnings[0].info.should == { :method => 'method_name', :score => score }
118
- warnings[0].line_number.should == 1
119
- warnings[0].message.should == "method_name has abc score of #{score}."
120
- end
121
-
122
- end
@@ -1,90 +0,0 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
-
3
- describe Simplabs::Excellent::Checks::AssignmentInConditionalCheck do
4
-
5
- before do
6
- @excellent = Simplabs::Excellent::Runner.new(Simplabs::Excellent::Checks::AssignmentInConditionalCheck.new)
7
- end
8
-
9
- describe '#evaluate' do
10
-
11
- it 'should accept an assignment before an if clause' do
12
- code = <<-END
13
- count = count += 1 if @some_condition
14
- END
15
- @excellent.check_code(code)
16
-
17
- @excellent.warnings.should be_empty
18
- end
19
-
20
- it 'should accept block parameters in an if clause' do
21
- code = <<-END
22
- return true if exp.children.any? { |child| contains_statements?(child) }
23
- END
24
- @excellent.check_code(code)
25
-
26
- @excellent.warnings.should be_empty
27
- end
28
-
29
- it 'should reject assignments of results of blocks in an if clause' do
30
- code = <<-END
31
- return true if value = exp.children.find { |child| contains_statements?(child) }
32
- END
33
-
34
- verify_warning_found(code)
35
- end
36
-
37
- it 'should reject an assignment inside an if clause' do
38
- code = <<-END
39
- call_foo if bar = bam
40
- END
41
-
42
- verify_warning_found(code)
43
- end
44
-
45
- it 'should reject an assignment inside an unless clause' do
46
- code = <<-END
47
- call_foo unless bar = bam
48
- END
49
-
50
- verify_warning_found(code)
51
- end
52
-
53
- it 'should reject an assignment inside a while clause' do
54
- code = <<-END
55
- call_foo while bar = bam
56
- END
57
-
58
- verify_warning_found(code)
59
- end
60
-
61
- it 'should reject an assignment inside an until clause' do
62
- code = <<-END
63
- call_foo until bar = bam
64
- END
65
-
66
- verify_warning_found(code)
67
- end
68
-
69
- it 'should reject an assignment inside a ternary operator check clause' do
70
- code = <<-END
71
- call_foo (bar = bam) ? baz : bad
72
- END
73
-
74
- #RubyParser sets line number 2 here
75
- verify_warning_found(code, 2)
76
- end
77
-
78
- end
79
-
80
- def verify_warning_found(code, line_number = nil)
81
- @excellent.check_code(code)
82
- warnings = @excellent.warnings
83
-
84
- warnings.should_not be_empty
85
- warnings[0].info.should == {}
86
- warnings[0].line_number.should == (line_number || 1)
87
- warnings[0].message.should == 'Assignment in condition.'
88
- end
89
-
90
- end