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
@@ -3,10 +3,10 @@ require_lib 'reek/smell_detectors/boolean_parameter'
3
3
 
4
4
  RSpec.describe Reek::SmellDetectors::BooleanParameter do
5
5
  it 'reports the right values' do
6
- src = <<-EOS
6
+ src = <<-RUBY
7
7
  def alfa(bravo = true)
8
8
  end
9
- EOS
9
+ RUBY
10
10
 
11
11
  expect(src).to reek_of(:BooleanParameter,
12
12
  lines: [1],
@@ -17,10 +17,10 @@ RSpec.describe Reek::SmellDetectors::BooleanParameter do
17
17
  end
18
18
 
19
19
  it 'does count all occurences' do
20
- src = <<-EOS
20
+ src = <<-RUBY
21
21
  def alfa(bravo = true, charlie = true)
22
22
  end
23
- EOS
23
+ RUBY
24
24
 
25
25
  expect(src).
26
26
  to reek_of(:BooleanParameter, lines: [1], context: 'alfa', parameter: 'bravo').
@@ -3,11 +3,11 @@ require_lib 'reek/smell_detectors/class_variable'
3
3
 
4
4
  RSpec.describe Reek::SmellDetectors::ClassVariable do
5
5
  it 'reports the right values' do
6
- src = <<-EOS
6
+ src = <<-RUBY
7
7
  class Alfa
8
8
  @@bravo = 5
9
9
  end
10
- EOS
10
+ RUBY
11
11
 
12
12
  expect(src).to reek_of(:ClassVariable,
13
13
  lines: [2],
@@ -18,12 +18,12 @@ RSpec.describe Reek::SmellDetectors::ClassVariable do
18
18
  end
19
19
 
20
20
  it 'does count all class variables' do
21
- src = <<-EOS
21
+ src = <<-RUBY
22
22
  class Alfa
23
23
  @@bravo = 42
24
24
  @@charlie = 99
25
25
  end
26
- EOS
26
+ RUBY
27
27
 
28
28
  expect(src).
29
29
  to reek_of(:ClassVariable, name: '@@bravo').
@@ -31,32 +31,32 @@ RSpec.describe Reek::SmellDetectors::ClassVariable do
31
31
  end
32
32
 
33
33
  it 'does not report class instance variables' do
34
- src = <<-EOS
34
+ src = <<-RUBY
35
35
  class Alfa
36
36
  @bravo = 42
37
37
  end
38
- EOS
38
+ RUBY
39
39
 
40
40
  expect(src).not_to reek_of(:ClassVariable)
41
41
  end
42
42
 
43
43
  context 'with no class variables' do
44
44
  it 'records nothing in the class' do
45
- src = <<-EOS
45
+ src = <<-RUBY
46
46
  class Alfa
47
47
  def bravo; end
48
48
  end
49
- EOS
49
+ RUBY
50
50
 
51
51
  expect(src).not_to reek_of(:ClassVariable)
52
52
  end
53
53
 
54
54
  it 'records nothing in the module' do
55
- src = <<-EOS
55
+ src = <<-RUBY
56
56
  module Alfa
57
57
  def bravo; end
58
58
  end
59
- EOS
59
+ RUBY
60
60
 
61
61
  expect(src).not_to reek_of(:ClassVariable)
62
62
  end
@@ -65,31 +65,31 @@ RSpec.describe Reek::SmellDetectors::ClassVariable do
65
65
  ['class', 'module'].each do |scope|
66
66
  context "when examining a #{scope}" do
67
67
  it 'reports a class variable set in a method' do
68
- src = <<-EOS
68
+ src = <<-RUBY
69
69
  #{scope} Alfa
70
70
  def bravo
71
71
  @@charlie = {}
72
72
  end
73
73
  end
74
- EOS
74
+ RUBY
75
75
 
76
76
  expect(src).to reek_of(:ClassVariable, name: '@@charlie')
77
77
  end
78
78
 
79
79
  it 'reports a class variable used in a method' do
80
- src = <<-EOS
80
+ src = <<-RUBY
81
81
  #{scope} Alfa
82
82
  def bravo
83
83
  puts @@charlie
84
84
  end
85
85
  end
86
- EOS
86
+ RUBY
87
87
 
88
88
  expect(src).to reek_of(:ClassVariable, name: '@@charlie')
89
89
  end
90
90
 
91
91
  it "reports a class variable set in the #{scope} body and used in a method" do
92
- src = <<-EOS
92
+ src = <<-RUBY
93
93
  #{scope} Alfa
94
94
  @@bravo = 42
95
95
 
@@ -97,7 +97,7 @@ RSpec.describe Reek::SmellDetectors::ClassVariable do
97
97
  puts @@bravo
98
98
  end
99
99
  end
100
- EOS
100
+ RUBY
101
101
 
102
102
  expect(src).to reek_of(:ClassVariable, name: '@@bravo')
103
103
  end
@@ -3,11 +3,11 @@ require_lib 'reek/smell_detectors/control_parameter'
3
3
 
4
4
  RSpec.describe Reek::SmellDetectors::ControlParameter do
5
5
  it 'reports the right values' do
6
- src = <<-EOS
6
+ src = <<-RUBY
7
7
  def alfa(bravo)
8
8
  bravo ? true : false
9
9
  end
10
- EOS
10
+ RUBY
11
11
 
12
12
  expect(src).to reek_of(:ControlParameter,
13
13
  lines: [2],
@@ -18,12 +18,12 @@ RSpec.describe Reek::SmellDetectors::ControlParameter do
18
18
  end
19
19
 
20
20
  it 'does count all occurences' do
21
- src = <<-EOS
21
+ src = <<-RUBY
22
22
  def alfa(bravo, charlie)
23
23
  bravo ? true : false
24
24
  charlie ? true : false
25
25
  end
26
- EOS
26
+ RUBY
27
27
 
28
28
  expect(src).
29
29
  to reek_of(:ControlParameter, lines: [2], argument: 'bravo').
@@ -31,7 +31,7 @@ RSpec.describe Reek::SmellDetectors::ControlParameter do
31
31
  end
32
32
 
33
33
  it 'does count multiple occurences of the same parameter' do
34
- src = <<-EOS
34
+ src = <<-RUBY
35
35
  def alfa(bravo, charlie)
36
36
  if bravo
37
37
  delta if charlie
@@ -40,7 +40,7 @@ RSpec.describe Reek::SmellDetectors::ControlParameter do
40
40
  delta if bravo
41
41
  end
42
42
  end
43
- EOS
43
+ RUBY
44
44
 
45
45
  expect(src).
46
46
  to reek_of(:ControlParameter, lines: [2, 6], argument: 'bravo').
@@ -136,46 +136,46 @@ RSpec.describe Reek::SmellDetectors::ControlParameter do
136
136
  end
137
137
 
138
138
  it 'reports on case statement' do
139
- src = <<-EOS
139
+ src = <<-RUBY
140
140
  def alfa(bravo)
141
141
  case bravo
142
142
  when nil then nil
143
143
  else false
144
144
  end
145
145
  end
146
- EOS
146
+ RUBY
147
147
 
148
148
  expect(src).to reek_of(:ControlParameter)
149
149
  end
150
150
 
151
151
  it 'reports on nested if statements that are both using control parameters' do
152
- src = <<-EOS
152
+ src = <<-RUBY
153
153
  def nested(bravo)
154
154
  if bravo
155
155
  charlie
156
156
  charlie if bravo
157
157
  end
158
158
  end
159
- EOS
159
+ RUBY
160
160
 
161
161
  expect(src).to reek_of(:ControlParameter)
162
162
  end
163
163
 
164
164
  it 'reports on nested suffix if statements where the inner if is a control parameter' do
165
- src = <<-EOS
165
+ src = <<-RUBY
166
166
  def nested(bravo)
167
167
  if true
168
168
  charlie
169
169
  charlie if bravo
170
170
  end
171
171
  end
172
- EOS
172
+ RUBY
173
173
 
174
174
  expect(src).to reek_of(:ControlParameter)
175
175
  end
176
176
 
177
177
  it 'reports on nested full if statements where the inner if is a control parameter' do
178
- src = <<-EOS
178
+ src = <<-RUBY
179
179
  def alfa(bravo)
180
180
  if true
181
181
  charlie
@@ -185,13 +185,13 @@ RSpec.describe Reek::SmellDetectors::ControlParameter do
185
185
  end
186
186
  end
187
187
  end
188
- EOS
188
+ RUBY
189
189
 
190
190
  expect(src).to reek_of(:ControlParameter)
191
191
  end
192
192
 
193
193
  it 'reports on elsif statements' do
194
- src = <<-EOS
194
+ src = <<-RUBY
195
195
  def alfa(bravo)
196
196
  if true
197
197
  charlie
@@ -199,7 +199,7 @@ RSpec.describe Reek::SmellDetectors::ControlParameter do
199
199
  delta
200
200
  end
201
201
  end
202
- EOS
202
+ RUBY
203
203
 
204
204
  expect(src).to reek_of(:ControlParameter)
205
205
  end
@@ -282,7 +282,7 @@ RSpec.describe Reek::SmellDetectors::ControlParameter do
282
282
  end
283
283
 
284
284
  it 'does not report when used in body of control flow operator' do
285
- src = <<-EOS
285
+ src = <<-RUBY
286
286
  def alfa(bravo)
287
287
  case bravo
288
288
  when :charlie
@@ -292,7 +292,7 @@ RSpec.describe Reek::SmellDetectors::ControlParameter do
292
292
  end
293
293
  echo or foxtrot(bravo)
294
294
  end
295
- EOS
295
+ RUBY
296
296
 
297
297
  expect(src).not_to reek_of(:ControlParameter)
298
298
  end
@@ -3,13 +3,13 @@ require_lib 'reek/smell_detectors/data_clump'
3
3
 
4
4
  RSpec.describe Reek::SmellDetectors::DataClump do
5
5
  it 'reports the right values' do
6
- src = <<-EOS
6
+ src = <<-RUBY
7
7
  class Alfa
8
8
  def bravo (echo, foxtrot); end
9
9
  def charlie(echo, foxtrot); end
10
10
  def delta (echo, foxtrot); end
11
11
  end
12
- EOS
12
+ RUBY
13
13
 
14
14
  expect(src).to reek_of(:DataClump,
15
15
  lines: [2, 3, 4],
@@ -21,7 +21,7 @@ RSpec.describe Reek::SmellDetectors::DataClump do
21
21
  end
22
22
 
23
23
  it 'does count all occurences' do
24
- src = <<-EOS
24
+ src = <<-RUBY
25
25
  class Alfa
26
26
  def bravo (echo, foxtrot); end
27
27
  def charlie(echo, foxtrot); end
@@ -31,7 +31,7 @@ RSpec.describe Reek::SmellDetectors::DataClump do
31
31
  def hotel(juliett, kilo); end
32
32
  def india(juliett, kilo); end
33
33
  end
34
- EOS
34
+ RUBY
35
35
 
36
36
  expect(src).
37
37
  to reek_of(:DataClump, lines: [2, 3, 4], parameters: ['echo', 'foxtrot']).
@@ -40,36 +40,36 @@ RSpec.describe Reek::SmellDetectors::DataClump do
40
40
 
41
41
  %w(class module).each do |scope|
42
42
  it "does not report parameter sets < 2 for #{scope}" do
43
- src = <<-EOS
43
+ src = <<-RUBY
44
44
  #{scope} Alfa
45
45
  def bravo (echo); end
46
46
  def charlie(echo); end
47
47
  def delta (echo); end
48
48
  end
49
- EOS
49
+ RUBY
50
50
 
51
51
  expect(src).not_to reek_of(:DataClump)
52
52
  end
53
53
 
54
54
  it "does not report less than 3 methods for #{scope}" do
55
- src = <<-EOS
55
+ src = <<-RUBY
56
56
  #{scope} Alfa
57
57
  def bravo (echo, foxtrot); end
58
58
  def charlie(echo, foxtrot); end
59
59
  end
60
- EOS
60
+ RUBY
61
61
 
62
62
  expect(src).not_to reek_of(:DataClump)
63
63
  end
64
64
 
65
65
  it 'does not care about the order of arguments' do
66
- src = <<-EOS
66
+ src = <<-RUBY
67
67
  #{scope} Alfa
68
68
  def bravo (echo, foxtrot); end
69
69
  def charlie(foxtrot, echo); end # <- This is the swapped one!
70
70
  def delta (echo, foxtrot); end
71
71
  end
72
- EOS
72
+ RUBY
73
73
 
74
74
  expect(src).to reek_of(:DataClump,
75
75
  count: 3,
@@ -77,13 +77,13 @@ RSpec.describe Reek::SmellDetectors::DataClump do
77
77
  end
78
78
 
79
79
  it 'reports parameter sets that are > 2' do
80
- src = <<-EOS
80
+ src = <<-RUBY
81
81
  #{scope} Alfa
82
82
  def bravo (echo, foxtrot, golf); end
83
83
  def charlie(echo, foxtrot, golf); end
84
84
  def delta (echo, foxtrot, golf); end
85
85
  end
86
- EOS
86
+ RUBY
87
87
 
88
88
  expect(src).to reek_of(:DataClump,
89
89
  count: 3,
@@ -91,27 +91,27 @@ RSpec.describe Reek::SmellDetectors::DataClump do
91
91
  end
92
92
 
93
93
  it 'detects clumps smaller than the total number of parameters' do
94
- src = <<-EOS
94
+ src = <<-RUBY
95
95
  # Total number of parameters is 3 but the clump size is 2.
96
96
  #{scope} Alfa
97
97
  def bravo (echo, foxtrot, golf); end
98
98
  def charlie(echo, golf, foxtrot); end
99
99
  def delta (hotel, echo, foxtrot); end
100
100
  end
101
- EOS
101
+ RUBY
102
102
 
103
103
  expect(src).to reek_of(:DataClump,
104
104
  parameters: ['echo', 'foxtrot'])
105
105
  end
106
106
 
107
107
  it 'ignores anonymous parameters' do
108
- src = <<-EOS
108
+ src = <<-RUBY
109
109
  #{scope} Alfa
110
110
  def bravo (echo, foxtrot, *); end
111
111
  def charlie(echo, foxtrot, *); end
112
112
  def delta (echo, foxtrot, *); end
113
113
  end
114
- EOS
114
+ RUBY
115
115
 
116
116
  expect(src).to reek_of(:DataClump,
117
117
  parameters: ['echo', 'foxtrot'])
@@ -3,14 +3,14 @@ require_lib 'reek/smell_detectors/duplicate_method_call'
3
3
 
4
4
  RSpec.describe Reek::SmellDetectors::DuplicateMethodCall do
5
5
  it 'reports the right values' do
6
- src = <<-EOS
6
+ src = <<-RUBY
7
7
  class Alfa
8
8
  def bravo(charlie)
9
9
  charlie.delta
10
10
  charlie.delta
11
11
  end
12
12
  end
13
- EOS
13
+ RUBY
14
14
 
15
15
  expect(src).to reek_of(:DuplicateMethodCall,
16
16
  lines: [3, 4],
@@ -22,7 +22,7 @@ RSpec.describe Reek::SmellDetectors::DuplicateMethodCall do
22
22
  end
23
23
 
24
24
  it 'does count all occurences' do
25
- src = <<-EOS
25
+ src = <<-RUBY
26
26
  class Alfa
27
27
  def bravo(charlie)
28
28
  charlie.delta
@@ -34,7 +34,7 @@ RSpec.describe Reek::SmellDetectors::DuplicateMethodCall do
34
34
  foxtrot.golf
35
35
  end
36
36
  end
37
- EOS
37
+ RUBY
38
38
 
39
39
  expect(src).
40
40
  to reek_of(:DuplicateMethodCall, lines: [3, 4], name: 'charlie.delta', count: 2).
@@ -67,12 +67,12 @@ RSpec.describe Reek::SmellDetectors::DuplicateMethodCall do
67
67
 
68
68
  context 'with repeated simple method calls' do
69
69
  it 'reports no smell' do
70
- src = <<-EOS
70
+ src = <<-RUBY
71
71
  def alfa
72
72
  bravo
73
73
  bravo
74
74
  end
75
- EOS
75
+ RUBY
76
76
 
77
77
  expect(src).not_to reek_of(:DuplicateMethodCall)
78
78
  end
@@ -80,23 +80,23 @@ RSpec.describe Reek::SmellDetectors::DuplicateMethodCall do
80
80
 
81
81
  context 'with repeated simple method calls with blocks' do
82
82
  it 'reports a smell if the blocks are identical' do
83
- src = <<-EOS
83
+ src = <<-RUBY
84
84
  def alfa
85
85
  bravo { charlie }
86
86
  bravo { charlie }
87
87
  end
88
- EOS
88
+ RUBY
89
89
 
90
90
  expect(src).to reek_of(:DuplicateMethodCall)
91
91
  end
92
92
 
93
93
  it 'reports no smell if the blocks are different' do
94
- src = <<-EOS
94
+ src = <<-RUBY
95
95
  def alfa
96
96
  bravo { charlie }
97
97
  bravo { delta }
98
98
  end
99
- EOS
99
+ RUBY
100
100
 
101
101
  expect(src).not_to reek_of(:DuplicateMethodCall)
102
102
  end
@@ -104,23 +104,23 @@ RSpec.describe Reek::SmellDetectors::DuplicateMethodCall do
104
104
 
105
105
  context 'with repeated method calls with receivers with blocks' do
106
106
  it 'reports a smell if the blocks are identical' do
107
- src = <<-EOS
107
+ src = <<-RUBY
108
108
  def alfa
109
109
  bravo.charlie { delta }
110
110
  bravo.charlie { delta }
111
111
  end
112
- EOS
112
+ RUBY
113
113
 
114
114
  expect(src).to reek_of(:DuplicateMethodCall)
115
115
  end
116
116
 
117
117
  it 'reports a smell if the blocks are different' do
118
- src = <<-EOS
118
+ src = <<-RUBY
119
119
  def alfa
120
120
  bravo.charlie { delta }
121
121
  bravo.charlie { echo }
122
122
  end
123
- EOS
123
+ RUBY
124
124
 
125
125
  expect(src).to reek_of(:DuplicateMethodCall)
126
126
  end
@@ -128,23 +128,23 @@ RSpec.describe Reek::SmellDetectors::DuplicateMethodCall do
128
128
 
129
129
  context 'with repeated attribute assignment' do
130
130
  it 'reports repeated assignment' do
131
- src = <<-EOS
131
+ src = <<-RUBY
132
132
  def alfa(bravo)
133
133
  @charlie[bravo] = true
134
134
  @charlie[bravo] = true
135
135
  end
136
- EOS
136
+ RUBY
137
137
 
138
138
  expect(src).to reek_of(:DuplicateMethodCall)
139
139
  end
140
140
 
141
141
  it 'does not report multi-assignments' do
142
- src = <<-EOS
142
+ src = <<-RUBY
143
143
  def alfa
144
144
  bravo, charlie = delta, echo
145
145
  charlie, bravo = delta, echo
146
146
  end
147
- EOS
147
+ RUBY
148
148
 
149
149
  expect(src).not_to reek_of(:DuplicateMethodCall)
150
150
  end
@@ -178,11 +178,11 @@ RSpec.describe Reek::SmellDetectors::DuplicateMethodCall do
178
178
  end
179
179
 
180
180
  it 'reports quadruple calls' do
181
- src = <<-EOS
181
+ src = <<-RUBY
182
182
  def alfa
183
183
  bravo.charlie + bravo.charlie + bravo.charlie + bravo.charlie
184
184
  end
185
- EOS
185
+ RUBY
186
186
 
187
187
  expect(src).to reek_of(:DuplicateMethodCall,
188
188
  count: 4).with_config(config)