reek 3.2.1 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Rakefile +0 -1
- data/config/defaults.reek +1 -1
- data/features/samples.feature +17 -16
- data/lib/reek.rb +0 -1
- data/lib/reek/ast/ast_node_class_map.rb +5 -1
- data/lib/reek/ast/node.rb +10 -3
- data/lib/reek/ast/object_refs.rb +11 -5
- data/lib/reek/ast/reference_collector.rb +6 -2
- data/lib/reek/ast/sexp_extensions.rb +42 -1
- data/lib/reek/ast/sexp_formatter.rb +2 -1
- data/lib/reek/cli/application.rb +12 -9
- data/lib/reek/cli/command.rb +6 -0
- data/lib/reek/cli/input.rb +4 -4
- data/lib/reek/cli/option_interpreter.rb +11 -7
- data/lib/reek/cli/options.rb +42 -40
- data/lib/reek/cli/reek_command.rb +3 -3
- data/lib/reek/cli/silencer.rb +12 -3
- data/lib/reek/cli/warning_collector.rb +8 -3
- data/lib/reek/code_comment.rb +6 -1
- data/lib/reek/configuration/app_configuration.rb +65 -100
- data/lib/reek/configuration/configuration_file_finder.rb +4 -13
- data/lib/reek/configuration/configuration_validator.rb +35 -0
- data/lib/reek/configuration/default_directive.rb +12 -0
- data/lib/reek/configuration/directory_directives.rb +54 -0
- data/lib/reek/configuration/excluded_paths.rb +18 -0
- data/lib/reek/context/code_context.rb +19 -17
- data/lib/reek/examiner.rb +9 -7
- data/lib/reek/rake/task.rb +12 -22
- data/lib/reek/report/formatter.rb +6 -1
- data/lib/reek/report/report.rb +22 -13
- data/lib/reek/smells/attribute.rb +6 -53
- data/lib/reek/smells/control_parameter.rb +21 -13
- data/lib/reek/smells/data_clump.rb +17 -9
- data/lib/reek/smells/duplicate_method_call.rb +12 -6
- data/lib/reek/smells/long_parameter_list.rb +2 -2
- data/lib/reek/smells/long_yield_list.rb +4 -4
- data/lib/reek/smells/nested_iterators.rb +4 -2
- data/lib/reek/smells/nil_check.rb +6 -2
- data/lib/reek/smells/repeated_conditional.rb +3 -3
- data/lib/reek/smells/smell_configuration.rb +17 -7
- data/lib/reek/smells/smell_detector.rb +24 -11
- data/lib/reek/smells/smell_repository.rb +1 -1
- data/lib/reek/smells/smell_warning.rb +6 -6
- data/lib/reek/smells/too_many_instance_variables.rb +2 -2
- data/lib/reek/smells/too_many_methods.rb +4 -4
- data/lib/reek/smells/too_many_statements.rb +4 -4
- data/lib/reek/smells/uncommunicative_method_name.rb +5 -5
- data/lib/reek/smells/uncommunicative_module_name.rb +6 -6
- data/lib/reek/smells/uncommunicative_parameter_name.rb +8 -4
- data/lib/reek/smells/uncommunicative_variable_name.rb +9 -5
- data/lib/reek/smells/utility_function.rb +1 -1
- data/lib/reek/source/source_code.rb +5 -1
- data/lib/reek/source/source_locator.rb +3 -2
- data/lib/reek/spec.rb +3 -3
- data/lib/reek/spec/should_reek.rb +10 -5
- data/lib/reek/spec/should_reek_of.rb +9 -6
- data/lib/reek/spec/should_reek_only_of.rb +13 -8
- data/lib/reek/tree_dresser.rb +6 -2
- data/lib/reek/tree_walker.rb +40 -32
- data/lib/reek/version.rb +1 -1
- data/reek.gemspec +1 -1
- data/spec/reek/ast/node_spec.rb +1 -2
- data/spec/reek/ast/object_refs_spec.rb +40 -42
- data/spec/reek/ast/sexp_extensions_spec.rb +98 -104
- data/spec/reek/cli/warning_collector_spec.rb +8 -12
- data/spec/reek/code_comment_spec.rb +3 -5
- data/spec/reek/configuration/app_configuration_spec.rb +43 -57
- data/spec/reek/configuration/configuration_file_finder_spec.rb +5 -7
- data/spec/reek/configuration/default_directive_spec.rb +13 -0
- data/spec/reek/configuration/directory_directives_spec.rb +89 -0
- data/spec/reek/configuration/excluded_paths_spec.rb +30 -0
- data/spec/reek/context/code_context_spec.rb +63 -62
- data/spec/reek/context/method_context_spec.rb +8 -12
- data/spec/reek/context/module_context_spec.rb +1 -1
- data/spec/reek/context/root_context_spec.rb +3 -7
- data/spec/reek/examiner_spec.rb +14 -25
- data/spec/reek/smells/attribute_spec.rb +2 -4
- data/spec/reek/smells/boolean_parameter_spec.rb +5 -7
- data/spec/reek/smells/class_variable_spec.rb +29 -44
- data/spec/reek/smells/control_parameter_spec.rb +7 -9
- data/spec/reek/smells/data_clump_spec.rb +25 -32
- data/spec/reek/smells/duplicate_method_call_spec.rb +8 -7
- data/spec/reek/smells/feature_envy_spec.rb +16 -17
- data/spec/reek/smells/irresponsible_module_spec.rb +2 -4
- data/spec/reek/smells/long_parameter_list_spec.rb +6 -9
- data/spec/reek/smells/long_yield_list_spec.rb +6 -9
- data/spec/reek/smells/nested_iterators_spec.rb +14 -16
- data/spec/reek/smells/repeated_conditional_spec.rb +25 -25
- data/spec/reek/smells/smell_configuration_spec.rb +32 -27
- data/spec/reek/smells/smell_detector_shared.rb +12 -13
- data/spec/reek/smells/smell_warning_spec.rb +54 -58
- data/spec/reek/smells/too_many_instance_variables_spec.rb +9 -9
- data/spec/reek/smells/too_many_methods_spec.rb +13 -14
- data/spec/reek/smells/too_many_statements_spec.rb +8 -10
- data/spec/reek/smells/uncommunicative_method_name_spec.rb +8 -9
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +12 -13
- data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +7 -10
- data/spec/reek/smells/uncommunicative_variable_name_spec.rb +16 -20
- data/spec/reek/smells/utility_function_spec.rb +11 -15
- data/spec/reek/source/source_code_spec.rb +6 -11
- data/spec/reek/spec/should_reek_of_spec.rb +19 -30
- data/spec/reek/spec/should_reek_only_of_spec.rb +28 -34
- data/spec/reek/tree_walker_spec.rb +14 -2
- data/spec/spec_helper.rb +2 -3
- data/tasks/test.rake +0 -5
- metadata +10 -6
- data/docs/Configuration-Files.md +0 -49
- data/spec/gem/updates_spec.rb +0 -25
- data/spec/gem/yard_spec.rb +0 -11
- data/spec/reek/smells/behaves_like_variable_detector.rb +0 -39
data/lib/reek/tree_dresser.rb
CHANGED
@@ -25,8 +25,12 @@ module Reek
|
|
25
25
|
type = sexp.type
|
26
26
|
children = sexp.children.map { |child| dress(child, comment_map, sexp) }
|
27
27
|
comments = comment_map[sexp]
|
28
|
-
|
29
|
-
|
28
|
+
klass_map.klass_for(type).new(type, children,
|
29
|
+
location: sexp.loc, comments: comments, parent: parent)
|
30
30
|
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
private_attr_reader :klass_map
|
31
35
|
end
|
32
36
|
end
|
data/lib/reek/tree_walker.rb
CHANGED
@@ -24,14 +24,20 @@ module Reek
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def walk
|
27
|
-
|
28
|
-
|
29
|
-
@smell_repository.examine(element)
|
27
|
+
result.each do |element|
|
28
|
+
smell_repository.examine(element)
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
33
32
|
private
|
34
33
|
|
34
|
+
private_attr_accessor :element
|
35
|
+
private_attr_reader :exp, :smell_repository
|
36
|
+
|
37
|
+
def result
|
38
|
+
@result ||= process(exp)
|
39
|
+
end
|
40
|
+
|
35
41
|
def process(exp)
|
36
42
|
context_processor = "process_#{exp.type}"
|
37
43
|
if context_processor_exists?(context_processor)
|
@@ -39,7 +45,7 @@ module Reek
|
|
39
45
|
else
|
40
46
|
process_default exp
|
41
47
|
end
|
42
|
-
|
48
|
+
element
|
43
49
|
end
|
44
50
|
|
45
51
|
def process_module(exp)
|
@@ -85,29 +91,35 @@ module Reek
|
|
85
91
|
#
|
86
92
|
|
87
93
|
def process_send(exp)
|
88
|
-
if visibility_modifier?
|
89
|
-
|
94
|
+
if exp.visibility_modifier?
|
95
|
+
element.track_visibility(exp.method_name, exp.arg_names)
|
90
96
|
end
|
91
|
-
|
97
|
+
if exp.attribute_writer?
|
98
|
+
exp.args.each do |arg|
|
99
|
+
next unless arg.type == :sym
|
100
|
+
new_context(Context::MethodContext, arg)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
element.record_call_to(exp)
|
92
104
|
process_default(exp)
|
93
105
|
end
|
94
106
|
|
95
107
|
def process_attrasgn(exp)
|
96
|
-
|
108
|
+
element.record_call_to(exp)
|
97
109
|
process_default(exp)
|
98
110
|
end
|
99
111
|
|
100
112
|
alias_method :process_op_asgn, :process_attrasgn
|
101
113
|
|
102
114
|
def process_ivar(exp)
|
103
|
-
|
115
|
+
element.record_use_of_self
|
104
116
|
process_default(exp)
|
105
117
|
end
|
106
118
|
|
107
119
|
alias_method :process_ivasgn, :process_ivar
|
108
120
|
|
109
121
|
def process_self(_)
|
110
|
-
|
122
|
+
element.record_use_of_self
|
111
123
|
end
|
112
124
|
|
113
125
|
alias_method :process_zsuper, :process_self
|
@@ -123,7 +135,7 @@ module Reek
|
|
123
135
|
|
124
136
|
def process_begin(exp)
|
125
137
|
count_statement_list(exp.children)
|
126
|
-
|
138
|
+
element.count_statements(-1)
|
127
139
|
process_default(exp)
|
128
140
|
end
|
129
141
|
|
@@ -132,13 +144,13 @@ module Reek
|
|
132
144
|
def process_if(exp)
|
133
145
|
count_clause(exp[2])
|
134
146
|
count_clause(exp[3])
|
135
|
-
|
147
|
+
element.count_statements(-1)
|
136
148
|
process_default(exp)
|
137
149
|
end
|
138
150
|
|
139
151
|
def process_while(exp)
|
140
152
|
count_clause(exp[2])
|
141
|
-
|
153
|
+
element.count_statements(-1)
|
142
154
|
process_default(exp)
|
143
155
|
end
|
144
156
|
|
@@ -146,13 +158,13 @@ module Reek
|
|
146
158
|
|
147
159
|
def process_for(exp)
|
148
160
|
count_clause(exp[3])
|
149
|
-
|
161
|
+
element.count_statements(-1)
|
150
162
|
process_default(exp)
|
151
163
|
end
|
152
164
|
|
153
165
|
def process_rescue(exp)
|
154
166
|
count_clause(exp[1])
|
155
|
-
|
167
|
+
element.count_statements(-1)
|
156
168
|
process_default(exp)
|
157
169
|
end
|
158
170
|
|
@@ -163,7 +175,7 @@ module Reek
|
|
163
175
|
|
164
176
|
def process_case(exp)
|
165
177
|
count_clause(exp.else_body)
|
166
|
-
|
178
|
+
element.count_statements(-1)
|
167
179
|
process_default(exp)
|
168
180
|
end
|
169
181
|
|
@@ -177,34 +189,30 @@ module Reek
|
|
177
189
|
end
|
178
190
|
|
179
191
|
def count_clause(sexp)
|
180
|
-
|
192
|
+
element.count_statements(1) if sexp
|
181
193
|
end
|
182
194
|
|
183
195
|
def count_statement_list(statement_list)
|
184
|
-
|
196
|
+
element.count_statements statement_list.length
|
185
197
|
end
|
186
198
|
|
187
199
|
def inside_new_context(klass, exp)
|
188
|
-
|
189
|
-
@element.append_child_context(scope)
|
190
|
-
push(scope) do
|
200
|
+
push(new_context(klass, exp)) do
|
191
201
|
yield
|
192
202
|
end
|
193
|
-
scope
|
194
203
|
end
|
195
204
|
|
196
|
-
def
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
@element = orig
|
205
|
+
def new_context(klass, exp)
|
206
|
+
klass.new(element, exp).tap do |scope|
|
207
|
+
element.append_child_context(scope)
|
208
|
+
end
|
201
209
|
end
|
202
210
|
|
203
|
-
|
204
|
-
|
205
|
-
|
211
|
+
def push(scope)
|
212
|
+
orig = element
|
213
|
+
self.element = scope
|
214
|
+
yield
|
215
|
+
self.element = orig
|
206
216
|
end
|
207
|
-
|
208
|
-
VISIBILITY_MODIFIERS = [:private, :public, :protected, :module_function]
|
209
217
|
end
|
210
218
|
end
|
data/lib/reek/version.rb
CHANGED
data/reek.gemspec
CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |s|
|
|
5
5
|
s.name = 'reek'
|
6
6
|
s.version = Reek::Version::STRING
|
7
7
|
|
8
|
-
s.authors = ['Kevin Rutherford', 'Timo Roessner', 'Matijs van Zuijlen']
|
8
|
+
s.authors = ['Kevin Rutherford', 'Timo Roessner', 'Matijs van Zuijlen', 'Piotr Szotkowski']
|
9
9
|
s.default_executable = 'reek'
|
10
10
|
s.description = <<-DESC
|
11
11
|
Reek is a tool that examines Ruby classes, modules and methods and reports
|
data/spec/reek/ast/node_spec.rb
CHANGED
@@ -2,52 +2,50 @@ require_relative '../../spec_helper'
|
|
2
2
|
require_relative '../../../lib/reek/ast/object_refs'
|
3
3
|
|
4
4
|
RSpec.describe Reek::AST::ObjectRefs do
|
5
|
-
|
6
|
-
@refs = Reek::AST::ObjectRefs.new
|
7
|
-
end
|
5
|
+
let(:refs) { Reek::AST::ObjectRefs.new }
|
8
6
|
|
9
7
|
context 'when empty' do
|
10
8
|
it 'should report no refs to self' do
|
11
|
-
expect(
|
9
|
+
expect(refs.references_to(:self)).to be_empty
|
12
10
|
end
|
13
11
|
end
|
14
12
|
|
15
13
|
context 'with references to a, b, and a' do
|
16
14
|
context 'with no refs to self' do
|
17
15
|
before(:each) do
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
refs.record_reference_to(:a)
|
17
|
+
refs.record_reference_to(:b)
|
18
|
+
refs.record_reference_to(:a)
|
21
19
|
end
|
22
20
|
|
23
21
|
it 'should report no refs to self' do
|
24
|
-
expect(
|
22
|
+
expect(refs.references_to(:self)).to be_empty
|
25
23
|
end
|
26
24
|
|
27
25
|
it 'should report :a as the max' do
|
28
|
-
expect(
|
26
|
+
expect(refs.most_popular).to include(:a)
|
29
27
|
end
|
30
28
|
|
31
29
|
it 'should not report self as the max' do
|
32
|
-
expect(
|
30
|
+
expect(refs.self_is_max?).to eq(false)
|
33
31
|
end
|
34
32
|
|
35
33
|
context 'with one reference to self' do
|
36
34
|
before(:each) do
|
37
|
-
|
35
|
+
refs.record_reference_to(:self)
|
38
36
|
end
|
39
37
|
|
40
38
|
it 'should report 1 ref to self' do
|
41
|
-
expect(
|
39
|
+
expect(refs.references_to(:self).size).to eq(1)
|
42
40
|
end
|
43
41
|
|
44
42
|
it 'should not report self among the max' do
|
45
|
-
expect(
|
46
|
-
expect(
|
43
|
+
expect(refs.most_popular).to include(:a)
|
44
|
+
expect(refs.most_popular).not_to include(:self)
|
47
45
|
end
|
48
46
|
|
49
47
|
it 'should not report self as the max' do
|
50
|
-
expect(
|
48
|
+
expect(refs.self_is_max?).to eq(false)
|
51
49
|
end
|
52
50
|
end
|
53
51
|
end
|
@@ -55,70 +53,70 @@ RSpec.describe Reek::AST::ObjectRefs do
|
|
55
53
|
|
56
54
|
context 'with many refs to self' do
|
57
55
|
before(:each) do
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
56
|
+
refs.record_reference_to(:self)
|
57
|
+
refs.record_reference_to(:self)
|
58
|
+
refs.record_reference_to(:a)
|
59
|
+
refs.record_reference_to(:self)
|
60
|
+
refs.record_reference_to(:b)
|
61
|
+
refs.record_reference_to(:a)
|
62
|
+
refs.record_reference_to(:self)
|
65
63
|
end
|
66
64
|
|
67
65
|
it 'should report all refs to self' do
|
68
|
-
expect(
|
66
|
+
expect(refs.references_to(:self).size).to eq(4)
|
69
67
|
end
|
70
68
|
|
71
69
|
it 'should report self among the max' do
|
72
|
-
expect(
|
70
|
+
expect(refs.most_popular).to include(:self)
|
73
71
|
end
|
74
72
|
|
75
73
|
it 'should report self as the max' do
|
76
|
-
expect(
|
74
|
+
expect(refs.self_is_max?).to eq(true)
|
77
75
|
end
|
78
76
|
end
|
79
77
|
|
80
78
|
context 'when self is not the only max' do
|
81
79
|
before(:each) do
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
80
|
+
refs.record_reference_to(:a)
|
81
|
+
refs.record_reference_to(:self)
|
82
|
+
refs.record_reference_to(:self)
|
83
|
+
refs.record_reference_to(:b)
|
84
|
+
refs.record_reference_to(:a)
|
87
85
|
end
|
88
86
|
|
89
87
|
it 'should report all refs to self' do
|
90
|
-
expect(
|
88
|
+
expect(refs.references_to(:self).size).to eq(2)
|
91
89
|
end
|
92
90
|
|
93
91
|
it 'should report self among the max' do
|
94
|
-
expect(
|
95
|
-
expect(
|
92
|
+
expect(refs.most_popular).to include(:a)
|
93
|
+
expect(refs.most_popular).to include(:self)
|
96
94
|
end
|
97
95
|
|
98
96
|
it 'should report self as the max' do
|
99
|
-
expect(
|
97
|
+
expect(refs.self_is_max?).to eq(true)
|
100
98
|
end
|
101
99
|
end
|
102
100
|
|
103
101
|
context 'when self is not among the max' do
|
104
102
|
before(:each) do
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
103
|
+
refs.record_reference_to(:a)
|
104
|
+
refs.record_reference_to(:b)
|
105
|
+
refs.record_reference_to(:a)
|
106
|
+
refs.record_reference_to(:b)
|
109
107
|
end
|
110
108
|
|
111
109
|
it 'should report all refs to self' do
|
112
|
-
expect(
|
110
|
+
expect(refs.references_to(:self).size).to eq(0)
|
113
111
|
end
|
114
112
|
|
115
113
|
it 'should not report self among the max' do
|
116
|
-
expect(
|
117
|
-
expect(
|
114
|
+
expect(refs.most_popular).to include(:a)
|
115
|
+
expect(refs.most_popular).to include(:b)
|
118
116
|
end
|
119
117
|
|
120
118
|
it 'should not report self as the max' do
|
121
|
-
expect(
|
119
|
+
expect(refs.self_is_max?).to eq(false)
|
122
120
|
end
|
123
121
|
end
|
124
122
|
end
|
@@ -3,300 +3,282 @@ require_relative '../../../lib/reek/ast/sexp_extensions'
|
|
3
3
|
|
4
4
|
RSpec.describe Reek::AST::SexpExtensions::DefNode do
|
5
5
|
context 'with no parameters' do
|
6
|
-
|
7
|
-
@node = s(:def, :hello, s(:args))
|
8
|
-
end
|
6
|
+
let(:node) { s(:def, :hello, s(:args)) }
|
9
7
|
|
10
8
|
it 'has no arg names' do
|
11
|
-
expect(
|
9
|
+
expect(node.arg_names).to eq []
|
12
10
|
end
|
13
11
|
|
14
12
|
it 'has no parameter names' do
|
15
|
-
expect(
|
13
|
+
expect(node.parameter_names).to eq []
|
16
14
|
end
|
17
15
|
|
18
16
|
it 'includes outer scope in its full name' do
|
19
|
-
expect(
|
17
|
+
expect(node.full_name('Fred')).to eq 'Fred#hello'
|
20
18
|
end
|
21
19
|
|
22
20
|
it 'includes no marker in its full name with empty outer scope' do
|
23
|
-
expect(
|
21
|
+
expect(node.full_name('')).to eq 'hello'
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
27
25
|
context 'with 1 parameter' do
|
28
|
-
|
29
|
-
|
30
|
-
|
26
|
+
let(:node) do
|
27
|
+
s(:def, :hello,
|
28
|
+
s(:args, s(:arg, :param)))
|
31
29
|
end
|
32
30
|
|
33
31
|
it 'has 1 arg name' do
|
34
|
-
expect(
|
32
|
+
expect(node.arg_names).to eq [:param]
|
35
33
|
end
|
36
34
|
|
37
35
|
it 'has 1 parameter name' do
|
38
|
-
expect(
|
36
|
+
expect(node.parameter_names).to eq [:param]
|
39
37
|
end
|
40
38
|
|
41
39
|
it 'includes outer scope in its full name' do
|
42
|
-
expect(
|
40
|
+
expect(node.full_name('Fred')).to eq 'Fred#hello'
|
43
41
|
end
|
44
42
|
|
45
43
|
it 'includes no marker in its full name with empty outer scope' do
|
46
|
-
expect(
|
44
|
+
expect(node.full_name('')).to eq 'hello'
|
47
45
|
end
|
48
46
|
end
|
49
47
|
|
50
48
|
context 'with a block parameter' do
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
49
|
+
let(:node) do
|
50
|
+
s(:def, :hello,
|
51
|
+
s(:args,
|
52
|
+
s(:arg, :param),
|
53
|
+
s(:blockarg, :blk)))
|
56
54
|
end
|
57
55
|
|
58
56
|
it 'has 1 arg name' do
|
59
|
-
expect(
|
57
|
+
expect(node.arg_names).to eq [:param]
|
60
58
|
end
|
61
59
|
|
62
60
|
it 'has 2 parameter names' do
|
63
|
-
expect(
|
61
|
+
expect(node.parameter_names).to eq [:param, :blk]
|
64
62
|
end
|
65
63
|
|
66
64
|
it 'includes outer scope in its full name' do
|
67
|
-
expect(
|
65
|
+
expect(node.full_name('Fred')).to eq 'Fred#hello'
|
68
66
|
end
|
69
67
|
|
70
68
|
it 'includes no marker in its full name with empty outer scope' do
|
71
|
-
expect(
|
69
|
+
expect(node.full_name('')).to eq 'hello'
|
72
70
|
end
|
73
71
|
end
|
74
72
|
|
75
73
|
context 'with 1 defaulted parameter' do
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
74
|
+
let(:node) do
|
75
|
+
s(:def, :hello,
|
76
|
+
s(:args,
|
77
|
+
s(:optarg, :param, s(:array))))
|
80
78
|
end
|
81
79
|
|
82
80
|
it 'has 1 arg name' do
|
83
|
-
expect(
|
81
|
+
expect(node.arg_names).to eq [:param]
|
84
82
|
end
|
85
83
|
|
86
84
|
it 'has 1 parameter name' do
|
87
|
-
expect(
|
85
|
+
expect(node.parameter_names).to eq [:param]
|
88
86
|
end
|
89
87
|
|
90
88
|
it 'includes outer scope in its full name' do
|
91
|
-
expect(
|
89
|
+
expect(node.full_name('Fred')).to eq 'Fred#hello'
|
92
90
|
end
|
93
91
|
|
94
92
|
it 'includes no marker in its full name with empty outer scope' do
|
95
|
-
expect(
|
93
|
+
expect(node.full_name('')).to eq 'hello'
|
96
94
|
end
|
97
95
|
end
|
98
96
|
|
99
97
|
context 'with a body with 2 statements' do
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
98
|
+
let(:node) do
|
99
|
+
s(:def, :hello, s(:args),
|
100
|
+
s(:begin,
|
101
|
+
s(:first),
|
102
|
+
s(:second)))
|
105
103
|
end
|
106
104
|
|
107
105
|
it 'has 2 body statements' do
|
108
|
-
expect(
|
106
|
+
expect(node.body).to eq s(:begin, s(:first), s(:second))
|
109
107
|
end
|
110
108
|
|
111
109
|
it 'finds nodes in the body with #body_nodes' do
|
112
|
-
expect(
|
110
|
+
expect(node.body_nodes([:first])).to eq [s(:first)]
|
113
111
|
end
|
114
112
|
end
|
115
113
|
|
116
114
|
context 'with no body' do
|
117
|
-
|
118
|
-
@node = s(:def, :hello, s(:args), nil)
|
119
|
-
end
|
115
|
+
let(:node) { s(:def, :hello, s(:args), nil) }
|
120
116
|
|
121
117
|
it 'has a body that is nil' do
|
122
|
-
expect(
|
118
|
+
expect(node.body).to be_nil
|
123
119
|
end
|
124
120
|
|
125
121
|
it 'finds no nodes in the body' do
|
126
|
-
expect(
|
122
|
+
expect(node.body_nodes([:foo])).to eq []
|
127
123
|
end
|
128
124
|
end
|
129
125
|
end
|
130
126
|
|
131
127
|
RSpec.describe Reek::AST::SexpExtensions::DefsNode do
|
132
128
|
context 'with no parameters' do
|
133
|
-
|
134
|
-
@node = s(:defs, s(:lvar, :obj), :hello, s(:args))
|
135
|
-
end
|
129
|
+
let(:node) { s(:defs, s(:lvar, :obj), :hello, s(:args)) }
|
136
130
|
|
137
131
|
it 'has no arg names' do
|
138
|
-
expect(
|
132
|
+
expect(node.arg_names).to eq []
|
139
133
|
end
|
140
134
|
|
141
135
|
it 'has no parameter names' do
|
142
|
-
expect(
|
136
|
+
expect(node.parameter_names).to eq []
|
143
137
|
end
|
144
138
|
|
145
139
|
it 'includes outer scope in its full name' do
|
146
|
-
expect(
|
140
|
+
expect(node.full_name('Fred')).to eq 'Fred#obj.hello'
|
147
141
|
end
|
148
142
|
|
149
143
|
it 'includes no marker in its full name with empty outer scope' do
|
150
|
-
expect(
|
144
|
+
expect(node.full_name('')).to eq 'obj.hello'
|
151
145
|
end
|
152
146
|
end
|
153
147
|
|
154
148
|
context 'with 1 parameter' do
|
155
|
-
|
156
|
-
|
157
|
-
|
149
|
+
let(:node) do
|
150
|
+
s(:defs, s(:lvar, :obj), :hello,
|
151
|
+
s(:args, s(:arg, :param)))
|
158
152
|
end
|
159
153
|
|
160
154
|
it 'has 1 arg name' do
|
161
|
-
expect(
|
155
|
+
expect(node.arg_names).to eq [:param]
|
162
156
|
end
|
163
157
|
|
164
158
|
it 'has 1 parameter name' do
|
165
|
-
expect(
|
159
|
+
expect(node.parameter_names).to eq [:param]
|
166
160
|
end
|
167
161
|
|
168
162
|
it 'includes outer scope in its full name' do
|
169
|
-
expect(
|
163
|
+
expect(node.full_name('Fred')).to eq 'Fred#obj.hello'
|
170
164
|
end
|
171
165
|
|
172
166
|
it 'includes no marker in its full name with empty outer scope' do
|
173
|
-
expect(
|
167
|
+
expect(node.full_name('')).to eq 'obj.hello'
|
174
168
|
end
|
175
169
|
end
|
176
170
|
|
177
171
|
context 'with a block' do
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
172
|
+
let(:node) do
|
173
|
+
s(:defs, s(:lvar, :obj), :hello,
|
174
|
+
s(:args,
|
175
|
+
s(:arg, :param),
|
176
|
+
s(:blockarg, :blk)))
|
183
177
|
end
|
184
178
|
|
185
179
|
it 'has 1 arg name' do
|
186
|
-
expect(
|
180
|
+
expect(node.arg_names).to eq [:param]
|
187
181
|
end
|
188
182
|
|
189
183
|
it 'has 2 parameter names' do
|
190
|
-
expect(
|
184
|
+
expect(node.parameter_names).to eq [:param, :blk]
|
191
185
|
end
|
192
186
|
|
193
187
|
it 'includes outer scope in its full name' do
|
194
|
-
expect(
|
188
|
+
expect(node.full_name('Fred')).to eq 'Fred#obj.hello'
|
195
189
|
end
|
196
190
|
|
197
191
|
it 'includes no marker in its full name with empty outer scope' do
|
198
|
-
expect(
|
192
|
+
expect(node.full_name('')).to eq 'obj.hello'
|
199
193
|
end
|
200
194
|
end
|
201
195
|
|
202
196
|
context 'with 1 defaulted parameter' do
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
197
|
+
let(:node) do
|
198
|
+
s(:defs, s(:lvar, :obj), :hello,
|
199
|
+
s(:args,
|
200
|
+
s(:optarg, :param, s(:array))))
|
207
201
|
end
|
208
202
|
|
209
203
|
it 'has 1 arg name' do
|
210
|
-
expect(
|
204
|
+
expect(node.arg_names).to eq [:param]
|
211
205
|
end
|
212
206
|
|
213
207
|
it 'has 1 parameter name' do
|
214
|
-
expect(
|
208
|
+
expect(node.parameter_names).to eq [:param]
|
215
209
|
end
|
216
210
|
|
217
211
|
it 'includes outer scope in its full name' do
|
218
|
-
expect(
|
212
|
+
expect(node.full_name('Fred')).to eq 'Fred#obj.hello'
|
219
213
|
end
|
220
214
|
|
221
215
|
it 'includes no marker in its full name with empty outer scope' do
|
222
|
-
expect(
|
216
|
+
expect(node.full_name('')).to eq 'obj.hello'
|
223
217
|
end
|
224
218
|
end
|
225
219
|
|
226
220
|
context 'with a body with 2 statements' do
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
221
|
+
let(:node) do
|
222
|
+
s(:defs, s(:self), :hello, s(:args),
|
223
|
+
s(:begin,
|
224
|
+
s(:first),
|
225
|
+
s(:second)))
|
232
226
|
end
|
233
227
|
|
234
228
|
it 'has 2 body statements' do
|
235
|
-
expect(
|
229
|
+
expect(node.body).to eq s(:begin, s(:first), s(:second))
|
236
230
|
end
|
237
231
|
end
|
238
232
|
end
|
239
233
|
|
240
234
|
RSpec.describe Reek::AST::SexpExtensions::SendNode do
|
241
235
|
context 'with no parameters' do
|
242
|
-
|
243
|
-
@node = s(:send, nil, :hello)
|
244
|
-
end
|
236
|
+
let(:node) { s(:send, nil, :hello) }
|
245
237
|
|
246
238
|
it 'has no argument names' do
|
247
|
-
expect(
|
239
|
+
expect(node.arg_names).to eq []
|
248
240
|
end
|
249
241
|
end
|
250
242
|
|
251
243
|
context 'with 1 literal parameter' do
|
252
|
-
|
253
|
-
@node = s(:send, nil, :hello, s(:lit, :param))
|
254
|
-
end
|
244
|
+
let(:node) { s(:send, nil, :hello, s(:lit, :param)) }
|
255
245
|
|
256
246
|
it 'has 1 argument name' do
|
257
|
-
expect(
|
247
|
+
expect(node.arg_names).to eq [:param]
|
258
248
|
end
|
259
249
|
end
|
260
250
|
|
261
251
|
context 'with 2 literal parameters' do
|
262
|
-
|
263
|
-
@node = s(:send, nil, :hello, s(:lit, :x), s(:lit, :y))
|
264
|
-
end
|
252
|
+
let(:node) { s(:send, nil, :hello, s(:lit, :x), s(:lit, :y)) }
|
265
253
|
|
266
254
|
it 'has 2 argument names' do
|
267
|
-
expect(
|
255
|
+
expect(node.arg_names).to eq [:x, :y]
|
268
256
|
end
|
269
257
|
end
|
270
258
|
end
|
271
259
|
|
272
260
|
RSpec.describe Reek::AST::SexpExtensions::BlockNode do
|
273
261
|
context 'with no parameters' do
|
274
|
-
|
275
|
-
@node = s(:block, s(:send, nil, :map), s(:args), nil)
|
276
|
-
end
|
262
|
+
let(:node) { s(:block, s(:send, nil, :map), s(:args), nil) }
|
277
263
|
|
278
264
|
it 'has no parameter names' do
|
279
|
-
expect(
|
265
|
+
expect(node.parameter_names).to eq []
|
280
266
|
end
|
281
267
|
end
|
282
268
|
|
283
269
|
context 'with 1 parameter' do
|
284
|
-
|
285
|
-
@node = s(:block, s(:send, nil, :map), s(:args, :param), nil)
|
286
|
-
end
|
270
|
+
let(:node) { s(:block, s(:send, nil, :map), s(:args, :param), nil) }
|
287
271
|
|
288
272
|
it 'has 1 parameter name' do
|
289
|
-
expect(
|
273
|
+
expect(node.parameter_names).to eq [:param]
|
290
274
|
end
|
291
275
|
end
|
292
276
|
|
293
277
|
context 'with 2 parameters' do
|
294
|
-
|
295
|
-
@node = s(:block, s(:send, nil, :map), s(:args, :x, :y), nil)
|
296
|
-
end
|
278
|
+
let(:node) { s(:block, s(:send, nil, :map), s(:args, :x, :y), nil) }
|
297
279
|
|
298
280
|
it 'has 2 parameter names' do
|
299
|
-
expect(
|
281
|
+
expect(node.parameter_names).to eq [:x, :y]
|
300
282
|
end
|
301
283
|
end
|
302
284
|
end
|
@@ -347,3 +329,15 @@ RSpec.describe Reek::AST::SexpExtensions::ModuleNode do
|
|
347
329
|
end
|
348
330
|
end
|
349
331
|
end
|
332
|
+
|
333
|
+
RSpec.describe Reek::AST::SexpExtensions::CasgnNode do
|
334
|
+
context 'with single assignment' do
|
335
|
+
subject do
|
336
|
+
s(:casgn, nil, :Foo)
|
337
|
+
end
|
338
|
+
|
339
|
+
it 'does not define a module' do
|
340
|
+
expect(subject.defines_module?).to eq(false)
|
341
|
+
end
|
342
|
+
end
|
343
|
+
end
|