excellent 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/lib/simplabs/excellent/checks/class_line_count_check.rb +7 -2
- data/lib/simplabs/excellent/checks/control_coupling_check.rb +1 -1
- data/lib/simplabs/excellent/checks/method_line_count_check.rb +1 -1
- data/lib/simplabs/excellent/checks/module_line_count_check.rb +1 -1
- data/lib/simplabs/excellent/checks/rails/instance_var_in_partial_check.rb +1 -1
- data/lib/simplabs/excellent/checks/rails/params_hash_in_view_check.rb +1 -1
- data/lib/simplabs/excellent/checks/rails/session_hash_in_view_check.rb +1 -1
- data/lib/simplabs/excellent/parsing/code_processor.rb +14 -2
- data/lib/simplabs/excellent/parsing/parser.rb +1 -1
- data/spec/checks/case_missing_else_check_spec.rb +9 -5
- data/spec/checks/control_coupling_check_spec.rb +5 -5
- data/spec/checks/singleton_variable_check_spec.rb +3 -3
- metadata +62 -37
data/History.txt
CHANGED
@@ -1,4 +1,15 @@
|
|
1
1
|
=======
|
2
|
+
= 1.7.0
|
3
|
+
|
4
|
+
* fixed issue #24
|
5
|
+
* updated ruby_parser and sexp_processor dependencies
|
6
|
+
* fixed some wrong line number reports
|
7
|
+
|
8
|
+
= 1.6.0
|
9
|
+
|
10
|
+
* added Gemfile
|
11
|
+
* internal refactoring/cleanups
|
12
|
+
|
2
13
|
= 1.5.5
|
3
14
|
|
4
15
|
* better option parsing in the executable, (thanks trans, http://github.com/trans)
|
@@ -21,10 +21,15 @@ module Simplabs
|
|
21
21
|
super([Parsing::ClassContext], threshold)
|
22
22
|
end
|
23
23
|
|
24
|
+
def evaluate(context)
|
25
|
+
line_count = context.line_count == 1 ? 1 : context.line_count + 1
|
26
|
+
add_warning(*warning_args(context, line_count)) unless line_count <= @threshold
|
27
|
+
end
|
28
|
+
|
24
29
|
protected
|
25
30
|
|
26
|
-
def warning_args(context) #:nodoc:
|
27
|
-
[context, '{{class}} has {{count}} lines.', { :class => context.full_name, :count =>
|
31
|
+
def warning_args(context, line_count) #:nodoc:
|
32
|
+
[context, '{{class}} has {{count}} lines.', { :class => context.full_name, :count => line_count }]
|
28
33
|
end
|
29
34
|
|
30
35
|
end
|
@@ -22,7 +22,7 @@ module Simplabs
|
|
22
22
|
|
23
23
|
def evaluate(context) #:nodoc:
|
24
24
|
if tested_parameter = context.tests_parameter?
|
25
|
-
add_warning(context, '{{method}} is coupled to {{argument}}.', { :method => context.parent.full_name, :argument => tested_parameter.to_s }
|
25
|
+
add_warning(context, '{{method}} is coupled to {{argument}}.', { :method => context.parent.full_name, :argument => tested_parameter.to_s })
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
@@ -24,7 +24,7 @@ module Simplabs
|
|
24
24
|
protected
|
25
25
|
|
26
26
|
def warning_args(context) #:nodoc:
|
27
|
-
[context, '{{method}} has {{count}} lines.', { :method => context.full_name, :count => context.line_count }]
|
27
|
+
[context, '{{method}} has {{count}} lines.', { :method => context.full_name, :count => context.line_count + 1 }]
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
@@ -24,7 +24,7 @@ module Simplabs
|
|
24
24
|
protected
|
25
25
|
|
26
26
|
def warning_args(context) #:nodoc:
|
27
|
-
[context, '{{module}} has {{count}} lines.', { :module => context.full_name, :count => context.line_count }]
|
27
|
+
[context, '{{module}} has {{count}} lines.', { :module => context.full_name, :count => context.line_count + 1 }]
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
@@ -23,7 +23,7 @@ module Simplabs
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def evaluate(context) #:nodoc:
|
26
|
-
add_warning(context, 'Instance variable {{variable}} used in partial.', { :variable => context.full_name }, -1)
|
26
|
+
add_warning(context, 'Instance variable {{variable}} used in partial.', { :variable => context.full_name }, RUBY_VERSION =~ /1\.9/ ? -1 : 0)
|
27
27
|
end
|
28
28
|
|
29
29
|
end
|
@@ -24,7 +24,7 @@ module Simplabs
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def evaluate(context) #:nodoc:
|
27
|
-
add_warning(context, 'Params hash used in view.', {}, -1) if (context.full_name == 'params')
|
27
|
+
add_warning(context, 'Params hash used in view.', {}, RUBY_VERSION =~ /1\.9/ ? -1 : 0) if (context.full_name == 'params')
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
@@ -24,7 +24,7 @@ module Simplabs
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def evaluate(context) #:nodoc:
|
27
|
-
add_warning(context, 'Session hash used in view.', {}, -1) if (context.full_name == 'session')
|
27
|
+
add_warning(context, 'Session hash used in view.', {}, RUBY_VERSION =~ /1\.9/ ? -1 : 0) if (context.full_name == 'session')
|
28
28
|
end
|
29
29
|
|
30
30
|
end
|
@@ -88,12 +88,24 @@ module Simplabs
|
|
88
88
|
end
|
89
89
|
|
90
90
|
def process_args(exp)
|
91
|
-
exp[1..-1].each
|
91
|
+
exp[1..-1].each do |parameter|
|
92
|
+
case parameter
|
93
|
+
when Sexp
|
94
|
+
case parameter[0]
|
95
|
+
when :masgn
|
96
|
+
parameter[1..-1].each { |parameter| @contexts.last.parameters << parameter }
|
97
|
+
when :lasgn
|
98
|
+
@contexts.last.parameters << parameter[1]
|
99
|
+
end
|
100
|
+
when Symbol
|
101
|
+
@contexts.last.parameters << parameter if parameter.is_a?(Symbol)
|
102
|
+
end
|
103
|
+
end
|
92
104
|
process_default(exp)
|
93
105
|
end
|
94
106
|
|
95
107
|
def process_masgn(exp)
|
96
|
-
exp[1
|
108
|
+
exp[1..-1].each { |parameter| @contexts.last.parameters << parameter[1] if parameter[1].is_a?(Symbol) } if @contexts.last.is_a?(BlockContext)
|
97
109
|
process_default(exp)
|
98
110
|
end
|
99
111
|
|
@@ -19,7 +19,7 @@ module Simplabs
|
|
19
19
|
private
|
20
20
|
|
21
21
|
def silent_parse(content, filename)
|
22
|
-
@parser ||= RubyParser.
|
22
|
+
@parser ||= RubyParser.for_current_ruby
|
23
23
|
content = ::ERB.new(content, nil, '-').src if filename =~ /\.erb$/
|
24
24
|
sexp = @parser.parse(content, filename)
|
25
25
|
sexp
|
@@ -11,8 +11,10 @@ describe Simplabs::Excellent::Checks::CaseMissingElseCheck do
|
|
11
11
|
it 'should accept case statements that do have an else clause' do
|
12
12
|
code = <<-END
|
13
13
|
case foo
|
14
|
-
when "bar"
|
15
|
-
|
14
|
+
when "bar"
|
15
|
+
"ok"
|
16
|
+
else
|
17
|
+
"good"
|
16
18
|
end
|
17
19
|
END
|
18
20
|
@excellent.check_code(code)
|
@@ -24,8 +26,10 @@ describe Simplabs::Excellent::Checks::CaseMissingElseCheck do
|
|
24
26
|
it 'should reject case statements that do not have an else clause' do
|
25
27
|
code = <<-END
|
26
28
|
case foo
|
27
|
-
when "bar"
|
28
|
-
|
29
|
+
when "bar"
|
30
|
+
"ok"
|
31
|
+
when "bar"
|
32
|
+
"bad"
|
29
33
|
end
|
30
34
|
END
|
31
35
|
@excellent.check_code(code)
|
@@ -33,7 +37,7 @@ describe Simplabs::Excellent::Checks::CaseMissingElseCheck do
|
|
33
37
|
|
34
38
|
warnings.should_not be_empty
|
35
39
|
warnings[0].info.should == {}
|
36
|
-
warnings[0].line_number.should ==
|
40
|
+
warnings[0].line_number.should == 1
|
37
41
|
warnings[0].message.should == 'Case statement is missing else clause.'
|
38
42
|
end
|
39
43
|
|
@@ -58,7 +58,7 @@ describe Simplabs::Excellent::Checks::ControlCouplingCheck do
|
|
58
58
|
end
|
59
59
|
END
|
60
60
|
|
61
|
-
verify_warning_found(code)
|
61
|
+
verify_warning_found(code, 2)
|
62
62
|
end
|
63
63
|
|
64
64
|
end
|
@@ -70,7 +70,7 @@ describe Simplabs::Excellent::Checks::ControlCouplingCheck do
|
|
70
70
|
end
|
71
71
|
END
|
72
72
|
|
73
|
-
verify_warning_found(code)
|
73
|
+
verify_warning_found(code, 3) # this should actually be line 2
|
74
74
|
end
|
75
75
|
|
76
76
|
it "should reject methods with case statements using a parameter" do
|
@@ -85,18 +85,18 @@ describe Simplabs::Excellent::Checks::ControlCouplingCheck do
|
|
85
85
|
end
|
86
86
|
END
|
87
87
|
|
88
|
-
verify_warning_found(code)
|
88
|
+
verify_warning_found(code, 2)
|
89
89
|
end
|
90
90
|
|
91
91
|
end
|
92
92
|
|
93
|
-
def verify_warning_found(code)
|
93
|
+
def verify_warning_found(code, line)
|
94
94
|
@excellent.check_code(code)
|
95
95
|
warnings = @excellent.warnings
|
96
96
|
|
97
97
|
warnings.should_not be_empty
|
98
98
|
warnings[0].info.should == { :method => 'write', :argument => 'quoted' }
|
99
|
-
warnings[0].line_number.should ==
|
99
|
+
warnings[0].line_number.should == line
|
100
100
|
warnings[0].message.should == 'write is coupled to quoted.'
|
101
101
|
end
|
102
102
|
|
@@ -17,7 +17,7 @@ describe Simplabs::Excellent::Checks::SingletonVariableCheck do
|
|
17
17
|
|
18
18
|
warnings.should_not be_empty
|
19
19
|
warnings[0].info.should == { :variable => 'foo' }
|
20
|
-
warnings[0].line_number.should ==
|
20
|
+
warnings[0].line_number.should == 1
|
21
21
|
warnings[0].message.should == 'Singleton variable foo used.'
|
22
22
|
end
|
23
23
|
|
@@ -36,7 +36,7 @@ describe Simplabs::Excellent::Checks::SingletonVariableCheck do
|
|
36
36
|
|
37
37
|
warnings.should_not be_empty
|
38
38
|
warnings[0].info.should == { :variable => 'Outer::Inner::Class.foo' }
|
39
|
-
warnings[0].line_number.should ==
|
39
|
+
warnings[0].line_number.should == 4
|
40
40
|
warnings[0].message.should == 'Singleton variable Outer::Inner::Class.foo used.'
|
41
41
|
end
|
42
42
|
|
@@ -57,7 +57,7 @@ describe Simplabs::Excellent::Checks::SingletonVariableCheck do
|
|
57
57
|
|
58
58
|
warnings.should_not be_empty
|
59
59
|
warnings[0].info.should == { :variable => 'Outer::Inner::Class.foo' }
|
60
|
-
warnings[0].line_number.should ==
|
60
|
+
warnings[0].line_number.should == 5
|
61
61
|
warnings[0].message.should == 'Singleton variable Outer::Inner::Class.foo used.'
|
62
62
|
end
|
63
63
|
|
metadata
CHANGED
@@ -1,45 +1,61 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: excellent
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 7
|
9
|
+
- 0
|
10
|
+
version: 1.7.0
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Marco Otte-Witte
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
|
18
|
+
date: 2009-08-05 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
15
21
|
name: ruby_parser
|
16
|
-
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
17
24
|
none: false
|
18
|
-
requirements:
|
19
|
-
- -
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 7
|
29
|
+
segments:
|
30
|
+
- 3
|
31
|
+
- 0
|
32
|
+
version: "3.0"
|
22
33
|
type: :runtime
|
23
|
-
|
24
|
-
|
25
|
-
- !ruby/object:Gem::Dependency
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
26
36
|
name: sexp_processor
|
27
|
-
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
28
39
|
none: false
|
29
|
-
requirements:
|
30
|
-
- -
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 27
|
44
|
+
segments:
|
45
|
+
- 4
|
46
|
+
- 0
|
47
|
+
version: "4.0"
|
33
48
|
type: :runtime
|
34
|
-
|
35
|
-
version_requirements: *70159583024300
|
49
|
+
version_requirements: *id002
|
36
50
|
description:
|
37
51
|
email: marco.otte-witte@simplabs.com
|
38
|
-
executables:
|
52
|
+
executables:
|
39
53
|
- excellent
|
40
54
|
extensions: []
|
55
|
+
|
41
56
|
extra_rdoc_files: []
|
42
|
-
|
57
|
+
|
58
|
+
files:
|
43
59
|
- History.txt
|
44
60
|
- README.rdoc
|
45
61
|
- VERSION.yml
|
@@ -149,28 +165,37 @@ files:
|
|
149
165
|
- spec/spec_helper.rb
|
150
166
|
homepage: http://github.com/simplabs/excellent
|
151
167
|
licenses: []
|
168
|
+
|
152
169
|
post_install_message:
|
153
|
-
rdoc_options:
|
170
|
+
rdoc_options:
|
154
171
|
- --inline-source
|
155
172
|
- --charset=UTF-8
|
156
|
-
require_paths:
|
173
|
+
require_paths:
|
157
174
|
- lib
|
158
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
175
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
159
176
|
none: false
|
160
|
-
requirements:
|
161
|
-
- -
|
162
|
-
- !ruby/object:Gem::Version
|
163
|
-
|
164
|
-
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
hash: 3
|
181
|
+
segments:
|
182
|
+
- 0
|
183
|
+
version: "0"
|
184
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
185
|
none: false
|
166
|
-
requirements:
|
167
|
-
- -
|
168
|
-
- !ruby/object:Gem::Version
|
169
|
-
|
186
|
+
requirements:
|
187
|
+
- - ">="
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
hash: 3
|
190
|
+
segments:
|
191
|
+
- 0
|
192
|
+
version: "0"
|
170
193
|
requirements: []
|
194
|
+
|
171
195
|
rubyforge_project:
|
172
|
-
rubygems_version: 1.8.
|
196
|
+
rubygems_version: 1.8.15
|
173
197
|
signing_key:
|
174
198
|
specification_version: 2
|
175
199
|
summary: Source Code analysis gem for Ruby and Rails
|
176
200
|
test_files: []
|
201
|
+
|