reek 1.3.8 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +11 -0
- data/README.md +22 -14
- data/Rakefile +2 -15
- data/assets/html_output.html.erb +103 -0
- data/features/command_line_interface/options.feature +3 -0
- data/features/command_line_interface/smell_selection.feature +19 -0
- data/features/rake_task/rake_task.feature +1 -1
- data/features/reports/reports.feature +16 -0
- data/features/reports/yaml.feature +26 -23
- data/features/samples.feature +2 -1
- data/features/step_definitions/reek_steps.rb +15 -15
- data/features/support/env.rb +7 -9
- data/lib/reek/cli/application.rb +2 -4
- data/lib/reek/cli/command.rb +12 -0
- data/lib/reek/cli/help_command.rb +3 -6
- data/lib/reek/cli/options.rb +147 -0
- data/lib/reek/cli/reek_command.rb +18 -14
- data/lib/reek/cli/report/formatter.rb +56 -0
- data/lib/reek/cli/report/report.rb +106 -0
- data/lib/reek/cli/report/strategy.rb +63 -0
- data/lib/reek/cli/version_command.rb +3 -6
- data/lib/reek/config_file_exception.rb +0 -1
- data/lib/reek/core/code_context.rb +1 -3
- data/lib/reek/core/code_parser.rb +13 -12
- data/lib/reek/core/method_context.rb +13 -2
- data/lib/reek/core/module_context.rb +0 -4
- data/lib/reek/core/object_refs.rb +2 -3
- data/lib/reek/core/singleton_method_context.rb +0 -2
- data/lib/reek/core/smell_configuration.rb +3 -5
- data/lib/reek/core/smell_repository.rb +7 -8
- data/lib/reek/core/sniffer.rb +4 -10
- data/lib/reek/core/stop_context.rb +2 -4
- data/lib/reek/core/warning_collector.rb +0 -1
- data/lib/reek/examiner.rb +19 -17
- data/lib/reek/rake/task.rb +7 -10
- data/lib/reek/smell_warning.rb +4 -8
- data/lib/reek/smells.rb +0 -1
- data/lib/reek/smells/attribute.rb +8 -11
- data/lib/reek/smells/boolean_parameter.rb +5 -7
- data/lib/reek/smells/class_variable.rb +6 -7
- data/lib/reek/smells/control_parameter.rb +78 -45
- data/lib/reek/smells/data_clump.rb +13 -16
- data/lib/reek/smells/duplicate_method_call.rb +13 -11
- data/lib/reek/smells/feature_envy.rb +6 -7
- data/lib/reek/smells/irresponsible_module.rb +4 -6
- data/lib/reek/smells/long_parameter_list.rb +5 -7
- data/lib/reek/smells/long_yield_list.rb +2 -4
- data/lib/reek/smells/nested_iterators.rb +12 -22
- data/lib/reek/smells/nil_check.rb +35 -46
- data/lib/reek/smells/prima_donna_method.rb +24 -16
- data/lib/reek/smells/repeated_conditional.rb +8 -10
- data/lib/reek/smells/smell_detector.rb +9 -7
- data/lib/reek/smells/too_many_instance_variables.rb +7 -9
- data/lib/reek/smells/too_many_methods.rb +6 -8
- data/lib/reek/smells/too_many_statements.rb +4 -6
- data/lib/reek/smells/uncommunicative_method_name.rb +5 -7
- data/lib/reek/smells/uncommunicative_module_name.rb +5 -7
- data/lib/reek/smells/uncommunicative_parameter_name.rb +7 -9
- data/lib/reek/smells/uncommunicative_variable_name.rb +15 -18
- data/lib/reek/smells/unused_parameters.rb +5 -45
- data/lib/reek/smells/utility_function.rb +9 -10
- data/lib/reek/source.rb +0 -1
- data/lib/reek/source/code_comment.rb +7 -8
- data/lib/reek/source/config_file.rb +2 -4
- data/lib/reek/source/core_extras.rb +1 -1
- data/lib/reek/source/reference_collector.rb +1 -2
- data/lib/reek/source/sexp_extensions.rb +93 -10
- data/lib/reek/source/sexp_formatter.rb +2 -3
- data/lib/reek/source/sexp_node.rb +19 -15
- data/lib/reek/source/source_code.rb +4 -14
- data/lib/reek/source/source_file.rb +3 -5
- data/lib/reek/source/source_locator.rb +5 -6
- data/lib/reek/source/source_repository.rb +3 -3
- data/lib/reek/source/tree_dresser.rb +2 -2
- data/lib/reek/spec.rb +1 -2
- data/lib/reek/spec/should_reek.rb +8 -5
- data/lib/reek/spec/should_reek_of.rb +6 -4
- data/lib/reek/spec/should_reek_only_of.rb +10 -6
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +34 -30
- data/spec/gem/updates_spec.rb +3 -4
- data/spec/gem/yard_spec.rb +1 -2
- data/spec/matchers/smell_of_matcher.rb +12 -14
- data/spec/quality/reek_source_spec.rb +42 -0
- data/spec/reek/cli/help_command_spec.rb +7 -5
- data/spec/reek/cli/report_spec.rb +89 -22
- data/spec/reek/cli/version_command_spec.rb +8 -6
- data/spec/reek/core/code_context_spec.rb +25 -26
- data/spec/reek/core/code_parser_spec.rb +6 -6
- data/spec/reek/core/method_context_spec.rb +18 -18
- data/spec/reek/core/module_context_spec.rb +5 -5
- data/spec/reek/core/object_refs_spec.rb +21 -22
- data/spec/reek/core/smell_configuration_spec.rb +22 -21
- data/spec/reek/core/stop_context_spec.rb +2 -2
- data/spec/reek/core/warning_collector_spec.rb +3 -3
- data/spec/reek/examiner_spec.rb +9 -9
- data/spec/reek/smell_warning_spec.rb +29 -29
- data/spec/reek/smells/attribute_spec.rb +6 -6
- data/spec/reek/smells/behaves_like_variable_detector.rb +6 -6
- data/spec/reek/smells/boolean_parameter_spec.rb +17 -17
- data/spec/reek/smells/class_variable_spec.rb +9 -9
- data/spec/reek/smells/control_parameter_spec.rb +161 -137
- data/spec/reek/smells/data_clump_spec.rb +22 -19
- data/spec/reek/smells/duplicate_method_call_spec.rb +71 -27
- data/spec/reek/smells/feature_envy_spec.rb +32 -32
- data/spec/reek/smells/irresponsible_module_spec.rb +21 -21
- data/spec/reek/smells/long_parameter_list_spec.rb +14 -14
- data/spec/reek/smells/long_yield_list_spec.rb +6 -6
- data/spec/reek/smells/nested_iterators_spec.rb +21 -21
- data/spec/reek/smells/nil_check_spec.rb +23 -15
- data/spec/reek/smells/prima_donna_method_spec.rb +5 -5
- data/spec/reek/smells/repeated_conditional_spec.rb +14 -14
- data/spec/reek/smells/smell_detector_shared.rb +9 -9
- data/spec/reek/smells/too_many_instance_variables_spec.rb +12 -12
- data/spec/reek/smells/too_many_methods_spec.rb +10 -10
- data/spec/reek/smells/too_many_statements_spec.rb +41 -41
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +4 -4
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +12 -12
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +21 -21
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +49 -49
- data/spec/reek/smells/unused_parameters_spec.rb +26 -16
- data/spec/reek/smells/utility_function_spec.rb +20 -20
- data/spec/reek/source/code_comment_spec.rb +37 -37
- data/spec/reek/source/object_source_spec.rb +5 -5
- data/spec/reek/source/reference_collector_spec.rb +9 -9
- data/spec/reek/source/sexp_extensions_spec.rb +73 -52
- data/spec/reek/source/sexp_formatter_spec.rb +3 -4
- data/spec/reek/source/sexp_node_spec.rb +3 -3
- data/spec/reek/source/source_code_spec.rb +16 -15
- data/spec/reek/source/tree_dresser_spec.rb +2 -2
- data/spec/reek/spec/should_reek_of_spec.rb +11 -11
- data/spec/reek/spec/should_reek_only_of_spec.rb +11 -11
- data/spec/reek/spec/should_reek_spec.rb +11 -11
- data/spec/samples/one_smelly_file/dirty.rb +3 -0
- data/spec/spec_helper.rb +0 -6
- data/tasks/develop.rake +8 -16
- data/tasks/reek.rake +5 -13
- data/tasks/test.rake +5 -22
- metadata +56 -34
- data/lib/reek/cli/command_line.rb +0 -126
- data/lib/reek/cli/report.rb +0 -138
@@ -15,54 +15,54 @@ describe UncommunicativeParameterName do
|
|
15
15
|
it_should_behave_like 'SmellDetector'
|
16
16
|
|
17
17
|
{ 'obj.' => 'with a receiveer',
|
18
|
-
'' => 'without a receiver'}.each do |host, description|
|
18
|
+
'' => 'without a receiver' }.each do |host, description|
|
19
19
|
context "in a method definition #{description}" do
|
20
20
|
it 'does not recognise *' do
|
21
|
-
"def #{host}help(xray, *) basics(17) end".
|
22
|
-
|
21
|
+
expect("def #{host}help(xray, *) basics(17) end").
|
22
|
+
not_to smell_of(UncommunicativeParameterName)
|
23
23
|
end
|
24
24
|
|
25
25
|
it "reports parameter's name" do
|
26
26
|
src = "def #{host}help(x) basics(x) end"
|
27
|
-
src.
|
28
|
-
|
27
|
+
expect(src).to smell_of(UncommunicativeParameterName,
|
28
|
+
UncommunicativeParameterName::PARAMETER_NAME_KEY => 'x')
|
29
29
|
end
|
30
30
|
|
31
|
-
it
|
31
|
+
it 'does not report unused parameters' do
|
32
32
|
src = "def #{host}help(x) basics(17) end"
|
33
|
-
src.
|
33
|
+
expect(src).not_to smell_of(UncommunicativeParameterName)
|
34
34
|
end
|
35
35
|
|
36
36
|
it 'does not report two-letter parameter names' do
|
37
|
-
"def #{host}help(ab) basics(ab) end".
|
38
|
-
|
37
|
+
expect("def #{host}help(ab) basics(ab) end").
|
38
|
+
not_to smell_of(UncommunicativeParameterName)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'reports names of the form "x2"' do
|
42
42
|
src = "def #{host}help(x2) basics(x2) end"
|
43
|
-
src.
|
44
|
-
|
43
|
+
expect(src).to smell_of(UncommunicativeParameterName,
|
44
|
+
UncommunicativeParameterName::PARAMETER_NAME_KEY => 'x2')
|
45
45
|
end
|
46
46
|
|
47
47
|
it 'reports long name ending in a number' do
|
48
48
|
src = "def #{host}help(param2) basics(param2) end"
|
49
|
-
src.
|
50
|
-
|
49
|
+
expect(src).to smell_of(UncommunicativeParameterName,
|
50
|
+
UncommunicativeParameterName::PARAMETER_NAME_KEY => 'param2')
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'does not report unused anonymous parameter' do
|
54
|
-
"def #{host}help(_) basics(17) end".
|
55
|
-
|
54
|
+
expect("def #{host}help(_) basics(17) end").
|
55
|
+
not_to smell_of(UncommunicativeParameterName)
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'reports used anonymous parameter' do
|
59
|
-
"def #{host}help(_) basics(_) end".
|
60
|
-
|
59
|
+
expect("def #{host}help(_) basics(_) end").
|
60
|
+
to smell_of(UncommunicativeParameterName)
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'reports used parameters marked as unused' do
|
64
|
-
"def #{host}help(_unused) basics(_unused) end".
|
65
|
-
|
64
|
+
expect("def #{host}help(_unused) basics(_unused) end").
|
65
|
+
to smell_of(UncommunicativeParameterName)
|
66
66
|
end
|
67
67
|
end
|
68
68
|
end
|
@@ -78,8 +78,8 @@ describe UncommunicativeParameterName do
|
|
78
78
|
it_should_behave_like 'common fields set correctly'
|
79
79
|
|
80
80
|
it 'reports the correct values' do
|
81
|
-
@warning.smell[UncommunicativeParameterName::PARAMETER_NAME_KEY].
|
82
|
-
@warning.lines.
|
81
|
+
expect(@warning.smell[UncommunicativeParameterName::PARAMETER_NAME_KEY]).to eq('bad2')
|
82
|
+
expect(@warning.lines).to eq([1])
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
@@ -15,61 +15,61 @@ describe UncommunicativeVariableName do
|
|
15
15
|
|
16
16
|
it_should_behave_like 'SmellDetector'
|
17
17
|
|
18
|
-
context
|
18
|
+
context 'field name' do
|
19
19
|
it 'does not report use of one-letter fieldname' do
|
20
20
|
src = 'class Thing; def simple(fred) @x end end'
|
21
|
-
src.
|
21
|
+
expect(src).not_to smell_of(UncommunicativeVariableName)
|
22
22
|
end
|
23
23
|
it 'reports one-letter fieldname in assignment' do
|
24
24
|
src = 'class Thing; def simple(fred) @x = fred end end'
|
25
|
-
src.
|
25
|
+
expect(src).to reek_of(:UncommunicativeVariableName, /@x/, /Thing/, /variable name/)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
context
|
29
|
+
context 'local variable name' do
|
30
30
|
it 'does not report one-word variable name' do
|
31
|
-
'def help(fred) simple = jim(45) end'.
|
31
|
+
expect('def help(fred) simple = jim(45) end').not_to smell_of(UncommunicativeVariableName)
|
32
32
|
end
|
33
33
|
it 'does not report single underscore as a variable name' do
|
34
|
-
'def help(fred) _ = jim(45) end'.
|
34
|
+
expect('def help(fred) _ = jim(45) end').not_to smell_of(UncommunicativeVariableName)
|
35
35
|
end
|
36
36
|
it 'reports one-letter variable name' do
|
37
37
|
src = 'def simple(fred) x = jim(45) end'
|
38
|
-
src.
|
39
|
-
|
38
|
+
expect(src).to smell_of(UncommunicativeVariableName,
|
39
|
+
UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x')
|
40
40
|
end
|
41
41
|
it 'reports name of the form "x2"' do
|
42
42
|
src = 'def simple(fred) x2 = jim(45) end'
|
43
|
-
src.
|
44
|
-
|
43
|
+
expect(src).to smell_of(UncommunicativeVariableName,
|
44
|
+
UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x2')
|
45
45
|
end
|
46
46
|
it 'reports long name ending in a number' do
|
47
47
|
@bad_var = 'var123'
|
48
48
|
src = "def simple(fred) #{@bad_var} = jim(45) end"
|
49
|
-
src.
|
50
|
-
|
49
|
+
expect(src).to smell_of(UncommunicativeVariableName,
|
50
|
+
UncommunicativeVariableName::VARIABLE_NAME_KEY => @bad_var)
|
51
51
|
end
|
52
52
|
it 'reports variable name only once' do
|
53
53
|
src = 'def simple(fred) x = jim(45); x = y end'
|
54
54
|
ctx = CodeContext.new(nil, src.to_reek_source.syntax_tree)
|
55
55
|
smells = @detector.examine_context(ctx)
|
56
|
-
smells.length.
|
57
|
-
smells[0].subclass.
|
58
|
-
smells[0].smell[UncommunicativeVariableName::VARIABLE_NAME_KEY].
|
59
|
-
smells[0].lines.
|
56
|
+
expect(smells.length).to eq(1)
|
57
|
+
expect(smells[0].subclass).to eq(UncommunicativeVariableName::SMELL_SUBCLASS)
|
58
|
+
expect(smells[0].smell[UncommunicativeVariableName::VARIABLE_NAME_KEY]).to eq('x')
|
59
|
+
expect(smells[0].lines).to eq([1, 1])
|
60
60
|
end
|
61
61
|
it 'reports a bad name inside a block' do
|
62
62
|
src = 'def clean(text) text.each { q2 = 3 } end'
|
63
|
-
src.
|
64
|
-
|
63
|
+
expect(src).to smell_of(UncommunicativeVariableName,
|
64
|
+
UncommunicativeVariableName::VARIABLE_NAME_KEY => 'q2')
|
65
65
|
end
|
66
66
|
it 'reports variable name outside any method' do
|
67
|
-
'class Simple; x = jim(45); end'.
|
67
|
+
expect('class Simple; x = jim(45); end').to reek_of(:UncommunicativeVariableName, /x/)
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
-
context
|
72
|
-
it
|
71
|
+
context 'block parameter name' do
|
72
|
+
it 'reports deep block parameter' do
|
73
73
|
src = <<EOS
|
74
74
|
def bad
|
75
75
|
unless @mod then
|
@@ -77,73 +77,73 @@ describe UncommunicativeVariableName do
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
EOS
|
80
|
-
src.
|
81
|
-
|
80
|
+
expect(src).to smell_of(UncommunicativeVariableName,
|
81
|
+
UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x')
|
82
82
|
end
|
83
83
|
|
84
|
-
it
|
84
|
+
it 'reports all relevant block parameters' do
|
85
85
|
src = <<-EOS
|
86
86
|
def bad
|
87
87
|
@foo.map { |x, y| x + y }
|
88
88
|
end
|
89
89
|
EOS
|
90
|
-
src.
|
91
|
-
|
92
|
-
|
90
|
+
expect(src).to smell_of(UncommunicativeVariableName,
|
91
|
+
{ UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x' },
|
92
|
+
UncommunicativeVariableName::VARIABLE_NAME_KEY => 'y')
|
93
93
|
end
|
94
94
|
|
95
|
-
it
|
95
|
+
it 'reports block parameters used outside of methods' do
|
96
96
|
src = <<-EOS
|
97
97
|
class Foo
|
98
98
|
@foo.map { |x| x * 2 }
|
99
99
|
end
|
100
100
|
EOS
|
101
|
-
src.
|
102
|
-
|
101
|
+
expect(src).to smell_of(UncommunicativeVariableName,
|
102
|
+
UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x')
|
103
103
|
end
|
104
104
|
|
105
|
-
it
|
105
|
+
it 'reports splatted block parameters correctly' do
|
106
106
|
src = <<-EOS
|
107
107
|
def bad
|
108
108
|
@foo.map { |*y| y << 1 }
|
109
109
|
end
|
110
110
|
EOS
|
111
|
-
src.
|
112
|
-
|
111
|
+
expect(src).to smell_of(UncommunicativeVariableName,
|
112
|
+
UncommunicativeVariableName::VARIABLE_NAME_KEY => 'y')
|
113
113
|
end
|
114
114
|
|
115
|
-
it
|
115
|
+
it 'reports nested block parameters' do
|
116
116
|
src = <<-EOS
|
117
117
|
def bad
|
118
118
|
@foo.map { |(x, y)| x + y }
|
119
119
|
end
|
120
120
|
EOS
|
121
|
-
src.
|
122
|
-
|
123
|
-
|
121
|
+
expect(src).to smell_of(UncommunicativeVariableName,
|
122
|
+
{ UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x' },
|
123
|
+
UncommunicativeVariableName::VARIABLE_NAME_KEY => 'y')
|
124
124
|
end
|
125
125
|
|
126
|
-
it
|
126
|
+
it 'reports splatted nested block parameters' do
|
127
127
|
src = <<-EOS
|
128
128
|
def bad
|
129
129
|
@foo.map { |(x, *y)| x + y }
|
130
130
|
end
|
131
131
|
EOS
|
132
|
-
src.
|
133
|
-
|
134
|
-
|
132
|
+
expect(src).to smell_of(UncommunicativeVariableName,
|
133
|
+
{ UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x' },
|
134
|
+
UncommunicativeVariableName::VARIABLE_NAME_KEY => 'y')
|
135
135
|
end
|
136
136
|
|
137
|
-
it
|
137
|
+
it 'reports deeply nested block parameters' do
|
138
138
|
src = <<-EOS
|
139
139
|
def bad
|
140
140
|
@foo.map { |(x, (y, z))| x + y + z }
|
141
141
|
end
|
142
142
|
EOS
|
143
|
-
src.
|
144
|
-
|
145
|
-
|
146
|
-
|
143
|
+
expect(src).to smell_of(UncommunicativeVariableName,
|
144
|
+
{ UncommunicativeVariableName::VARIABLE_NAME_KEY => 'x' },
|
145
|
+
{ UncommunicativeVariableName::VARIABLE_NAME_KEY => 'y' },
|
146
|
+
UncommunicativeVariableName::VARIABLE_NAME_KEY => 'z')
|
147
147
|
end
|
148
148
|
|
149
149
|
end
|
@@ -167,8 +167,8 @@ EOS
|
|
167
167
|
it_should_behave_like 'common fields set correctly'
|
168
168
|
|
169
169
|
it 'reports the correct values' do
|
170
|
-
@warning.smell['variable_name'].
|
171
|
-
@warning.lines.
|
170
|
+
expect(@warning.smell['variable_name']).to eq('x2')
|
171
|
+
expect(@warning.lines).to eq([3, 5])
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
@@ -183,7 +183,7 @@ EOS
|
|
183
183
|
it_should_behave_like 'common fields set correctly'
|
184
184
|
|
185
185
|
it 'reports the fq context' do
|
186
|
-
@warning.context.
|
186
|
+
expect(@warning.context).to eq('self.bad')
|
187
187
|
end
|
188
188
|
end
|
189
189
|
end
|
@@ -10,57 +10,67 @@ describe UnusedParameters do
|
|
10
10
|
context 'for methods' do
|
11
11
|
|
12
12
|
it 'reports nothing for no parameters' do
|
13
|
-
'def simple; true end'.
|
13
|
+
expect('def simple; true end').not_to smell_of(UnusedParameters)
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'reports nothing for used parameter' do
|
17
|
-
'def simple(sum); sum end'.
|
17
|
+
expect('def simple(sum); sum end').not_to smell_of(UnusedParameters)
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'reports for 1 used and 2 unused parameter' do
|
21
21
|
src = 'def simple(num,sum,denum); sum end'
|
22
|
-
src.
|
23
|
-
|
24
|
-
|
22
|
+
expect(src).to smell_of(UnusedParameters,
|
23
|
+
{ UnusedParameters::PARAMETER_KEY => 'num' },
|
24
|
+
UnusedParameters::PARAMETER_KEY => 'denum')
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'reports for 3 used and 1 unused parameter' do
|
28
28
|
src = 'def simple(num,sum,denum,quotient); num + denum + sum end'
|
29
|
-
src.
|
30
|
-
|
29
|
+
expect(src).to smell_of(UnusedParameters,
|
30
|
+
UnusedParameters::PARAMETER_KEY => 'quotient')
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'reports nothing for used splatted parameter' do
|
34
|
-
'def simple(*sum); sum end'.
|
34
|
+
expect('def simple(*sum); sum end').not_to smell_of(UnusedParameters)
|
35
35
|
end
|
36
36
|
|
37
37
|
it 'reports nothing for unused anonymous parameter' do
|
38
|
-
'def simple(_); end'.
|
38
|
+
expect('def simple(_); end').not_to smell_of(UnusedParameters)
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'reports nothing for named parameters prefixed with _' do
|
42
|
-
'def simple(_name); end'.
|
42
|
+
expect('def simple(_name); end').not_to smell_of(UnusedParameters)
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'reports nothing for unused anonymous splatted parameter' do
|
46
|
-
'def simple(*); end'.
|
46
|
+
expect('def simple(*); end').not_to smell_of(UnusedParameters)
|
47
47
|
end
|
48
48
|
|
49
49
|
it 'reports nothing when using super with implicit arguments' do
|
50
|
-
'def simple(*args); super; end'.
|
50
|
+
expect('def simple(*args); super; end').not_to smell_of(UnusedParameters)
|
51
51
|
end
|
52
52
|
|
53
53
|
it 'reports something when using super explicitely passing no arguments' do
|
54
|
-
'def simple(*args); super(); end'.
|
54
|
+
expect('def simple(*args); super(); end').to smell_of(UnusedParameters)
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'reports nothing when using super explicitely passing all arguments' do
|
58
|
-
'def simple(*args); super(*args); end'.
|
58
|
+
expect('def simple(*args); super(*args); end').not_to smell_of(UnusedParameters)
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'reports nothing when using super in a nested context' do
|
62
|
-
'def simple(*args); call_other("something", super); end'.
|
63
|
-
|
62
|
+
expect('def simple(*args); call_other("something", super); end').
|
63
|
+
not_to smell_of(UnusedParameters)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'reports something when not using a keyword argument with splat' do
|
67
|
+
expect('def simple(var, kw: :val, **args); @var, @kw = var, kw; end').
|
68
|
+
to smell_of(UnusedParameters)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'reports nothing when using a keyword argument with splat' do
|
72
|
+
expect('def simple(var, kw: :val, **args); @var, @kw, @args = var, kw, args; end').
|
73
|
+
not_to smell_of(UnusedParameters)
|
64
74
|
end
|
65
75
|
end
|
66
76
|
end
|
@@ -18,7 +18,7 @@ describe UtilityFunction do
|
|
18
18
|
it 'ignores the receiver' do
|
19
19
|
src = "def #{receiver}.simple(arga) arga.to_s + arga.to_i end"
|
20
20
|
ctx = MethodContext.new(nil, src.to_reek_source.syntax_tree)
|
21
|
-
@detector.examine_context(ctx).
|
21
|
+
expect(@detector.examine_context(ctx)).to be_empty
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -26,60 +26,60 @@ describe UtilityFunction do
|
|
26
26
|
it 'does not report empty method' do
|
27
27
|
src = 'def simple(arga) end'
|
28
28
|
ctx = MethodContext.new(nil, src.to_reek_source.syntax_tree)
|
29
|
-
@detector.examine_context(ctx).
|
29
|
+
expect(@detector.examine_context(ctx)).to be_empty
|
30
30
|
end
|
31
31
|
it 'does not report literal' do
|
32
|
-
'def simple() 3; end'.
|
32
|
+
expect('def simple() 3; end').not_to reek
|
33
33
|
end
|
34
34
|
it 'does not report instance variable reference' do
|
35
|
-
'def simple() @yellow end'.
|
35
|
+
expect('def simple() @yellow end').not_to reek
|
36
36
|
end
|
37
37
|
it 'does not report vcall' do
|
38
|
-
'def simple() y end'.
|
38
|
+
expect('def simple() y end').not_to reek
|
39
39
|
end
|
40
40
|
it 'does not report references to self' do
|
41
|
-
'def into; self; end'.
|
41
|
+
expect('def into; self; end').not_to reek
|
42
42
|
end
|
43
43
|
it 'recognises an ivar reference within a block' do
|
44
|
-
'def clean(text) text.each { @fred = 3} end'.
|
44
|
+
expect('def clean(text) text.each { @fred = 3} end').not_to reek
|
45
45
|
end
|
46
46
|
it 'copes with nil superclass' do
|
47
|
-
'# clean class for testing purposes
|
48
|
-
class Object; def is_maybe?() false end end'.
|
47
|
+
expect('# clean class for testing purposes
|
48
|
+
class Object; def is_maybe?() false end end').not_to reek
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
context 'with only one call' do
|
53
53
|
it 'does not report a call to a parameter' do
|
54
|
-
'def simple(arga) arga.to_s end'.
|
54
|
+
expect('def simple(arga) arga.to_s end').not_to reek_of(:UtilityFunction, /simple/)
|
55
55
|
end
|
56
56
|
it 'does not report a call to a constant' do
|
57
|
-
'def simple(arga) FIELDS[arga] end'.
|
57
|
+
expect('def simple(arga) FIELDS[arga] end').not_to reek
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
61
|
context 'with two or more calls' do
|
62
62
|
it 'reports two calls' do
|
63
|
-
'def simple(arga) arga.to_s + arga.to_i end'.
|
63
|
+
expect('def simple(arga) arga.to_s + arga.to_i end').to reek_of(:UtilityFunction, /simple/)
|
64
64
|
end
|
65
65
|
it 'counts a local call in a param initializer' do
|
66
|
-
'def simple(arga=local) arga.to_s end'.
|
66
|
+
expect('def simple(arga=local) arga.to_s end').not_to reek_of(:UtilityFunction)
|
67
67
|
end
|
68
68
|
it 'should count usages of self'do
|
69
|
-
'def <=>(other) Options[:sort_order].compare(self, other) end'.
|
69
|
+
expect('def <=>(other) Options[:sort_order].compare(self, other) end').not_to reek
|
70
70
|
end
|
71
71
|
it 'should count self reference within a dstr' do
|
72
|
-
'def as(alias_name); "#{self} as #{alias_name}".to_sym; end'.
|
72
|
+
expect('def as(alias_name); "#{self} as #{alias_name}".to_sym; end').not_to reek
|
73
73
|
end
|
74
74
|
it 'should count calls to self within a dstr' do
|
75
|
-
'def to_sql; "\'#{self.gsub(/\'/, "\'\'")}\'"; end'.
|
75
|
+
expect('def to_sql; "\'#{self.gsub(/\'/, "\'\'")}\'"; end').not_to reek
|
76
76
|
end
|
77
77
|
it 'should report message chain' do
|
78
|
-
'def simple(arga) arga.b.c end'.
|
78
|
+
expect('def simple(arga) arga.b.c end').to reek_of(:UtilityFunction, /simple/)
|
79
79
|
end
|
80
80
|
|
81
81
|
it 'does not report a method that calls super' do
|
82
|
-
'def child(arg) super; arg.to_s; end'.
|
82
|
+
expect('def child(arg) super; arg.to_s; end').not_to reek
|
83
83
|
end
|
84
84
|
|
85
85
|
it 'should recognise a deep call' do
|
@@ -95,7 +95,7 @@ class Object; def is_maybe?() false end end'.should_not reek
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
EOS
|
98
|
-
src.
|
98
|
+
expect(src).not_to reek
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
@@ -115,7 +115,7 @@ EOS
|
|
115
115
|
it_should_behave_like 'common fields set correctly'
|
116
116
|
|
117
117
|
it 'reports the line number of the method' do
|
118
|
-
@warning.lines.
|
118
|
+
expect(@warning.lines).to eq([1])
|
119
119
|
end
|
120
120
|
end
|
121
121
|
end
|