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.
- checksums.yaml +5 -5
- data/.rubocop.yml +0 -9
- data/.travis.yml +1 -2
- data/CHANGELOG.md +4 -0
- data/Gemfile +1 -1
- data/docs/API.md +4 -4
- data/docs/Duplicate-Method-Call.md +68 -1
- data/docs/How-To-Write-New-Detectors.md +4 -4
- data/docs/Reek-Driven-Development.md +19 -12
- data/features/command_line_interface/options.feature +2 -2
- data/features/reports/json.feature +3 -3
- data/features/reports/reports.feature +4 -4
- data/features/reports/yaml.feature +3 -3
- data/lib/reek/source/source_code.rb +2 -2
- data/lib/reek/version.rb +1 -1
- data/spec/reek/ast/node_spec.rb +2 -2
- data/spec/reek/code_comment_spec.rb +6 -6
- data/spec/reek/context/code_context_spec.rb +2 -2
- data/spec/reek/context_builder_spec.rb +30 -30
- data/spec/reek/examiner_spec.rb +6 -6
- data/spec/reek/report/json_report_spec.rb +2 -2
- data/spec/reek/smell_detectors/attribute_spec.rb +32 -32
- data/spec/reek/smell_detectors/boolean_parameter_spec.rb +4 -4
- data/spec/reek/smell_detectors/class_variable_spec.rb +16 -16
- data/spec/reek/smell_detectors/control_parameter_spec.rb +18 -18
- data/spec/reek/smell_detectors/data_clump_spec.rb +16 -16
- data/spec/reek/smell_detectors/duplicate_method_call_spec.rb +20 -20
- data/spec/reek/smell_detectors/feature_envy_spec.rb +32 -32
- data/spec/reek/smell_detectors/instance_variable_assumption_spec.rb +12 -12
- data/spec/reek/smell_detectors/irresponsible_module_spec.rb +36 -36
- data/spec/reek/smell_detectors/long_parameter_list_spec.rb +6 -6
- data/spec/reek/smell_detectors/long_yield_list_spec.rb +6 -6
- data/spec/reek/smell_detectors/manual_dispatch_spec.rb +10 -10
- data/spec/reek/smell_detectors/missing_safe_method_spec.rb +8 -8
- data/spec/reek/smell_detectors/module_initialize_spec.rb +12 -12
- data/spec/reek/smell_detectors/nested_iterators_spec.rb +48 -48
- data/spec/reek/smell_detectors/nil_check_spec.rb +16 -16
- data/spec/reek/smell_detectors/repeated_conditional_spec.rb +8 -8
- data/spec/reek/smell_detectors/subclassed_from_core_class_spec.rb +10 -10
- data/spec/reek/smell_detectors/too_many_constants_spec.rb +22 -22
- data/spec/reek/smell_detectors/too_many_instance_variables_spec.rb +16 -16
- data/spec/reek/smell_detectors/too_many_methods_spec.rb +6 -6
- data/spec/reek/smell_detectors/too_many_statements_spec.rb +10 -10
- data/spec/reek/smell_detectors/uncommunicative_method_name_spec.rb +2 -2
- data/spec/reek/smell_detectors/uncommunicative_module_name_spec.rb +2 -2
- data/spec/reek/smell_detectors/uncommunicative_parameter_name_spec.rb +4 -4
- data/spec/reek/smell_detectors/uncommunicative_variable_name_spec.rb +18 -18
- data/spec/reek/smell_detectors/unused_parameters_spec.rb +4 -4
- data/spec/reek/smell_detectors/unused_private_method_spec.rb +24 -24
- data/spec/reek/smell_detectors/utility_function_spec.rb +30 -30
- metadata +3 -3
@@ -3,12 +3,12 @@ require_lib 'reek/smell_detectors/long_parameter_list'
|
|
3
3
|
|
4
4
|
RSpec.describe Reek::SmellDetectors::LongParameterList do
|
5
5
|
it 'reports the right values' do
|
6
|
-
src = <<-
|
6
|
+
src = <<-RUBY
|
7
7
|
class Alfa
|
8
8
|
def bravo(charlie, delta, echo, foxtrot)
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
11
|
+
RUBY
|
12
12
|
|
13
13
|
expect(src).to reek_of(:LongParameterList,
|
14
14
|
lines: [2],
|
@@ -19,7 +19,7 @@ RSpec.describe Reek::SmellDetectors::LongParameterList do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'does count all occurences' do
|
22
|
-
src = <<-
|
22
|
+
src = <<-RUBY
|
23
23
|
class Alfa
|
24
24
|
def bravo(charlie, delta, echo, foxtrot)
|
25
25
|
end
|
@@ -27,7 +27,7 @@ RSpec.describe Reek::SmellDetectors::LongParameterList do
|
|
27
27
|
def golf(hotel, india, juliett, kilo)
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
RUBY
|
31
31
|
|
32
32
|
expect(src).
|
33
33
|
to reek_of(:LongParameterList, lines: [2], context: 'Alfa#bravo').
|
@@ -45,11 +45,11 @@ RSpec.describe Reek::SmellDetectors::LongParameterList do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'does not report inner block with too many parameters' do
|
48
|
-
src = <<-
|
48
|
+
src = <<-RUBY
|
49
49
|
def alfa(bravo)
|
50
50
|
bravo.each { |charlie, delta, echo, foxtrot| }
|
51
51
|
end
|
52
|
-
|
52
|
+
RUBY
|
53
53
|
|
54
54
|
expect(src).not_to reek_of(:LongParameterList)
|
55
55
|
end
|
@@ -3,13 +3,13 @@ require_lib 'reek/smell_detectors/long_yield_list'
|
|
3
3
|
|
4
4
|
RSpec.describe Reek::SmellDetectors::LongYieldList do
|
5
5
|
it 'reports the right values' do
|
6
|
-
src = <<-
|
6
|
+
src = <<-RUBY
|
7
7
|
class Alfa
|
8
8
|
def bravo(charlie, delta, echo, foxtrot)
|
9
9
|
yield charlie, delta, echo, foxtrot
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
RUBY
|
13
13
|
|
14
14
|
expect(src).to reek_of(:LongYieldList,
|
15
15
|
lines: [3],
|
@@ -20,7 +20,7 @@ RSpec.describe Reek::SmellDetectors::LongYieldList do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'does count all occurences' do
|
23
|
-
src = <<-
|
23
|
+
src = <<-RUBY
|
24
24
|
class Alfa
|
25
25
|
def bravo(charlie, delta, echo, foxtrot)
|
26
26
|
yield charlie, delta, echo, foxtrot
|
@@ -30,7 +30,7 @@ RSpec.describe Reek::SmellDetectors::LongYieldList do
|
|
30
30
|
yield hotel, india, juliett, kilo
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
33
|
+
RUBY
|
34
34
|
|
35
35
|
expect(src).
|
36
36
|
to reek_of(:LongYieldList, lines: [3], context: 'Alfa#bravo').
|
@@ -38,11 +38,11 @@ RSpec.describe Reek::SmellDetectors::LongYieldList do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
it 'does not report yield with 3 parameters' do
|
41
|
-
src = <<-
|
41
|
+
src = <<-RUBY
|
42
42
|
def alfa(bravo, charlie, delta)
|
43
43
|
yield bravo, charlie, delta
|
44
44
|
end
|
45
|
-
|
45
|
+
RUBY
|
46
46
|
|
47
47
|
expect(src).not_to reek_of(:LongYieldList)
|
48
48
|
end
|
@@ -3,13 +3,13 @@ require_lib 'reek/smell_detectors/too_many_constants'
|
|
3
3
|
|
4
4
|
RSpec.describe Reek::SmellDetectors::ManualDispatch do
|
5
5
|
it 'reports the right values' do
|
6
|
-
src = <<-
|
6
|
+
src = <<-RUBY
|
7
7
|
class Alfa
|
8
8
|
def bravo(charlie)
|
9
9
|
true if charlie.respond_to?(:to_a)
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
RUBY
|
13
13
|
|
14
14
|
expect(src).to reek_of(:ManualDispatch,
|
15
15
|
lines: [3],
|
@@ -19,7 +19,7 @@ RSpec.describe Reek::SmellDetectors::ManualDispatch do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'does count all occurences' do
|
22
|
-
src = <<-
|
22
|
+
src = <<-RUBY
|
23
23
|
class Alfa
|
24
24
|
def bravo(charlie)
|
25
25
|
true if charlie.respond_to?(:to_a)
|
@@ -29,7 +29,7 @@ RSpec.describe Reek::SmellDetectors::ManualDispatch do
|
|
29
29
|
true if echo.respond_to?(:to_a)
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
32
|
+
RUBY
|
33
33
|
|
34
34
|
expect(src).
|
35
35
|
to reek_of(:ManualDispatch, lines: [3], context: 'Alfa#bravo').
|
@@ -37,38 +37,38 @@ RSpec.describe Reek::SmellDetectors::ManualDispatch do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'reports manual dispatch smell when using #respond_to? on implicit self' do
|
40
|
-
src = <<-
|
40
|
+
src = <<-RUBY
|
41
41
|
class Alfa
|
42
42
|
def bravo
|
43
43
|
charlie if respond_to?(:delta)
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
RUBY
|
47
47
|
|
48
48
|
expect(src).to reek_of(:ManualDispatch)
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'reports manual dispatch within a conditional' do
|
52
|
-
src = <<-
|
52
|
+
src = <<-RUBY
|
53
53
|
class Alfa
|
54
54
|
def bravo
|
55
55
|
charlie.respond_to?(:delta) && charlie.echo
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
RUBY
|
59
59
|
|
60
60
|
expect(src).to reek_of(:ManualDispatch)
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'reports occurences in a single method as one smell warning' do
|
64
|
-
src = <<-
|
64
|
+
src = <<-RUBY
|
65
65
|
class Alfa
|
66
66
|
def bravo(charlie, delta)
|
67
67
|
return true if charlie.respond_to?(:to_a)
|
68
68
|
true if delta.respond_to?(:to_a)
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
71
|
+
RUBY
|
72
72
|
|
73
73
|
expect(src).to reek_of(:ManualDispatch, lines: [3, 4], context: 'Alfa#bravo')
|
74
74
|
end
|
@@ -3,12 +3,12 @@ require_lib 'reek/smell_detectors/missing_safe_method'
|
|
3
3
|
|
4
4
|
RSpec.describe Reek::SmellDetectors::MissingSafeMethod do
|
5
5
|
it 'reports the right values' do
|
6
|
-
src = <<-
|
6
|
+
src = <<-RUBY
|
7
7
|
class Alfa
|
8
8
|
def bravo!
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
11
|
+
RUBY
|
12
12
|
|
13
13
|
expect(src).to reek_of(:MissingSafeMethod,
|
14
14
|
lines: [2],
|
@@ -19,7 +19,7 @@ RSpec.describe Reek::SmellDetectors::MissingSafeMethod do
|
|
19
19
|
end
|
20
20
|
|
21
21
|
it 'does count all occurences' do
|
22
|
-
src = <<-
|
22
|
+
src = <<-RUBY
|
23
23
|
class Alfa
|
24
24
|
def bravo!
|
25
25
|
end
|
@@ -27,7 +27,7 @@ RSpec.describe Reek::SmellDetectors::MissingSafeMethod do
|
|
27
27
|
def charlie!
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
RUBY
|
31
31
|
|
32
32
|
expect(src).
|
33
33
|
to reek_of(:MissingSafeMethod, lines: [2], name: 'bravo!').
|
@@ -35,7 +35,7 @@ RSpec.describe Reek::SmellDetectors::MissingSafeMethod do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'reports nothing when method and bang counterpart exist' do
|
38
|
-
src = <<-
|
38
|
+
src = <<-RUBY
|
39
39
|
class Alfa
|
40
40
|
def bravo
|
41
41
|
end
|
@@ -43,19 +43,19 @@ RSpec.describe Reek::SmellDetectors::MissingSafeMethod do
|
|
43
43
|
def bravo!
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
RUBY
|
47
47
|
|
48
48
|
expect(src).not_to reek_of(:MissingSafeMethod)
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'does not report methods we excluded via comment' do
|
52
|
-
source = <<-
|
52
|
+
source = <<-RUBY
|
53
53
|
# :reek:MissingSafeMethod: { exclude: [ bravo! ] }
|
54
54
|
class Alfa
|
55
55
|
def bravo!
|
56
56
|
end
|
57
57
|
end
|
58
|
-
|
58
|
+
RUBY
|
59
59
|
|
60
60
|
expect(source).not_to reek_of(:MissingSafeMethod)
|
61
61
|
end
|
@@ -3,11 +3,11 @@ require_lib 'reek/smell_detectors/module_initialize'
|
|
3
3
|
|
4
4
|
RSpec.describe Reek::SmellDetectors::ModuleInitialize do
|
5
5
|
it 'reports the right values' do
|
6
|
-
src = <<-
|
6
|
+
src = <<-RUBY
|
7
7
|
module Alfa
|
8
8
|
def initialize; end
|
9
9
|
end
|
10
|
-
|
10
|
+
RUBY
|
11
11
|
|
12
12
|
expect(src).to reek_of(:ModuleInitialize,
|
13
13
|
lines: [1],
|
@@ -17,41 +17,41 @@ RSpec.describe Reek::SmellDetectors::ModuleInitialize do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'reports nothing for a method with a different name' do
|
20
|
-
src = <<-
|
20
|
+
src = <<-RUBY
|
21
21
|
module Alfa
|
22
22
|
def bravo; end
|
23
23
|
end
|
24
|
-
|
24
|
+
RUBY
|
25
25
|
|
26
26
|
expect(src).not_to reek_of(:ModuleInitialize)
|
27
27
|
end
|
28
28
|
|
29
29
|
it 'reports nothing for a method named initialize in a nested class' do
|
30
|
-
src = <<-
|
30
|
+
src = <<-RUBY
|
31
31
|
module Alfa
|
32
32
|
class Bravo
|
33
33
|
def initialize; end
|
34
34
|
end
|
35
35
|
end
|
36
|
-
|
36
|
+
RUBY
|
37
37
|
|
38
38
|
expect(src).not_to reek_of(:ModuleInitialize)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'reports nothing for a method named initialize in a nested struct' do
|
42
|
-
src = <<-
|
42
|
+
src = <<-RUBY
|
43
43
|
module Alfa
|
44
44
|
Bravo = Struct.new(:charlie) do
|
45
45
|
def initialize; end
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
48
|
+
RUBY
|
49
49
|
|
50
50
|
expect(src).not_to reek_of(:ModuleInitialize)
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'reports nothing for a method named initialize in a nested dynamic class' do
|
54
|
-
src = <<-
|
54
|
+
src = <<-RUBY
|
55
55
|
module Alfa
|
56
56
|
def self.bravo
|
57
57
|
Class.new do
|
@@ -59,18 +59,18 @@ RSpec.describe Reek::SmellDetectors::ModuleInitialize do
|
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
62
|
+
RUBY
|
63
63
|
|
64
64
|
expect(src).not_to reek_of(:ModuleInitialize)
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'can be disabled via comment' do
|
68
|
-
src = <<-
|
68
|
+
src = <<-RUBY
|
69
69
|
# :reek:ModuleInitialize
|
70
70
|
module Alfa
|
71
71
|
def initialize; end
|
72
72
|
end
|
73
|
-
|
73
|
+
RUBY
|
74
74
|
|
75
75
|
expect(src).not_to reek_of(:ModuleInitialize)
|
76
76
|
end
|
@@ -3,13 +3,13 @@ require_lib 'reek/smell_detectors/nested_iterators'
|
|
3
3
|
|
4
4
|
RSpec.describe Reek::SmellDetectors::NestedIterators do
|
5
5
|
it 'reports the right values' do
|
6
|
-
src = <<-
|
6
|
+
src = <<-RUBY
|
7
7
|
def alfa(bravo)
|
8
8
|
bravo.each do |charlie|
|
9
9
|
charlie.each { |delta| delta }
|
10
10
|
end
|
11
11
|
end
|
12
|
-
|
12
|
+
RUBY
|
13
13
|
|
14
14
|
expect(src).to reek_of(:NestedIterators,
|
15
15
|
lines: [3],
|
@@ -20,7 +20,7 @@ RSpec.describe Reek::SmellDetectors::NestedIterators do
|
|
20
20
|
end
|
21
21
|
|
22
22
|
it 'does count all occurences' do
|
23
|
-
src = <<-
|
23
|
+
src = <<-RUBY
|
24
24
|
def alfa
|
25
25
|
bravo.each do |charlie|
|
26
26
|
charlie.each { |delta| delta }
|
@@ -32,7 +32,7 @@ RSpec.describe Reek::SmellDetectors::NestedIterators do
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
35
|
+
RUBY
|
36
36
|
|
37
37
|
expect(src).
|
38
38
|
to reek_of(:NestedIterators, lines: [3], depth: 2).
|
@@ -45,62 +45,62 @@ RSpec.describe Reek::SmellDetectors::NestedIterators do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'reports no smells with one iterator' do
|
48
|
-
src = <<-
|
48
|
+
src = <<-RUBY
|
49
49
|
def alfa(bravo)
|
50
50
|
bravo.each { |charlie| charlie }
|
51
51
|
end
|
52
|
-
|
52
|
+
RUBY
|
53
53
|
|
54
54
|
expect(src).not_to reek_of(:NestedIterators)
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'does not report nested iterators for Object#tap' do
|
58
|
-
src = <<-
|
58
|
+
src = <<-RUBY
|
59
59
|
def alfa(bravo)
|
60
60
|
bravo.tap do |charlie|
|
61
61
|
charlie.each { |delta| delta }
|
62
62
|
end
|
63
63
|
end
|
64
|
-
|
64
|
+
RUBY
|
65
65
|
|
66
66
|
expect(src).not_to reek_of(:NestedIterators)
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'does not report method with successive iterators' do
|
70
|
-
src = <<-
|
70
|
+
src = <<-RUBY
|
71
71
|
def alfa
|
72
72
|
@bravo.each { |charlie| charlie }
|
73
73
|
@charlie.each { |delta| delta }
|
74
74
|
end
|
75
|
-
|
75
|
+
RUBY
|
76
76
|
|
77
77
|
expect(src).not_to reek_of(:NestedIterators)
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'does not report method with chained iterators' do
|
81
|
-
src = <<-
|
81
|
+
src = <<-RUBY
|
82
82
|
def alfa
|
83
83
|
bravo.sort_by { |charlie| charlie }.each { |delta| delta }
|
84
84
|
end
|
85
|
-
|
85
|
+
RUBY
|
86
86
|
|
87
87
|
expect(src).not_to reek_of(:NestedIterators)
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'detects an iterator with an empty block' do
|
91
|
-
src = <<-
|
91
|
+
src = <<-RUBY
|
92
92
|
def alfa
|
93
93
|
bravo do |charlie|
|
94
94
|
charlie { |delta| }
|
95
95
|
end
|
96
96
|
end
|
97
|
-
|
97
|
+
RUBY
|
98
98
|
|
99
99
|
expect(src).to reek_of(:NestedIterators)
|
100
100
|
end
|
101
101
|
|
102
102
|
it 'reports nesting inside iterator arguments' do
|
103
|
-
src = <<-
|
103
|
+
src = <<-RUBY
|
104
104
|
def alfa(bravo)
|
105
105
|
bravo(
|
106
106
|
charlie.each do |delta|
|
@@ -108,13 +108,13 @@ RSpec.describe Reek::SmellDetectors::NestedIterators do
|
|
108
108
|
end
|
109
109
|
)
|
110
110
|
end
|
111
|
-
|
111
|
+
RUBY
|
112
112
|
|
113
113
|
expect(src).to reek_of(:NestedIterators, depth: 2)
|
114
114
|
end
|
115
115
|
|
116
116
|
it 'reports the deepest level of nesting only' do
|
117
|
-
src = <<-
|
117
|
+
src = <<-RUBY
|
118
118
|
def alfa(bravo)
|
119
119
|
bravo.each do |charlie|
|
120
120
|
charlie.each do |delta|
|
@@ -122,7 +122,7 @@ RSpec.describe Reek::SmellDetectors::NestedIterators do
|
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
125
|
-
|
125
|
+
RUBY
|
126
126
|
|
127
127
|
expect(src).
|
128
128
|
to not_reek_of(:NestedIterators, depth: 2).
|
@@ -130,95 +130,95 @@ RSpec.describe Reek::SmellDetectors::NestedIterators do
|
|
130
130
|
end
|
131
131
|
|
132
132
|
it 'reports all lines on which nested iterators occur' do
|
133
|
-
source = <<-
|
133
|
+
source = <<-RUBY
|
134
134
|
def alfa
|
135
135
|
@bravo.each { |charlie| charlie.each { |delta| @echo.send } }
|
136
136
|
@foxtrot.each { |golf| golf.each { |hotel| @india.send } }
|
137
137
|
end
|
138
|
-
|
138
|
+
RUBY
|
139
139
|
|
140
140
|
expect(source).to reek_of(:NestedIterators, lines: [2, 3])
|
141
141
|
end
|
142
142
|
|
143
143
|
it 'handles the case where super receives a block' do
|
144
|
-
src = <<-
|
144
|
+
src = <<-RUBY
|
145
145
|
def alfa
|
146
146
|
super do |bravo|
|
147
147
|
bravo.each { |charlie| charlie }
|
148
148
|
end
|
149
149
|
end
|
150
|
-
|
150
|
+
RUBY
|
151
151
|
|
152
152
|
expect(src).to reek_of(:NestedIterators)
|
153
153
|
end
|
154
154
|
|
155
155
|
it 'handles the case where super receives a block and arguments' do
|
156
|
-
src = <<-
|
156
|
+
src = <<-RUBY
|
157
157
|
def alfa
|
158
158
|
super(delta) do |bravo|
|
159
159
|
bravo.each { |charlie| charlie }
|
160
160
|
end
|
161
161
|
end
|
162
|
-
|
162
|
+
RUBY
|
163
163
|
|
164
164
|
expect(src).to reek_of(:NestedIterators)
|
165
165
|
end
|
166
166
|
|
167
167
|
it 'does not count iterators without block arguments' do
|
168
|
-
src = <<-
|
168
|
+
src = <<-RUBY
|
169
169
|
def alfa
|
170
170
|
bravo do
|
171
171
|
charlie.each { |delta| delta }
|
172
172
|
end
|
173
173
|
end
|
174
|
-
|
174
|
+
RUBY
|
175
175
|
|
176
176
|
expect(src).not_to reek_of(:NestedIterators)
|
177
177
|
end
|
178
178
|
|
179
179
|
context 'when blocks are specified as lambdas' do
|
180
180
|
it 'does not report blocks that are not nested' do
|
181
|
-
src = <<-
|
181
|
+
src = <<-RUBY
|
182
182
|
def alfa
|
183
183
|
bravo ->(charlie) { delta }
|
184
184
|
end
|
185
|
-
|
185
|
+
RUBY
|
186
186
|
|
187
187
|
expect(src).not_to reek_of(:NestedIterators)
|
188
188
|
end
|
189
189
|
|
190
190
|
it 'reports blocks that are nested' do
|
191
|
-
src = <<-
|
191
|
+
src = <<-RUBY
|
192
192
|
def alfa
|
193
193
|
bravo ->(charlie) do
|
194
194
|
delta ->(echo) { echo }
|
195
195
|
end
|
196
196
|
end
|
197
|
-
|
197
|
+
RUBY
|
198
198
|
|
199
199
|
expect(src).to reek_of(:NestedIterators)
|
200
200
|
end
|
201
201
|
end
|
202
202
|
|
203
203
|
it 'reports nested iterators called via safe navigation' do
|
204
|
-
src = <<-
|
204
|
+
src = <<-RUBY
|
205
205
|
def alfa(bravo)
|
206
206
|
bravo&.each do |charlie|
|
207
207
|
charlie&.each { |delta| delta }
|
208
208
|
end
|
209
209
|
end
|
210
|
-
|
210
|
+
RUBY
|
211
211
|
|
212
212
|
expect(src).to reek_of(:NestedIterators)
|
213
213
|
end
|
214
214
|
|
215
215
|
it 'does not report unnested iterators called via safe navigation' do
|
216
|
-
src = <<-
|
216
|
+
src = <<-RUBY
|
217
217
|
def alfa(bravo)
|
218
218
|
bravo&.each { |charlie| charlie }
|
219
219
|
delta&.each { |echo| echo }
|
220
220
|
end
|
221
|
-
|
221
|
+
RUBY
|
222
222
|
|
223
223
|
expect(src).not_to reek_of(:NestedIterators)
|
224
224
|
end
|
@@ -229,7 +229,7 @@ RSpec.describe Reek::SmellDetectors::NestedIterators do
|
|
229
229
|
end
|
230
230
|
|
231
231
|
it 'does not report nested iterators 3 levels deep' do
|
232
|
-
src = <<-
|
232
|
+
src = <<-RUBY
|
233
233
|
def alfa(bravo)
|
234
234
|
bravo.each do |charlie|
|
235
235
|
charlie.each do |delta|
|
@@ -237,13 +237,13 @@ RSpec.describe Reek::SmellDetectors::NestedIterators do
|
|
237
237
|
end
|
238
238
|
end
|
239
239
|
end
|
240
|
-
|
240
|
+
RUBY
|
241
241
|
|
242
242
|
expect(src).not_to reek_of(:NestedIterators).with_config(config)
|
243
243
|
end
|
244
244
|
|
245
245
|
it 'reports nested iterators 4 levels deep' do
|
246
|
-
src = <<-
|
246
|
+
src = <<-RUBY
|
247
247
|
def alfa(bravo)
|
248
248
|
bravo.each do |charlie|
|
249
249
|
charlie.each do |delta|
|
@@ -253,7 +253,7 @@ RSpec.describe Reek::SmellDetectors::NestedIterators do
|
|
253
253
|
end
|
254
254
|
end
|
255
255
|
end
|
256
|
-
|
256
|
+
RUBY
|
257
257
|
|
258
258
|
expect(src).to reek_of(:NestedIterators).with_config(config)
|
259
259
|
end
|
@@ -265,31 +265,31 @@ RSpec.describe Reek::SmellDetectors::NestedIterators do
|
|
265
265
|
end
|
266
266
|
|
267
267
|
it 'does not report when nesting the ignored iterator inside another' do
|
268
|
-
src = <<-
|
268
|
+
src = <<-RUBY
|
269
269
|
def alfa(bravo)
|
270
270
|
bravo.each do |charlie|
|
271
271
|
charlie.ignore_me { |delta| delta }
|
272
272
|
end
|
273
273
|
end
|
274
|
-
|
274
|
+
RUBY
|
275
275
|
|
276
276
|
expect(src).not_to reek_of(:NestedIterators).with_config(config)
|
277
277
|
end
|
278
278
|
|
279
279
|
it 'does not report a nested iterator inside the ignored iterator' do
|
280
|
-
src = <<-
|
280
|
+
src = <<-RUBY
|
281
281
|
def alfa(bravo)
|
282
282
|
bravo.ignore_me do |charlie|
|
283
283
|
charlie.each { |delta| delta }
|
284
284
|
end
|
285
285
|
end
|
286
|
-
|
286
|
+
RUBY
|
287
287
|
|
288
288
|
expect(src).not_to reek_of(:NestedIterators).with_config(config)
|
289
289
|
end
|
290
290
|
|
291
291
|
it 'reports nested iterators inside the ignored iterator' do
|
292
|
-
src = <<-
|
292
|
+
src = <<-RUBY
|
293
293
|
def alfa(bravo)
|
294
294
|
bravo.ignore_me do |charlie|
|
295
295
|
charlie.each do |delta|
|
@@ -297,13 +297,13 @@ RSpec.describe Reek::SmellDetectors::NestedIterators do
|
|
297
297
|
end
|
298
298
|
end
|
299
299
|
end
|
300
|
-
|
300
|
+
RUBY
|
301
301
|
|
302
302
|
expect(src).to reek_of(:NestedIterators, depth: 2).with_config(config)
|
303
303
|
end
|
304
304
|
|
305
305
|
it 'reports nested iterators outside the ignored iterator' do
|
306
|
-
src = <<-
|
306
|
+
src = <<-RUBY
|
307
307
|
def alfa(bravo)
|
308
308
|
bravo.each do |charlie|
|
309
309
|
charlie.each do |delta|
|
@@ -311,13 +311,13 @@ RSpec.describe Reek::SmellDetectors::NestedIterators do
|
|
311
311
|
end
|
312
312
|
end
|
313
313
|
end
|
314
|
-
|
314
|
+
RUBY
|
315
315
|
|
316
316
|
expect(src).to reek_of(:NestedIterators, depth: 2).with_config(config)
|
317
317
|
end
|
318
318
|
|
319
319
|
it 'reports nested iterators with the ignored iterator between them' do
|
320
|
-
src = <<-
|
320
|
+
src = <<-RUBY
|
321
321
|
def alfa(bravo)
|
322
322
|
bravo.each do |charlie|
|
323
323
|
charlie.ignore_me do |delta|
|
@@ -325,7 +325,7 @@ RSpec.describe Reek::SmellDetectors::NestedIterators do
|
|
325
325
|
end
|
326
326
|
end
|
327
327
|
end
|
328
|
-
|
328
|
+
RUBY
|
329
329
|
|
330
330
|
expect(src).to reek_of(:NestedIterators, depth: 2).with_config(config)
|
331
331
|
end
|