reek 1.2.13 → 1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/config/defaults.reek +3 -0
- data/features/ruby_api/api.feature +5 -1
- data/features/samples.feature +170 -153
- data/features/step_definitions/reek_steps.rb +1 -9
- data/lib/reek/core/code_parser.rb +4 -4
- data/lib/reek/core/method_context.rb +2 -11
- data/lib/reek/core/smell_repository.rb +1 -0
- data/lib/reek/smells.rb +1 -0
- data/lib/reek/smells/duplication.rb +1 -1
- data/lib/reek/smells/irresponsible_module.rb +5 -1
- data/lib/reek/smells/simulated_polymorphism.rb +1 -1
- data/lib/reek/smells/uncommunicative_variable_name.rb +43 -3
- data/lib/reek/smells/unused_parameters.rb +37 -0
- data/lib/reek/source/source_code.rb +2 -13
- data/lib/reek/source/tree_dresser.rb +11 -24
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +4 -5
- data/spec/reek/smells/control_couple_spec.rb +1 -5
- data/spec/reek/smells/feature_envy_spec.rb +0 -3
- data/spec/reek/smells/irresponsible_module_spec.rb +10 -1
- data/spec/reek/smells/long_method_spec.rb +24 -2
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +66 -0
- data/spec/reek/smells/unused_parameters_spec.rb +47 -0
- data/spec/reek/smells/utility_function_spec.rb +3 -3
- data/spec/reek/source/tree_dresser_spec.rb +88 -33
- metadata +40 -40
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__)))), 'spec_helper')
|
3
|
+
require File.join(File.dirname(File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))), 'lib', 'reek', 'smells', 'unused_parameters')
|
4
|
+
require File.join(File.dirname(File.expand_path(__FILE__)), 'smell_detector_shared')
|
5
|
+
|
6
|
+
include Reek
|
7
|
+
include Reek::Smells
|
8
|
+
|
9
|
+
describe UnusedParameters do
|
10
|
+
|
11
|
+
context 'for methods' do
|
12
|
+
|
13
|
+
it 'should report nothing for no parameters' do
|
14
|
+
'def simple; true end'.should_not smell_of(UnusedParameters)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should report nothing for used parameter' do
|
18
|
+
'def simple(sum); sum end'.should_not smell_of(UnusedParameters)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should report for 1 used and 2 unused parameter' do
|
22
|
+
src = 'def simple(num,sum,denum); sum end'
|
23
|
+
src.should smell_of(UnusedParameters,
|
24
|
+
{UnusedParameters::PARAMETER_KEY => 'num'},
|
25
|
+
{UnusedParameters::PARAMETER_KEY => 'denum'})
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should report for 3 used and 1 unused parameter' do
|
29
|
+
src = 'def simple(num,sum,denum,quotient); num + denum + sum end'
|
30
|
+
src.should smell_of(UnusedParameters,
|
31
|
+
{UnusedParameters::PARAMETER_KEY => 'quotient'})
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should report nothing for used splatted parameter' do
|
35
|
+
'def simple(*sum); sum end'.should_not smell_of(UnusedParameters)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should report nothing for unused anonymous parameter' do
|
39
|
+
'def simple(_); end'.should_not smell_of(UnusedParameters)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should report nothing for unused anonymous splatted parameter' do
|
43
|
+
'def simple(*); end'.should_not smell_of(UnusedParameters)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -29,13 +29,13 @@ describe UtilityFunction do
|
|
29
29
|
@detector.examine_context(ctx).should be_empty
|
30
30
|
end
|
31
31
|
it 'does not report literal' do
|
32
|
-
'def simple(
|
32
|
+
'def simple() 3; end'.should_not reek
|
33
33
|
end
|
34
34
|
it 'does not report instance variable reference' do
|
35
|
-
'def simple(
|
35
|
+
'def simple() @yellow end'.should_not reek
|
36
36
|
end
|
37
37
|
it 'does not report vcall' do
|
38
|
-
'def simple(
|
38
|
+
'def simple() y end'.should_not reek
|
39
39
|
end
|
40
40
|
it 'does not report references to self' do
|
41
41
|
'def into; self; end'.should_not reek
|
@@ -44,8 +44,8 @@ describe SexpExtensions::DefnNode do
|
|
44
44
|
@node = s(:defn, :hello, s(:args))
|
45
45
|
@node.extend(SexpExtensions::DefnNode)
|
46
46
|
end
|
47
|
-
it 'has no
|
48
|
-
@node.
|
47
|
+
it 'has no arg names' do
|
48
|
+
@node.arg_names.should == s()
|
49
49
|
end
|
50
50
|
it 'has no parameter names' do
|
51
51
|
@node.parameter_names.should == s()
|
@@ -63,8 +63,8 @@ describe SexpExtensions::DefnNode do
|
|
63
63
|
@node = s(:defn, :hello, s(:args, :param))
|
64
64
|
@node.extend(SexpExtensions::DefnNode)
|
65
65
|
end
|
66
|
-
it 'has 1
|
67
|
-
@node.
|
66
|
+
it 'has 1 arg name' do
|
67
|
+
@node.arg_names.should == s(:param)
|
68
68
|
end
|
69
69
|
it 'has 1 parameter name' do
|
70
70
|
@node.parameter_names.should == s(:param)
|
@@ -82,10 +82,10 @@ describe SexpExtensions::DefnNode do
|
|
82
82
|
@node = s(:defn, :hello, s(:args, :param, :"&blk"))
|
83
83
|
@node.extend(SexpExtensions::DefnNode)
|
84
84
|
end
|
85
|
-
it 'has 1
|
86
|
-
@node.
|
85
|
+
it 'has 1 arg name' do
|
86
|
+
@node.arg_names.should == s(:param)
|
87
87
|
end
|
88
|
-
it 'has
|
88
|
+
it 'has 2 parameter names' do
|
89
89
|
@node.parameter_names.should == s(:param, :"&blk")
|
90
90
|
end
|
91
91
|
it 'includes outer scope in its full name' do
|
@@ -98,11 +98,11 @@ describe SexpExtensions::DefnNode do
|
|
98
98
|
|
99
99
|
context 'with 1 defaulted parameter' do
|
100
100
|
before :each do
|
101
|
-
@node = s(:defn, :hello, s(:args,
|
101
|
+
@node = s(:defn, :hello, s(:args, s(:lasgn, :param, s(:array))))
|
102
102
|
@node.extend(SexpExtensions::DefnNode)
|
103
103
|
end
|
104
|
-
it 'has 1
|
105
|
-
@node.
|
104
|
+
it 'has 1 arg name' do
|
105
|
+
@node.arg_names.should == s(:param)
|
106
106
|
end
|
107
107
|
it 'has 1 parameter name' do
|
108
108
|
@node.parameter_names.should == s(:param)
|
@@ -114,6 +114,22 @@ describe SexpExtensions::DefnNode do
|
|
114
114
|
@node.full_name('').should == 'hello'
|
115
115
|
end
|
116
116
|
end
|
117
|
+
|
118
|
+
context 'with a body with 2 statements' do
|
119
|
+
before :each do
|
120
|
+
@node = s(:defn, :hello, s(:args), s(:first), s(:second))
|
121
|
+
@node.extend(SexpExtensions::DefnNode)
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'has 2 body statements' do
|
125
|
+
@node.body.should == s(s(:first), s(:second))
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'has a body extended with SexpNode' do
|
129
|
+
b = @node.body
|
130
|
+
(class << b; self; end).ancestors.first.should == SexpNode
|
131
|
+
end
|
132
|
+
end
|
117
133
|
end
|
118
134
|
|
119
135
|
describe SexpExtensions::DefsNode do
|
@@ -122,8 +138,8 @@ describe SexpExtensions::DefsNode do
|
|
122
138
|
@node = s(:defs, :obj, :hello, s(:args))
|
123
139
|
@node.extend(SexpExtensions::DefsNode)
|
124
140
|
end
|
125
|
-
it 'has no
|
126
|
-
@node.
|
141
|
+
it 'has no arg names' do
|
142
|
+
@node.arg_names.should == s()
|
127
143
|
end
|
128
144
|
it 'has no parameter names' do
|
129
145
|
@node.parameter_names.should == s()
|
@@ -141,8 +157,8 @@ describe SexpExtensions::DefsNode do
|
|
141
157
|
@node = s(:defs, :obj, :hello, s(:args, :param))
|
142
158
|
@node.extend(SexpExtensions::DefsNode)
|
143
159
|
end
|
144
|
-
it 'has 1
|
145
|
-
@node.
|
160
|
+
it 'has 1 arg name' do
|
161
|
+
@node.arg_names.should == s(:param)
|
146
162
|
end
|
147
163
|
it 'has 1 parameter name' do
|
148
164
|
@node.parameter_names.should == s(:param)
|
@@ -160,10 +176,10 @@ describe SexpExtensions::DefsNode do
|
|
160
176
|
@node = s(:defs, :obj, :hello, s(:args, :param, :"&blk"))
|
161
177
|
@node.extend(SexpExtensions::DefsNode)
|
162
178
|
end
|
163
|
-
it 'has 1
|
164
|
-
@node.
|
179
|
+
it 'has 1 arg name' do
|
180
|
+
@node.arg_names.should == s(:param)
|
165
181
|
end
|
166
|
-
it 'has
|
182
|
+
it 'has 2 parameter names' do
|
167
183
|
@node.parameter_names.should == s(:param, :"&blk")
|
168
184
|
end
|
169
185
|
it 'includes outer scope in its full name' do
|
@@ -176,11 +192,11 @@ describe SexpExtensions::DefsNode do
|
|
176
192
|
|
177
193
|
context 'with 1 defaulted parameter' do
|
178
194
|
before :each do
|
179
|
-
@node = s(:defs, :obj, :hello, s(:args,
|
195
|
+
@node = s(:defs, :obj, :hello, s(:args, s(:lasgn, :param, s(:array))))
|
180
196
|
@node.extend(SexpExtensions::DefsNode)
|
181
197
|
end
|
182
|
-
it 'has 1
|
183
|
-
@node.
|
198
|
+
it 'has 1 arg name' do
|
199
|
+
@node.arg_names.should == s(:param)
|
184
200
|
end
|
185
201
|
it 'has 1 parameter name' do
|
186
202
|
@node.parameter_names.should == s(:param)
|
@@ -192,17 +208,62 @@ describe SexpExtensions::DefsNode do
|
|
192
208
|
@node.full_name('').should == 'obj.hello'
|
193
209
|
end
|
194
210
|
end
|
211
|
+
|
212
|
+
context 'with a body with 2 statements' do
|
213
|
+
before :each do
|
214
|
+
@node = s(:defs, s(:self), :hello, s(:args), s(:first), s(:second))
|
215
|
+
@node.extend(SexpExtensions::DefsNode)
|
216
|
+
end
|
217
|
+
|
218
|
+
it 'has 2 body statements' do
|
219
|
+
@node.body.should == s(s(:first), s(:second))
|
220
|
+
end
|
221
|
+
|
222
|
+
it 'has a body extended with SexpNode' do
|
223
|
+
b = @node.body
|
224
|
+
(class << b; self; end).ancestors.first.should == SexpNode
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
describe SexpExtensions::CallNode do
|
230
|
+
context 'with no parameters' do
|
231
|
+
before :each do
|
232
|
+
@node = s(:call, nil, :hello)
|
233
|
+
@node.extend(SexpExtensions::CallNode)
|
234
|
+
end
|
235
|
+
it 'has no parameter names' do
|
236
|
+
@node.parameter_names.should == nil
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
context 'with 1 literal parameter' do
|
241
|
+
before :each do
|
242
|
+
@node = s(:call, nil, :hello, s(:lit, :param))
|
243
|
+
@node.extend(SexpExtensions::CallNode)
|
244
|
+
end
|
245
|
+
it 'has 1 argument name' do
|
246
|
+
@node.arg_names.should == [:param]
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
context 'with 2 literal parameters' do
|
251
|
+
before :each do
|
252
|
+
@node = s(:call, nil, :hello, s(:lit, :x), s(:lit, :y))
|
253
|
+
@node.extend(SexpExtensions::CallNode)
|
254
|
+
end
|
255
|
+
it 'has 2 argument names' do
|
256
|
+
@node.arg_names.should == [:x, :y]
|
257
|
+
end
|
258
|
+
end
|
195
259
|
end
|
196
260
|
|
197
261
|
describe SexpExtensions::IterNode do
|
198
262
|
context 'with no parameters' do
|
199
263
|
before :each do
|
200
|
-
@node = s(:iter, s(),
|
264
|
+
@node = s(:iter, s(), s(:args), s())
|
201
265
|
@node.extend(SexpExtensions::IterNode)
|
202
266
|
end
|
203
|
-
it 'has no parameters' do
|
204
|
-
@node.parameters.should == []
|
205
|
-
end
|
206
267
|
it 'has no parameter names' do
|
207
268
|
@node.parameter_names.should == []
|
208
269
|
end
|
@@ -210,12 +271,9 @@ describe SexpExtensions::IterNode do
|
|
210
271
|
|
211
272
|
context 'with 1 parameter' do
|
212
273
|
before :each do
|
213
|
-
@node = s(:iter, s(), s(:
|
274
|
+
@node = s(:iter, s(), s(:args, :param), s())
|
214
275
|
@node.extend(SexpExtensions::IterNode)
|
215
276
|
end
|
216
|
-
it 'has 1 parameter' do
|
217
|
-
@node.parameters.should == s(:lasgn, :param)
|
218
|
-
end
|
219
277
|
it 'has 1 parameter name' do
|
220
278
|
@node.parameter_names.should == s(:param)
|
221
279
|
end
|
@@ -223,13 +281,10 @@ describe SexpExtensions::IterNode do
|
|
223
281
|
|
224
282
|
context 'with 2 parameters' do
|
225
283
|
before :each do
|
226
|
-
@node = s(:iter, s(), s(:
|
284
|
+
@node = s(:iter, s(), s(:args, :x, :y), s())
|
227
285
|
@node.extend(SexpExtensions::IterNode)
|
228
286
|
end
|
229
|
-
it 'has
|
230
|
-
@node.parameters.should == s(:masgn, s(:array, s(:lasgn, :x), s(:lasgn, :y)))
|
231
|
-
end
|
232
|
-
it 'has 1 parameter name' do
|
287
|
+
it 'has 2 parameter names' do
|
233
288
|
@node.parameter_names.should == [:x, :y]
|
234
289
|
end
|
235
290
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reek
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 1.2.13
|
8
|
+
- 3
|
9
|
+
version: "1.3"
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Kevin Rutherford
|
@@ -17,7 +16,7 @@ autorequire:
|
|
17
16
|
bindir: bin
|
18
17
|
cert_chain: []
|
19
18
|
|
20
|
-
date:
|
19
|
+
date: 2013-01-19 00:00:00 Z
|
21
20
|
dependencies:
|
22
21
|
- !ruby/object:Gem::Dependency
|
23
22
|
prerelease: false
|
@@ -27,27 +26,26 @@ dependencies:
|
|
27
26
|
requirements:
|
28
27
|
- - ~>
|
29
28
|
- !ruby/object:Gem::Version
|
30
|
-
hash:
|
29
|
+
hash: 15
|
31
30
|
segments:
|
32
|
-
-
|
31
|
+
- 3
|
33
32
|
- 0
|
34
|
-
|
33
|
+
- 4
|
34
|
+
version: 3.0.4
|
35
35
|
requirement: *id001
|
36
36
|
type: :runtime
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
prerelease: false
|
39
|
-
name:
|
39
|
+
name: sexp_processor
|
40
40
|
version_requirements: &id002 !ruby/object:Gem::Requirement
|
41
41
|
none: false
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
|
-
hash:
|
45
|
+
hash: 3
|
46
46
|
segments:
|
47
47
|
- 0
|
48
|
-
|
49
|
-
- 7
|
50
|
-
version: 0.0.7
|
48
|
+
version: "0"
|
51
49
|
requirement: *id002
|
52
50
|
type: :runtime
|
53
51
|
- !ruby/object:Gem::Dependency
|
@@ -58,33 +56,18 @@ dependencies:
|
|
58
56
|
requirements:
|
59
57
|
- - ~>
|
60
58
|
- !ruby/object:Gem::Version
|
61
|
-
hash:
|
59
|
+
hash: 15
|
62
60
|
segments:
|
63
|
-
- 1
|
64
61
|
- 2
|
65
|
-
- 5
|
66
|
-
version: 1.2.5
|
67
|
-
requirement: *id003
|
68
|
-
type: :runtime
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
prerelease: false
|
71
|
-
name: sexp_processor
|
72
|
-
version_requirements: &id004 !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ~>
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
hash: 7
|
78
|
-
segments:
|
79
|
-
- 3
|
80
62
|
- 0
|
81
|
-
|
82
|
-
|
63
|
+
- 0
|
64
|
+
version: 2.0.0
|
65
|
+
requirement: *id003
|
83
66
|
type: :runtime
|
84
67
|
- !ruby/object:Gem::Dependency
|
85
68
|
prerelease: false
|
86
69
|
name: bundler
|
87
|
-
version_requirements: &
|
70
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
88
71
|
none: false
|
89
72
|
requirements:
|
90
73
|
- - ~>
|
@@ -94,12 +77,12 @@ dependencies:
|
|
94
77
|
- 1
|
95
78
|
- 1
|
96
79
|
version: "1.1"
|
97
|
-
requirement: *
|
80
|
+
requirement: *id004
|
98
81
|
type: :development
|
99
82
|
- !ruby/object:Gem::Dependency
|
100
83
|
prerelease: false
|
101
84
|
name: rake
|
102
|
-
version_requirements: &
|
85
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
103
86
|
none: false
|
104
87
|
requirements:
|
105
88
|
- - ">="
|
@@ -108,12 +91,12 @@ dependencies:
|
|
108
91
|
segments:
|
109
92
|
- 0
|
110
93
|
version: "0"
|
111
|
-
requirement: *
|
94
|
+
requirement: *id005
|
112
95
|
type: :development
|
113
96
|
- !ruby/object:Gem::Dependency
|
114
97
|
prerelease: false
|
115
98
|
name: cucumber
|
116
|
-
version_requirements: &
|
99
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
117
100
|
none: false
|
118
101
|
requirements:
|
119
102
|
- - ">="
|
@@ -122,12 +105,12 @@ dependencies:
|
|
122
105
|
segments:
|
123
106
|
- 0
|
124
107
|
version: "0"
|
125
|
-
requirement: *
|
108
|
+
requirement: *id006
|
126
109
|
type: :development
|
127
110
|
- !ruby/object:Gem::Dependency
|
128
111
|
prerelease: false
|
129
112
|
name: rspec
|
130
|
-
version_requirements: &
|
113
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
131
114
|
none: false
|
132
115
|
requirements:
|
133
116
|
- - ~>
|
@@ -137,6 +120,20 @@ dependencies:
|
|
137
120
|
- 2
|
138
121
|
- 12
|
139
122
|
version: "2.12"
|
123
|
+
requirement: *id007
|
124
|
+
type: :development
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
prerelease: false
|
127
|
+
name: yard
|
128
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
hash: 3
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
version: "0"
|
140
137
|
requirement: *id008
|
141
138
|
type: :development
|
142
139
|
description: |
|
@@ -190,6 +187,7 @@ files:
|
|
190
187
|
- lib/reek/smells/duplication.rb
|
191
188
|
- lib/reek/smells/boolean_parameter.rb
|
192
189
|
- lib/reek/smells/uncommunicative_parameter_name.rb
|
190
|
+
- lib/reek/smells/unused_parameters.rb
|
193
191
|
- lib/reek/smells/long_method.rb
|
194
192
|
- lib/reek/smells/control_couple.rb
|
195
193
|
- lib/reek/smells/long_yield_list.rb
|
@@ -251,6 +249,7 @@ files:
|
|
251
249
|
- spec/reek/smells/class_variable_spec.rb
|
252
250
|
- spec/reek/smells/long_yield_list_spec.rb
|
253
251
|
- spec/reek/smells/control_couple_spec.rb
|
252
|
+
- spec/reek/smells/unused_parameters_spec.rb
|
254
253
|
- spec/reek/smells/uncommunicative_parameter_name_spec.rb
|
255
254
|
- spec/reek/smells/long_parameter_list_spec.rb
|
256
255
|
- spec/reek/smells/attribute_spec.rb
|
@@ -365,3 +364,4 @@ specification_version: 3
|
|
365
364
|
summary: Code smell detector for Ruby
|
366
365
|
test_files: []
|
367
366
|
|
367
|
+
has_rdoc:
|