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,11 +3,11 @@ require_lib 'reek/smell_detectors/nil_check'
|
|
3
3
|
|
4
4
|
RSpec.describe Reek::SmellDetectors::NilCheck do
|
5
5
|
it 'reports the right values' do
|
6
|
-
src = <<-
|
6
|
+
src = <<-RUBY
|
7
7
|
def alfa(bravo)
|
8
8
|
bravo.nil?
|
9
9
|
end
|
10
|
-
|
10
|
+
RUBY
|
11
11
|
|
12
12
|
expect(src).to reek_of(:NilCheck,
|
13
13
|
lines: [2],
|
@@ -17,12 +17,12 @@ RSpec.describe Reek::SmellDetectors::NilCheck do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'does count all occurences' do
|
20
|
-
src = <<-
|
20
|
+
src = <<-RUBY
|
21
21
|
def alfa(bravo, charlie)
|
22
22
|
bravo.nil?
|
23
23
|
charlie.nil?
|
24
24
|
end
|
25
|
-
|
25
|
+
RUBY
|
26
26
|
|
27
27
|
expect(src).to reek_of(:NilCheck,
|
28
28
|
lines: [2, 3],
|
@@ -35,65 +35,65 @@ RSpec.describe Reek::SmellDetectors::NilCheck do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'reports when scope uses == nil' do
|
38
|
-
src = <<-
|
38
|
+
src = <<-RUBY
|
39
39
|
def alfa(bravo)
|
40
40
|
bravo == nil
|
41
41
|
end
|
42
|
-
|
42
|
+
RUBY
|
43
43
|
|
44
44
|
expect(src).to reek_of(:NilCheck)
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'reports when scope uses === nil' do
|
48
|
-
src = <<-
|
48
|
+
src = <<-RUBY
|
49
49
|
def alfa(bravo)
|
50
50
|
bravo === nil
|
51
51
|
end
|
52
|
-
|
52
|
+
RUBY
|
53
53
|
|
54
54
|
expect(src).to reek_of(:NilCheck)
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'reports when scope uses nil ==' do
|
58
|
-
src = <<-
|
58
|
+
src = <<-RUBY
|
59
59
|
def alfa(bravo)
|
60
60
|
nil == bravo
|
61
61
|
end
|
62
|
-
|
62
|
+
RUBY
|
63
63
|
|
64
64
|
expect(src).to reek_of(:NilCheck)
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'reports when scope uses a case-clause checking nil' do
|
68
|
-
src = <<-
|
68
|
+
src = <<-RUBY
|
69
69
|
def alfa(bravo)
|
70
70
|
case bravo
|
71
71
|
when nil then puts "Nil"
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
74
|
+
RUBY
|
75
75
|
|
76
76
|
expect(src).to reek_of(:NilCheck)
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'reports when scope uses &.' do
|
80
|
-
src = <<-
|
80
|
+
src = <<-RUBY
|
81
81
|
def alfa(bravo)
|
82
82
|
bravo&.charlie
|
83
83
|
end
|
84
|
-
|
84
|
+
RUBY
|
85
85
|
|
86
86
|
expect(src).to reek_of(:NilCheck)
|
87
87
|
end
|
88
88
|
|
89
89
|
it 'reports all lines when scope uses multiple nilchecks' do
|
90
|
-
src = <<-
|
90
|
+
src = <<-RUBY
|
91
91
|
def alfa(bravo)
|
92
92
|
bravo.nil?
|
93
93
|
@charlie === nil
|
94
94
|
delta&.echo
|
95
95
|
end
|
96
|
-
|
96
|
+
RUBY
|
97
97
|
|
98
98
|
expect(src).to reek_of(:NilCheck, lines: [2, 3, 4])
|
99
99
|
end
|
@@ -3,7 +3,7 @@ require_lib 'reek/smell_detectors/repeated_conditional'
|
|
3
3
|
|
4
4
|
RSpec.describe Reek::SmellDetectors::RepeatedConditional do
|
5
5
|
it 'reports the right values' do
|
6
|
-
src = <<-
|
6
|
+
src = <<-RUBY
|
7
7
|
class Alfa
|
8
8
|
attr_accessor :bravo
|
9
9
|
|
@@ -19,7 +19,7 @@ RSpec.describe Reek::SmellDetectors::RepeatedConditional do
|
|
19
19
|
puts "Repeat 3!" if bravo
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
RUBY
|
23
23
|
|
24
24
|
expect(src).to reek_of(:RepeatedConditional,
|
25
25
|
lines: [5, 9, 13],
|
@@ -31,7 +31,7 @@ RSpec.describe Reek::SmellDetectors::RepeatedConditional do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'does count all occurences' do
|
34
|
-
src = <<-
|
34
|
+
src = <<-RUBY
|
35
35
|
class Alfa
|
36
36
|
attr_accessor :bravo
|
37
37
|
|
@@ -48,7 +48,7 @@ RSpec.describe Reek::SmellDetectors::RepeatedConditional do
|
|
48
48
|
puts "Repeat 3!" if bravo
|
49
49
|
end
|
50
50
|
end
|
51
|
-
|
51
|
+
RUBY
|
52
52
|
|
53
53
|
expect(src).to reek_of(:RepeatedConditional,
|
54
54
|
lines: [5, 6, 10, 14],
|
@@ -56,7 +56,7 @@ RSpec.describe Reek::SmellDetectors::RepeatedConditional do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'does not report two repeated conditionals' do
|
59
|
-
src = <<-
|
59
|
+
src = <<-RUBY
|
60
60
|
class Alfa
|
61
61
|
attr_accessor :bravo
|
62
62
|
|
@@ -68,13 +68,13 @@ RSpec.describe Reek::SmellDetectors::RepeatedConditional do
|
|
68
68
|
puts "Repeat 2!" if bravo
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
71
|
+
RUBY
|
72
72
|
|
73
73
|
expect(src).not_to reek_of(:RepeatedConditional)
|
74
74
|
end
|
75
75
|
|
76
76
|
it 'reports repeated conditionals regardless of `if` or `case` statements' do
|
77
|
-
src = <<-
|
77
|
+
src = <<-RUBY
|
78
78
|
class Alfa
|
79
79
|
attr_accessor :bravo
|
80
80
|
|
@@ -93,7 +93,7 @@ RSpec.describe Reek::SmellDetectors::RepeatedConditional do
|
|
93
93
|
puts "Repeat 3!" if bravo
|
94
94
|
end
|
95
95
|
end
|
96
|
-
|
96
|
+
RUBY
|
97
97
|
|
98
98
|
expect(src).to reek_of(:RepeatedConditional)
|
99
99
|
end
|
@@ -3,10 +3,10 @@ require_lib 'reek/smell_detectors/subclassed_from_core_class'
|
|
3
3
|
|
4
4
|
RSpec.describe Reek::SmellDetectors::SubclassedFromCoreClass do
|
5
5
|
it 'reports the right values' do
|
6
|
-
src = <<-
|
6
|
+
src = <<-RUBY
|
7
7
|
class Alfa < Hash
|
8
8
|
end
|
9
|
-
|
9
|
+
RUBY
|
10
10
|
|
11
11
|
expect(src).to reek_of(:SubclassedFromCoreClass,
|
12
12
|
lines: [1],
|
@@ -17,40 +17,40 @@ RSpec.describe Reek::SmellDetectors::SubclassedFromCoreClass do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'reports when inheriting from a core class inside a module' do
|
20
|
-
src = <<-
|
20
|
+
src = <<-RUBY
|
21
21
|
module Alfa
|
22
22
|
class Bravo < Hash
|
23
23
|
end
|
24
24
|
end
|
25
|
-
|
25
|
+
RUBY
|
26
26
|
|
27
27
|
expect(src).to reek_of(:SubclassedFromCoreClass, context: 'Alfa::Bravo')
|
28
28
|
end
|
29
29
|
|
30
30
|
it 'does not report when not inheriting from a core class' do
|
31
|
-
src = <<-
|
31
|
+
src = <<-RUBY
|
32
32
|
class Alfa
|
33
33
|
end
|
34
|
-
|
34
|
+
RUBY
|
35
35
|
|
36
36
|
expect(src).not_to reek_of(:SubclassedFromCoreClass)
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'does not report on coincidental core class names in other namespaces' do
|
40
|
-
src = <<-
|
40
|
+
src = <<-RUBY
|
41
41
|
class Alfa < Bravo::Array
|
42
42
|
end
|
43
|
-
|
43
|
+
RUBY
|
44
44
|
|
45
45
|
expect(src).not_to reek_of(:SubclassedFromCoreClass)
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'reports if inner class inherit from a core class' do
|
49
|
-
src = <<-
|
49
|
+
src = <<-RUBY
|
50
50
|
class Alfa
|
51
51
|
Bravo = Class.new(Array)
|
52
52
|
end
|
53
|
-
|
53
|
+
RUBY
|
54
54
|
|
55
55
|
expect(src).to reek_of(:SubclassedFromCoreClass, context: 'Alfa::Bravo')
|
56
56
|
end
|
@@ -7,11 +7,11 @@ RSpec.describe Reek::SmellDetectors::TooManyConstants do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'reports the right values' do
|
10
|
-
src = <<-
|
10
|
+
src = <<-RUBY
|
11
11
|
class Alfa
|
12
12
|
Bravo = Charlie = Delta = 1
|
13
13
|
end
|
14
|
-
|
14
|
+
RUBY
|
15
15
|
|
16
16
|
expect(src).to reek_of(:TooManyConstants,
|
17
17
|
lines: [1],
|
@@ -22,61 +22,61 @@ RSpec.describe Reek::SmellDetectors::TooManyConstants do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
it 'does not report for non-excessive constants' do
|
25
|
-
src = <<-
|
25
|
+
src = <<-RUBY
|
26
26
|
class Alfa
|
27
27
|
Bravo = Charlie = 1
|
28
28
|
end
|
29
|
-
|
29
|
+
RUBY
|
30
30
|
|
31
31
|
expect(src).not_to reek_of(:TooManyConstants).with_config(config)
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'does not report when increasing default' do
|
35
|
-
src = <<-
|
35
|
+
src = <<-RUBY
|
36
36
|
# :reek:TooManyConstants { max_constants: 3 }
|
37
37
|
class Alfa
|
38
38
|
Bravo = Charlie = Delta = 1
|
39
39
|
end
|
40
|
-
|
40
|
+
RUBY
|
41
41
|
|
42
42
|
expect(src).not_to reek_of(:TooManyConstants).with_config(config)
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'does not report when disabled' do
|
46
|
-
src = <<-
|
46
|
+
src = <<-RUBY
|
47
47
|
# :reek:TooManyConstants { enabled: false }
|
48
48
|
class Alfa
|
49
49
|
Bravo = Charlie = Delta = 1
|
50
50
|
end
|
51
|
-
|
51
|
+
RUBY
|
52
52
|
|
53
53
|
expect(src).not_to reek_of(:TooManyConstants).with_config(config)
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'does not account class definition' do
|
57
|
-
src = <<-
|
57
|
+
src = <<-RUBY
|
58
58
|
class Alfa
|
59
59
|
Bravo = Charlie = 1
|
60
60
|
Delta = Class.new(StandardError)
|
61
61
|
end
|
62
|
-
|
62
|
+
RUBY
|
63
63
|
|
64
64
|
expect(src).not_to reek_of(:TooManyConstants).with_config(config)
|
65
65
|
end
|
66
66
|
|
67
67
|
it 'does not account struct definition' do
|
68
|
-
src = <<-
|
68
|
+
src = <<-RUBY
|
69
69
|
class Alfa
|
70
70
|
Bravo = Charlie = 1
|
71
71
|
Delta = Struct.new
|
72
72
|
end
|
73
|
-
|
73
|
+
RUBY
|
74
74
|
|
75
75
|
expect(src).not_to reek_of(:TooManyConstants).with_config(config)
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'counts each constant only once' do
|
79
|
-
src = <<-
|
79
|
+
src = <<-RUBY
|
80
80
|
class Alfa
|
81
81
|
Bravo = Charlie = 1
|
82
82
|
end
|
@@ -88,26 +88,26 @@ RSpec.describe Reek::SmellDetectors::TooManyConstants do
|
|
88
88
|
class Golf
|
89
89
|
Hotel = India = 1
|
90
90
|
end
|
91
|
-
|
91
|
+
RUBY
|
92
92
|
|
93
93
|
expect(src).not_to reek_of(:TooManyConstants).with_config(config)
|
94
94
|
end
|
95
95
|
|
96
96
|
it 'does not report outer module when inner module suppressed' do
|
97
|
-
src = <<-
|
97
|
+
src = <<-RUBY
|
98
98
|
module Alfa
|
99
99
|
# ignore :reek:TooManyConstants
|
100
100
|
module Bravo
|
101
101
|
Charlie = Delta = Echo = 1
|
102
102
|
end
|
103
103
|
end
|
104
|
-
|
104
|
+
RUBY
|
105
105
|
|
106
106
|
expect(src).not_to reek_of(:TooManyConstants).with_config(config)
|
107
107
|
end
|
108
108
|
|
109
109
|
it 'counts each constant only once for each namespace' do
|
110
|
-
src = <<-
|
110
|
+
src = <<-RUBY
|
111
111
|
module Alfa
|
112
112
|
Bravo = Charlie = 1
|
113
113
|
|
@@ -115,29 +115,29 @@ RSpec.describe Reek::SmellDetectors::TooManyConstants do
|
|
115
115
|
Echo = 1
|
116
116
|
end
|
117
117
|
end
|
118
|
-
|
118
|
+
RUBY
|
119
119
|
|
120
120
|
expect(src).not_to reek_of(:TooManyConstants).with_config(config)
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'reports for excessive constants inside a module' do
|
124
|
-
src = <<-
|
124
|
+
src = <<-RUBY
|
125
125
|
module Alfa
|
126
126
|
Bravo = Charlie = Delta = 1
|
127
127
|
end
|
128
|
-
|
128
|
+
RUBY
|
129
129
|
|
130
130
|
expect(src).to reek_of(:TooManyConstants, context: 'Alfa').with_config(config)
|
131
131
|
end
|
132
132
|
|
133
133
|
it 'reports the full class name' do
|
134
|
-
src = <<-
|
134
|
+
src = <<-RUBY
|
135
135
|
module Alfa
|
136
136
|
class Bravo
|
137
137
|
Charlie = Delta = Echo = 1
|
138
138
|
end
|
139
139
|
end
|
140
|
-
|
140
|
+
RUBY
|
141
141
|
|
142
142
|
expect(src).to reek_of(:TooManyConstants, context: 'Alfa::Bravo').with_config(config)
|
143
143
|
end
|
@@ -7,13 +7,13 @@ RSpec.describe Reek::SmellDetectors::TooManyInstanceVariables do
|
|
7
7
|
end
|
8
8
|
|
9
9
|
it 'reports the right values' do
|
10
|
-
src = <<-
|
10
|
+
src = <<-RUBY
|
11
11
|
class Alfa
|
12
12
|
def bravo
|
13
13
|
@charlie = @delta = @echo = 1
|
14
14
|
end
|
15
15
|
end
|
16
|
-
|
16
|
+
RUBY
|
17
17
|
|
18
18
|
expect(src).to reek_of(:TooManyInstanceVariables,
|
19
19
|
lines: [1],
|
@@ -24,58 +24,58 @@ RSpec.describe Reek::SmellDetectors::TooManyInstanceVariables do
|
|
24
24
|
end
|
25
25
|
|
26
26
|
it 'does not report for non-excessive ivars' do
|
27
|
-
src = <<-
|
27
|
+
src = <<-RUBY
|
28
28
|
class Alfa
|
29
29
|
def bravo
|
30
30
|
@charlie = @delta = 1
|
31
31
|
end
|
32
32
|
end
|
33
|
-
|
33
|
+
RUBY
|
34
34
|
|
35
35
|
expect(src).not_to reek_of(:TooManyInstanceVariables).with_config(config)
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'has a configurable maximum' do
|
39
|
-
src = <<-
|
39
|
+
src = <<-RUBY
|
40
40
|
# :reek:TooManyInstanceVariables { max_instance_variables: 3 }
|
41
41
|
class Alfa
|
42
42
|
def bravo
|
43
43
|
@charlie = @delta = @echo = 1
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
RUBY
|
47
47
|
|
48
48
|
expect(src).not_to reek_of(:TooManyInstanceVariables).with_config(config)
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'counts each ivar only once' do
|
52
|
-
src = <<-
|
52
|
+
src = <<-RUBY
|
53
53
|
class Alfa
|
54
54
|
def bravo
|
55
55
|
@charlie = @delta = 1
|
56
56
|
@charlie = @delta = 1
|
57
57
|
end
|
58
58
|
end
|
59
|
-
|
59
|
+
RUBY
|
60
60
|
|
61
61
|
expect(src).not_to reek_of(:TooManyInstanceVariables).with_config(config)
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'does not report memoized bravo' do
|
65
|
-
src = <<-
|
65
|
+
src = <<-RUBY
|
66
66
|
class Alfa
|
67
67
|
def bravo
|
68
68
|
@charlie = @delta = 1
|
69
69
|
@echo ||= 1
|
70
70
|
end
|
71
71
|
end
|
72
|
-
|
72
|
+
RUBY
|
73
73
|
|
74
74
|
expect(src).not_to reek_of(:TooManyInstanceVariables).with_config(config)
|
75
75
|
end
|
76
76
|
|
77
77
|
it 'does not count ivars across inner classes' do
|
78
|
-
src = <<-
|
78
|
+
src = <<-RUBY
|
79
79
|
class Alfa
|
80
80
|
class Bravo
|
81
81
|
def charlie
|
@@ -89,13 +89,13 @@ RSpec.describe Reek::SmellDetectors::TooManyInstanceVariables do
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
end
|
92
|
-
|
92
|
+
RUBY
|
93
93
|
|
94
94
|
expect(src).not_to reek_of(:TooManyInstanceVariables).with_config(config)
|
95
95
|
end
|
96
96
|
|
97
97
|
it 'does not count ivars across inner modules and classes' do
|
98
|
-
src = <<-
|
98
|
+
src = <<-RUBY
|
99
99
|
class Alfa
|
100
100
|
class Bravo
|
101
101
|
def charlie
|
@@ -109,13 +109,13 @@ RSpec.describe Reek::SmellDetectors::TooManyInstanceVariables do
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
end
|
112
|
-
|
112
|
+
RUBY
|
113
113
|
|
114
114
|
expect(src).not_to reek_of(:TooManyInstanceVariables).with_config(config)
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'reports excessive ivars across different methods' do
|
118
|
-
src = <<-
|
118
|
+
src = <<-RUBY
|
119
119
|
class Alfa
|
120
120
|
def bravo
|
121
121
|
@charlie = @delta = 1
|
@@ -125,7 +125,7 @@ RSpec.describe Reek::SmellDetectors::TooManyInstanceVariables do
|
|
125
125
|
@hotel = 1
|
126
126
|
end
|
127
127
|
end
|
128
|
-
|
128
|
+
RUBY
|
129
129
|
|
130
130
|
expect(src).to reek_of(:TooManyInstanceVariables).with_config(config)
|
131
131
|
end
|