kevinrutherford-reek 1.1.2 → 1.1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/config/defaults.reek +2 -5
- data/lib/reek.rb +1 -1
- data/lib/reek/class_context.rb +1 -6
- data/lib/reek/code_parser.rb +11 -29
- data/lib/reek/object_source.rb +11 -3
- data/lib/reek/smells/large_class.rb +1 -1
- data/lib/reek/source.rb +4 -4
- data/reek.gemspec +1 -1
- data/spec/reek/class_context_spec.rb +0 -40
- data/spec/slow/inline_spec.rb +1 -2
- metadata +1 -1
data/History.txt
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
== 1.2.0 (In progress)
|
2
2
|
|
3
|
+
== Fixes
|
4
|
+
* LargeClass now relies only on the given source code (#26)
|
5
|
+
|
6
|
+
== 1.1.2 2009-05-18
|
7
|
+
|
3
8
|
=== Major Enhancements
|
4
9
|
* Switched from ParseTree to ruby_parser for source code parsing
|
5
10
|
* 'MyClass.should_not reek' now only possible if ParseTree gem installed
|
data/config/defaults.reek
CHANGED
data/lib/reek.rb
CHANGED
data/lib/reek/class_context.rb
CHANGED
@@ -2,10 +2,6 @@ require 'set'
|
|
2
2
|
require 'reek/code_context'
|
3
3
|
|
4
4
|
class Class
|
5
|
-
def non_inherited_methods
|
6
|
-
instance_methods(false) + private_instance_methods(false)
|
7
|
-
end
|
8
|
-
|
9
5
|
def is_overriding_method?(sym)
|
10
6
|
instance_methods(false).include?(sym) and superclass.instance_methods(true).include?(sym)
|
11
7
|
end
|
@@ -47,8 +43,7 @@ module Reek
|
|
47
43
|
end
|
48
44
|
|
49
45
|
def num_methods
|
50
|
-
|
51
|
-
meths.length
|
46
|
+
@parsed_methods.length
|
52
47
|
end
|
53
48
|
|
54
49
|
def record_instance_variable(sym)
|
data/lib/reek/code_parser.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require '
|
2
|
+
require 'sexp'
|
3
3
|
require 'reek/block_context'
|
4
4
|
require 'reek/class_context'
|
5
5
|
require 'reek/module_context'
|
@@ -11,31 +11,24 @@ require 'reek/yield_call_context'
|
|
11
11
|
|
12
12
|
module Reek
|
13
13
|
|
14
|
-
class CodeParser
|
14
|
+
class CodeParser
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
unifier.processors.each do |proc|
|
19
|
-
proc.unsupported.delete :cfunc # HACK
|
20
|
-
end
|
21
|
-
return unifier.process(sexp[0])
|
22
|
-
end
|
23
|
-
|
24
|
-
# Creates a new Ruby code checker. Any smells discovered by
|
25
|
-
# +check_source+ or +check_object+ will be stored in +report+.
|
16
|
+
# Creates a new Ruby code checker. Any smells discovered
|
17
|
+
# will be stored in +report+.
|
26
18
|
def initialize(report, smells, ctx = StopContext.new)
|
27
|
-
super()
|
28
19
|
@report = report
|
29
20
|
@smells = smells
|
30
21
|
@element = ctx
|
31
|
-
|
32
|
-
|
33
|
-
|
22
|
+
end
|
23
|
+
|
24
|
+
def process(exp)
|
25
|
+
meth = "process_#{exp[0]}"
|
26
|
+
meth = :process_default unless self.respond_to?(meth)
|
27
|
+
self.send(meth, exp)
|
34
28
|
end
|
35
29
|
|
36
30
|
def process_default(exp)
|
37
31
|
exp[0..-1].each { |sub| process(sub) if Array === sub }
|
38
|
-
s(exp)
|
39
32
|
end
|
40
33
|
|
41
34
|
def process_module(exp)
|
@@ -43,7 +36,6 @@ module Reek
|
|
43
36
|
process_default(exp)
|
44
37
|
check_smells(:module)
|
45
38
|
end
|
46
|
-
s(exp)
|
47
39
|
end
|
48
40
|
|
49
41
|
def process_class(exp)
|
@@ -51,7 +43,6 @@ module Reek
|
|
51
43
|
process_default(exp) unless @element.is_struct?
|
52
44
|
check_smells(:class)
|
53
45
|
end
|
54
|
-
s(exp)
|
55
46
|
end
|
56
47
|
|
57
48
|
def process_defn(exp)
|
@@ -64,18 +55,15 @@ module Reek
|
|
64
55
|
|
65
56
|
def process_args(exp)
|
66
57
|
exp[1..-1].each {|sym| @element.record_parameter(sym) }
|
67
|
-
s(exp)
|
68
58
|
end
|
69
59
|
|
70
60
|
def process_attrset(exp)
|
71
61
|
@element.record_depends_on_self if /^@/ === exp[1].to_s
|
72
|
-
s(exp)
|
73
62
|
end
|
74
63
|
|
75
64
|
def process_lit(exp)
|
76
65
|
val = exp[1]
|
77
66
|
@element.record_depends_on_self if val == :self
|
78
|
-
s(exp)
|
79
67
|
end
|
80
68
|
|
81
69
|
def process_iter(exp)
|
@@ -109,12 +97,10 @@ module Reek
|
|
109
97
|
|
110
98
|
def process_cfunc(exp)
|
111
99
|
@element.record_depends_on_self
|
112
|
-
s(exp)
|
113
100
|
end
|
114
101
|
|
115
102
|
def process_vcall(exp)
|
116
103
|
@element.record_use_of_self
|
117
|
-
s(exp)
|
118
104
|
end
|
119
105
|
|
120
106
|
def process_attrasgn(exp)
|
@@ -135,8 +121,7 @@ module Reek
|
|
135
121
|
|
136
122
|
def process_lasgn(exp)
|
137
123
|
@element.record_local_variable(exp[1])
|
138
|
-
|
139
|
-
s(exp)
|
124
|
+
process_default(exp)
|
140
125
|
end
|
141
126
|
|
142
127
|
def process_iasgn(exp)
|
@@ -147,7 +132,6 @@ module Reek
|
|
147
132
|
|
148
133
|
def process_self(exp)
|
149
134
|
@element.record_depends_on_self
|
150
|
-
s(exp)
|
151
135
|
end
|
152
136
|
|
153
137
|
def self.count_statements(exp)
|
@@ -173,7 +157,6 @@ module Reek
|
|
173
157
|
process_default(exp)
|
174
158
|
check_smells(type)
|
175
159
|
end
|
176
|
-
s(exp)
|
177
160
|
end
|
178
161
|
|
179
162
|
def check_smells(type)
|
@@ -189,7 +172,6 @@ module Reek
|
|
189
172
|
|
190
173
|
def pop(exp)
|
191
174
|
@element = @element.outer
|
192
|
-
s(exp)
|
193
175
|
end
|
194
176
|
end
|
195
177
|
end
|
data/lib/reek/object_source.rb
CHANGED
@@ -11,6 +11,15 @@ module Reek
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class ObjectSource < Source # :nodoc:
|
14
|
+
|
15
|
+
def self.unify(sexp) # :nodoc:
|
16
|
+
unifier = Unifier.new
|
17
|
+
unifier.processors.each do |proc|
|
18
|
+
proc.unsupported.delete :cfunc # HACK
|
19
|
+
end
|
20
|
+
return unifier.process(sexp[0])
|
21
|
+
end
|
22
|
+
|
14
23
|
def can_parse_objects?
|
15
24
|
return true if Object.const_defined?(:ParseTree)
|
16
25
|
begin
|
@@ -21,10 +30,9 @@ module Reek
|
|
21
30
|
end
|
22
31
|
end
|
23
32
|
|
24
|
-
def
|
33
|
+
def generate_syntax_tree
|
25
34
|
if can_parse_objects?
|
26
|
-
|
27
|
-
parser.process(sexp)
|
35
|
+
ObjectSource.unify(ParseTree.new.parse_tree(@source))
|
28
36
|
else
|
29
37
|
throw ArgumentError.new('You must install the ParseTree gem to use this feature')
|
30
38
|
end
|
data/lib/reek/source.rb
CHANGED
@@ -65,9 +65,8 @@ module Reek
|
|
65
65
|
@cf = @cf.load_local(dir) if dir
|
66
66
|
end
|
67
67
|
|
68
|
-
def
|
69
|
-
|
70
|
-
parser.process(sexp)
|
68
|
+
def generate_syntax_tree
|
69
|
+
RubyParser.new.parse(@source, @desc) || s()
|
71
70
|
end
|
72
71
|
|
73
72
|
#
|
@@ -78,7 +77,8 @@ module Reek
|
|
78
77
|
def report
|
79
78
|
unless @report
|
80
79
|
@report = Report.new
|
81
|
-
|
80
|
+
parser = CodeParser.new(@report, @cf.smell_listeners)
|
81
|
+
parser.process(generate_syntax_tree)
|
82
82
|
end
|
83
83
|
@report
|
84
84
|
end
|
data/reek.gemspec
CHANGED
@@ -39,46 +39,6 @@ EOEX
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
describe Class do
|
43
|
-
|
44
|
-
module Insert
|
45
|
-
def meth_a() end
|
46
|
-
private
|
47
|
-
def meth_b() end
|
48
|
-
protected
|
49
|
-
def meth_c() end
|
50
|
-
end
|
51
|
-
|
52
|
-
class Parent
|
53
|
-
def meth1() end
|
54
|
-
private
|
55
|
-
def meth2() end
|
56
|
-
protected
|
57
|
-
def meth3() end
|
58
|
-
end
|
59
|
-
|
60
|
-
class FullChild < Parent
|
61
|
-
include Insert
|
62
|
-
def meth7() end
|
63
|
-
private
|
64
|
-
def meth8() end
|
65
|
-
protected
|
66
|
-
def meth6() end
|
67
|
-
end
|
68
|
-
|
69
|
-
describe 'with no superclass or modules' do
|
70
|
-
it 'should report correct number of methods' do
|
71
|
-
Parent.non_inherited_methods.length.should == 3
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
describe 'with superclass and modules' do
|
76
|
-
it 'should report correct number of methods' do
|
77
|
-
FullChild.non_inherited_methods.length.should == 3
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
42
|
describe ClassContext, 'overridden methods' do
|
83
43
|
class Above
|
84
44
|
def above() end
|
data/spec/slow/inline_spec.rb
CHANGED
@@ -21,7 +21,6 @@ describe 'sample gem source code' do
|
|
21
21
|
ruby.should reek_of(:Duplication, /Inline::self.rootdir/, /env.nil?/)
|
22
22
|
ruby.should reek_of(:Duplication, /Module#inline/, /Inline.const_get\(lang\)/)
|
23
23
|
ruby.should reek_of(:FeatureEnvy, /Inline::C#strip_comments/, /src/)
|
24
|
-
ruby.should reek_of(:LargeClass, /Inline::C/, /methods/)
|
25
24
|
ruby.should reek_of(:LargeClass, /Inline::C/, /instance variables/)
|
26
25
|
ruby.should reek_of(:LongMethod, /File#self.write_with_backup/)
|
27
26
|
ruby.should reek_of(:LongMethod, /Inline::C#build/)
|
@@ -39,6 +38,6 @@ describe 'sample gem source code' do
|
|
39
38
|
ruby.should reek_of(:UncommunicativeName, /Inline::C#module_name/, /'x'/)
|
40
39
|
ruby.should reek_of(:UncommunicativeName, /Inline::C#parse_signature/, /'x'/)
|
41
40
|
ruby.should reek_of(:UtilityFunction, /Inline::C#strip_comments/)
|
42
|
-
ruby.report.should have_at_most(
|
41
|
+
ruby.report.should have_at_most(35).smells
|
43
42
|
end
|
44
43
|
end
|