reek 5.3.1 → 5.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +0 -9
  3. data/.travis.yml +1 -2
  4. data/CHANGELOG.md +4 -0
  5. data/Gemfile +1 -1
  6. data/docs/API.md +4 -4
  7. data/docs/Duplicate-Method-Call.md +68 -1
  8. data/docs/How-To-Write-New-Detectors.md +4 -4
  9. data/docs/Reek-Driven-Development.md +19 -12
  10. data/features/command_line_interface/options.feature +2 -2
  11. data/features/reports/json.feature +3 -3
  12. data/features/reports/reports.feature +4 -4
  13. data/features/reports/yaml.feature +3 -3
  14. data/lib/reek/source/source_code.rb +2 -2
  15. data/lib/reek/version.rb +1 -1
  16. data/spec/reek/ast/node_spec.rb +2 -2
  17. data/spec/reek/code_comment_spec.rb +6 -6
  18. data/spec/reek/context/code_context_spec.rb +2 -2
  19. data/spec/reek/context_builder_spec.rb +30 -30
  20. data/spec/reek/examiner_spec.rb +6 -6
  21. data/spec/reek/report/json_report_spec.rb +2 -2
  22. data/spec/reek/smell_detectors/attribute_spec.rb +32 -32
  23. data/spec/reek/smell_detectors/boolean_parameter_spec.rb +4 -4
  24. data/spec/reek/smell_detectors/class_variable_spec.rb +16 -16
  25. data/spec/reek/smell_detectors/control_parameter_spec.rb +18 -18
  26. data/spec/reek/smell_detectors/data_clump_spec.rb +16 -16
  27. data/spec/reek/smell_detectors/duplicate_method_call_spec.rb +20 -20
  28. data/spec/reek/smell_detectors/feature_envy_spec.rb +32 -32
  29. data/spec/reek/smell_detectors/instance_variable_assumption_spec.rb +12 -12
  30. data/spec/reek/smell_detectors/irresponsible_module_spec.rb +36 -36
  31. data/spec/reek/smell_detectors/long_parameter_list_spec.rb +6 -6
  32. data/spec/reek/smell_detectors/long_yield_list_spec.rb +6 -6
  33. data/spec/reek/smell_detectors/manual_dispatch_spec.rb +10 -10
  34. data/spec/reek/smell_detectors/missing_safe_method_spec.rb +8 -8
  35. data/spec/reek/smell_detectors/module_initialize_spec.rb +12 -12
  36. data/spec/reek/smell_detectors/nested_iterators_spec.rb +48 -48
  37. data/spec/reek/smell_detectors/nil_check_spec.rb +16 -16
  38. data/spec/reek/smell_detectors/repeated_conditional_spec.rb +8 -8
  39. data/spec/reek/smell_detectors/subclassed_from_core_class_spec.rb +10 -10
  40. data/spec/reek/smell_detectors/too_many_constants_spec.rb +22 -22
  41. data/spec/reek/smell_detectors/too_many_instance_variables_spec.rb +16 -16
  42. data/spec/reek/smell_detectors/too_many_methods_spec.rb +6 -6
  43. data/spec/reek/smell_detectors/too_many_statements_spec.rb +10 -10
  44. data/spec/reek/smell_detectors/uncommunicative_method_name_spec.rb +2 -2
  45. data/spec/reek/smell_detectors/uncommunicative_module_name_spec.rb +2 -2
  46. data/spec/reek/smell_detectors/uncommunicative_parameter_name_spec.rb +4 -4
  47. data/spec/reek/smell_detectors/uncommunicative_variable_name_spec.rb +18 -18
  48. data/spec/reek/smell_detectors/unused_parameters_spec.rb +4 -4
  49. data/spec/reek/smell_detectors/unused_private_method_spec.rb +24 -24
  50. data/spec/reek/smell_detectors/utility_function_spec.rb +30 -30
  51. metadata +3 -3
@@ -98,7 +98,7 @@ RSpec.describe Reek::ContextBuilder do
98
98
  end
99
99
 
100
100
  it 'counts 3 statements in an else' do
101
- code = <<-EOS
101
+ code = <<-RUBY
102
102
  def one()
103
103
  if val == 4
104
104
  callee(); callee(); callee()
@@ -106,7 +106,7 @@ RSpec.describe Reek::ContextBuilder do
106
106
  callee(); callee(); callee()
107
107
  end
108
108
  end
109
- EOS
109
+ RUBY
110
110
 
111
111
  expect(number_of_statements_for(code)).to eq(6)
112
112
  end
@@ -157,7 +157,7 @@ RSpec.describe Reek::ContextBuilder do
157
157
  end
158
158
 
159
159
  it 'counts 3 statements in a rescue' do
160
- code = <<-EOS
160
+ code = <<-RUBY
161
161
  def one()
162
162
  begin
163
163
  callee(); callee(); callee()
@@ -165,31 +165,31 @@ RSpec.describe Reek::ContextBuilder do
165
165
  callee(); callee(); callee()
166
166
  end
167
167
  end
168
- EOS
168
+ RUBY
169
169
  expect(number_of_statements_for(code)).to eq(6)
170
170
  end
171
171
 
172
172
  it 'counts 3 statements in a when' do
173
- code = <<-EOS
173
+ code = <<-RUBY
174
174
  def one()
175
175
  case fred
176
176
  when "hi" then callee(); callee()
177
177
  when "lo" then callee()
178
178
  end
179
179
  end
180
- EOS
180
+ RUBY
181
181
  expect(number_of_statements_for(code)).to eq(3)
182
182
  end
183
183
 
184
184
  it 'counts 3 statements in a case else' do
185
- code = <<-EOS
185
+ code = <<-RUBY
186
186
  def one()
187
187
  case fred
188
188
  when "hi" then callee(); callee(); callee()
189
189
  else callee(); callee(); callee()
190
190
  end
191
191
  end
192
- EOS
192
+ RUBY
193
193
  expect(number_of_statements_for(code)).to eq(6)
194
194
  end
195
195
 
@@ -221,7 +221,7 @@ RSpec.describe Reek::ContextBuilder do
221
221
  end
222
222
 
223
223
  it 'marks instance methods when using a def modifier' do
224
- code = <<-EOS
224
+ code = <<-RUBY
225
225
  class Foo
226
226
  private def bar
227
227
  end
@@ -229,7 +229,7 @@ RSpec.describe Reek::ContextBuilder do
229
229
  def baz
230
230
  end
231
231
  end
232
- EOS
232
+ RUBY
233
233
 
234
234
  root = context_tree_for(code)
235
235
  module_context = root.children.first
@@ -241,7 +241,7 @@ RSpec.describe Reek::ContextBuilder do
241
241
  end
242
242
 
243
243
  it 'does not mark class methods with instance visibility' do
244
- code = <<-EOS
244
+ code = <<-RUBY
245
245
  class Foo
246
246
  private
247
247
  def bar
@@ -249,7 +249,7 @@ RSpec.describe Reek::ContextBuilder do
249
249
  def self.baz
250
250
  end
251
251
  end
252
- EOS
252
+ RUBY
253
253
 
254
254
  root = context_tree_for(code)
255
255
  module_context = root.children.first
@@ -259,7 +259,7 @@ RSpec.describe Reek::ContextBuilder do
259
259
  end
260
260
 
261
261
  it 'only marks existing instance methods using later instance method modifiers' do
262
- code = <<-EOS
262
+ code = <<-RUBY
263
263
  class Foo
264
264
  def bar
265
265
  end
@@ -277,7 +277,7 @@ RSpec.describe Reek::ContextBuilder do
277
277
 
278
278
  private :bar, :baz
279
279
  end
280
- EOS
280
+ RUBY
281
281
 
282
282
  root = context_tree_for(code)
283
283
  module_context = root.children.first
@@ -289,7 +289,7 @@ RSpec.describe Reek::ContextBuilder do
289
289
  end
290
290
 
291
291
  it 'only marks existing instance attributes using later instance method modifiers' do
292
- code = <<-EOS
292
+ code = <<-RUBY
293
293
  class Foo
294
294
  attr_writer :bar
295
295
 
@@ -299,7 +299,7 @@ RSpec.describe Reek::ContextBuilder do
299
299
 
300
300
  private :bar
301
301
  end
302
- EOS
302
+ RUBY
303
303
 
304
304
  root = context_tree_for(code)
305
305
  module_context = root.children.first
@@ -309,14 +309,14 @@ RSpec.describe Reek::ContextBuilder do
309
309
  end
310
310
 
311
311
  it 'marks class method visibility using private_class_method' do
312
- code = <<-EOS
312
+ code = <<-RUBY
313
313
  class Foo
314
314
  def self.baz
315
315
  end
316
316
 
317
317
  private_class_method :baz
318
318
  end
319
- EOS
319
+ RUBY
320
320
 
321
321
  root = context_tree_for(code)
322
322
  module_context = root.children.first
@@ -325,7 +325,7 @@ RSpec.describe Reek::ContextBuilder do
325
325
  end
326
326
 
327
327
  it 'marks class method visibility using public_class_method' do
328
- code = <<-EOS
328
+ code = <<-RUBY
329
329
  class Foo
330
330
  class << self
331
331
  private
@@ -336,7 +336,7 @@ RSpec.describe Reek::ContextBuilder do
336
336
 
337
337
  public_class_method :baz
338
338
  end
339
- EOS
339
+ RUBY
340
340
 
341
341
  root = context_tree_for(code)
342
342
  module_context = root.children.first
@@ -345,7 +345,7 @@ RSpec.describe Reek::ContextBuilder do
345
345
  end
346
346
 
347
347
  it 'correctly skips nested modules' do
348
- code = <<-EOS
348
+ code = <<-RUBY
349
349
  class Foo
350
350
  class Bar
351
351
  def baz
@@ -361,7 +361,7 @@ RSpec.describe Reek::ContextBuilder do
361
361
  private :baz
362
362
  private_class_method :bar
363
363
  end
364
- EOS
364
+ RUBY
365
365
 
366
366
  root = context_tree_for(code)
367
367
  foo_context = root.children.first
@@ -373,7 +373,7 @@ RSpec.describe Reek::ContextBuilder do
373
373
 
374
374
  describe '#context_tree' do
375
375
  it 'creates the proper context for all kinds of singleton methods' do
376
- src = <<-EOS
376
+ src = <<-RUBY
377
377
  class Car
378
378
  def self.start; end
379
379
 
@@ -381,7 +381,7 @@ RSpec.describe Reek::ContextBuilder do
381
381
  def drive; end
382
382
  end
383
383
  end
384
- EOS
384
+ RUBY
385
385
 
386
386
  syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
387
387
  context_tree = described_class.new(syntax_tree).context_tree
@@ -395,7 +395,7 @@ RSpec.describe Reek::ContextBuilder do
395
395
  end
396
396
 
397
397
  it 'returns something sensible for nested metaclasses' do
398
- src = <<-EOS
398
+ src = <<-RUBY
399
399
  class Foo
400
400
  class << self
401
401
  class << self
@@ -403,7 +403,7 @@ RSpec.describe Reek::ContextBuilder do
403
403
  end
404
404
  end
405
405
  end
406
- EOS
406
+ RUBY
407
407
 
408
408
  syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
409
409
  context_tree = described_class.new(syntax_tree).context_tree
@@ -416,14 +416,14 @@ RSpec.describe Reek::ContextBuilder do
416
416
  end
417
417
 
418
418
  it 'returns something sensible for nested method definitions' do
419
- src = <<-EOS
419
+ src = <<-RUBY
420
420
  class Foo
421
421
  def foo
422
422
  def bar
423
423
  end
424
424
  end
425
425
  end
426
- EOS
426
+ RUBY
427
427
 
428
428
  syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
429
429
  context_tree = described_class.new(syntax_tree).context_tree
@@ -437,14 +437,14 @@ RSpec.describe Reek::ContextBuilder do
437
437
  end
438
438
 
439
439
  it 'returns something sensible for method definitions nested in singleton methods' do
440
- src = <<-EOS
440
+ src = <<-RUBY
441
441
  class Foo
442
442
  def self.foo
443
443
  def bar
444
444
  end
445
445
  end
446
446
  end
447
- EOS
447
+ RUBY
448
448
 
449
449
  syntax_tree = Reek::Source::SourceCode.from(src).syntax_tree
450
450
  context_tree = described_class.new(syntax_tree).context_tree
@@ -92,10 +92,10 @@ RSpec.describe Reek::Examiner do
92
92
 
93
93
  context 'when source only contains comments' do
94
94
  let(:source) do
95
- <<-EOS
95
+ <<-RUBY
96
96
  # Just a comment
97
97
  # And another
98
- EOS
98
+ RUBY
99
99
  end
100
100
  let(:examiner) do
101
101
  described_class.new(source)
@@ -255,10 +255,10 @@ RSpec.describe Reek::Examiner do
255
255
 
256
256
  context 'with an unknown smell detector' do
257
257
  let(:source) do
258
- <<-EOS
258
+ <<-RUBY
259
259
  # :reek:DoesNotExist
260
260
  def alfa; end
261
- EOS
261
+ RUBY
262
262
  end
263
263
 
264
264
  it 'raises a bad detector name error' do
@@ -281,10 +281,10 @@ RSpec.describe Reek::Examiner do
281
281
 
282
282
  context 'with garbage in detector config' do
283
283
  let(:source) do
284
- <<-EOS
284
+ <<-RUBY
285
285
  # :reek:UncommunicativeMethodName { thats: a: bad: config }
286
286
  def alfa; end
287
- EOS
287
+ RUBY
288
288
  end
289
289
 
290
290
  it 'raises a garbarge configuration error' do
@@ -30,7 +30,7 @@ RSpec.describe Reek::Report::JSONReport do
30
30
  instance.show(out)
31
31
  out.rewind
32
32
  result = JSON.parse(out.read)
33
- expected = JSON.parse <<-EOS
33
+ expected = JSON.parse <<-RUBY
34
34
  [
35
35
  {
36
36
  "context": "simple",
@@ -50,7 +50,7 @@ RSpec.describe Reek::Report::JSONReport do
50
50
  "documentation_link": "https://github.com/troessner/reek/blob/v#{Reek::Version::STRING}/docs/Utility-Function.md"
51
51
  }
52
52
  ]
53
- EOS
53
+ RUBY
54
54
 
55
55
  expect(result).to eq expected
56
56
  end
@@ -3,11 +3,11 @@ require_lib 'reek/smell_detectors/attribute'
3
3
 
4
4
  RSpec.describe Reek::SmellDetectors::Attribute do
5
5
  it 'reports the right values' do
6
- src = <<-EOS
6
+ src = <<-RUBY
7
7
  class Alfa
8
8
  attr_writer :bravo
9
9
  end
10
- EOS
10
+ RUBY
11
11
 
12
12
  expect(src).to reek_of(:Attribute,
13
13
  lines: [2],
@@ -16,12 +16,12 @@ RSpec.describe Reek::SmellDetectors::Attribute do
16
16
  end
17
17
 
18
18
  it 'does count all occurences' do
19
- src = <<-EOS
19
+ src = <<-RUBY
20
20
  class Alfa
21
21
  attr_writer :bravo
22
22
  attr_writer :charlie
23
23
  end
24
- EOS
24
+ RUBY
25
25
 
26
26
  expect(src).
27
27
  to reek_of(:Attribute, lines: [2], context: 'Alfa#bravo').
@@ -29,79 +29,79 @@ RSpec.describe Reek::SmellDetectors::Attribute do
29
29
  end
30
30
 
31
31
  it 'records nothing with no attributes' do
32
- src = <<-EOS
32
+ src = <<-RUBY
33
33
  class Alfa
34
34
  end
35
- EOS
35
+ RUBY
36
36
 
37
37
  expect(src).not_to reek_of(:Attribute)
38
38
  end
39
39
 
40
40
  context 'with attributes' do
41
41
  it 'records nothing for attribute readers' do
42
- src = <<-EOS
42
+ src = <<-RUBY
43
43
  class Alfa
44
44
  attr :bravo
45
45
  attr_reader :charlie
46
46
  end
47
- EOS
47
+ RUBY
48
48
 
49
49
  expect(src).not_to reek_of(:Attribute)
50
50
  end
51
51
 
52
52
  it 'records writer attribute' do
53
- src = <<-EOS
53
+ src = <<-RUBY
54
54
  class Alfa
55
55
  attr_writer :bravo
56
56
  end
57
- EOS
57
+ RUBY
58
58
 
59
59
  expect(src).to reek_of(:Attribute, context: 'Alfa#bravo')
60
60
  end
61
61
 
62
62
  it 'does not record writer attribute if suppressed with a preceding code comment' do
63
- src = <<-EOS
63
+ src = <<-RUBY
64
64
  class Alfa
65
65
  # :reek:Attribute
66
66
  attr_writer :bravo
67
67
  end
68
- EOS
68
+ RUBY
69
69
 
70
70
  expect(src).not_to reek_of(:Attribute)
71
71
  end
72
72
 
73
73
  it 'records attr_writer attribute in a module' do
74
- src = <<-EOS
74
+ src = <<-RUBY
75
75
  module Mod
76
76
  attr_writer :bravo
77
77
  end
78
- EOS
78
+ RUBY
79
79
 
80
80
  expect(src).to reek_of(:Attribute)
81
81
  end
82
82
 
83
83
  it 'records accessor attribute' do
84
- src = <<-EOS
84
+ src = <<-RUBY
85
85
  class Alfa
86
86
  attr_accessor :bravo
87
87
  end
88
- EOS
88
+ RUBY
89
89
 
90
90
  expect(src).to reek_of(:Attribute)
91
91
  end
92
92
 
93
93
  it 'records attr defining a writer' do
94
- src = <<-EOS
94
+ src = <<-RUBY
95
95
  class Alfa
96
96
  attr :bravo, true
97
97
  end
98
- EOS
98
+ RUBY
99
99
 
100
100
  expect(src).to reek_of(:Attribute)
101
101
  end
102
102
 
103
103
  it "doesn't record protected attributes" do
104
- src = <<-EOS
104
+ src = <<-RUBY
105
105
  class Alfa
106
106
  protected
107
107
  attr_writer :alfa
@@ -110,13 +110,13 @@ RSpec.describe Reek::SmellDetectors::Attribute do
110
110
  attr :delta, true
111
111
  attr_reader :echo
112
112
  end
113
- EOS
113
+ RUBY
114
114
 
115
115
  expect(src).not_to reek_of(:Attribute)
116
116
  end
117
117
 
118
118
  it "doesn't record private attributes" do
119
- src = <<-EOS
119
+ src = <<-RUBY
120
120
  class Alfa
121
121
  private
122
122
  attr_writer :alfa
@@ -125,37 +125,37 @@ RSpec.describe Reek::SmellDetectors::Attribute do
125
125
  attr :delta, true
126
126
  attr_reader :echo
127
127
  end
128
- EOS
128
+ RUBY
129
129
 
130
130
  expect(src).not_to reek_of(:Attribute)
131
131
  end
132
132
 
133
133
  it 'records attr_writer defined in public section' do
134
- src = <<-EOS
134
+ src = <<-RUBY
135
135
  class Alfa
136
136
  private
137
137
  public
138
138
  attr_writer :bravo
139
139
  end
140
- EOS
140
+ RUBY
141
141
 
142
142
  expect(src).to reek_of(:Attribute)
143
143
  end
144
144
 
145
145
  it 'records attr_writer after switching visbility to public' do
146
- src = <<-EOS
146
+ src = <<-RUBY
147
147
  class Alfa
148
148
  private
149
149
  attr_writer :bravo
150
150
  public :bravo
151
151
  end
152
- EOS
152
+ RUBY
153
153
 
154
154
  expect(src).to reek_of(:Attribute)
155
155
  end
156
156
 
157
157
  it 'resets visibility in new contexts' do
158
- src = <<-EOS
158
+ src = <<-RUBY
159
159
  class Alfa
160
160
  private
161
161
  attr_writer :bravo
@@ -164,32 +164,32 @@ RSpec.describe Reek::SmellDetectors::Attribute do
164
164
  class Charlie
165
165
  attr_writer :delta
166
166
  end
167
- EOS
167
+ RUBY
168
168
 
169
169
  expect(src).to reek_of(:Attribute, context: 'Charlie#delta')
170
170
  end
171
171
 
172
172
  it 'records attr_writer defining a class attribute' do
173
- src = <<-EOS
173
+ src = <<-RUBY
174
174
  class Alfa
175
175
  class << self
176
176
  attr_writer :bravo
177
177
  end
178
178
  end
179
- EOS
179
+ RUBY
180
180
 
181
181
  expect(src).to reek_of(:Attribute)
182
182
  end
183
183
 
184
184
  it 'does not record private class attributes' do
185
- src = <<-EOS
185
+ src = <<-RUBY
186
186
  class Alfa
187
187
  class << self
188
188
  private
189
189
  attr_writer :bravo
190
190
  end
191
191
  end
192
- EOS
192
+ RUBY
193
193
 
194
194
  expect(src).not_to reek_of(:Attribute)
195
195
  end