reek 3.2.1 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Rakefile +0 -1
  4. data/config/defaults.reek +1 -1
  5. data/features/samples.feature +17 -16
  6. data/lib/reek.rb +0 -1
  7. data/lib/reek/ast/ast_node_class_map.rb +5 -1
  8. data/lib/reek/ast/node.rb +10 -3
  9. data/lib/reek/ast/object_refs.rb +11 -5
  10. data/lib/reek/ast/reference_collector.rb +6 -2
  11. data/lib/reek/ast/sexp_extensions.rb +42 -1
  12. data/lib/reek/ast/sexp_formatter.rb +2 -1
  13. data/lib/reek/cli/application.rb +12 -9
  14. data/lib/reek/cli/command.rb +6 -0
  15. data/lib/reek/cli/input.rb +4 -4
  16. data/lib/reek/cli/option_interpreter.rb +11 -7
  17. data/lib/reek/cli/options.rb +42 -40
  18. data/lib/reek/cli/reek_command.rb +3 -3
  19. data/lib/reek/cli/silencer.rb +12 -3
  20. data/lib/reek/cli/warning_collector.rb +8 -3
  21. data/lib/reek/code_comment.rb +6 -1
  22. data/lib/reek/configuration/app_configuration.rb +65 -100
  23. data/lib/reek/configuration/configuration_file_finder.rb +4 -13
  24. data/lib/reek/configuration/configuration_validator.rb +35 -0
  25. data/lib/reek/configuration/default_directive.rb +12 -0
  26. data/lib/reek/configuration/directory_directives.rb +54 -0
  27. data/lib/reek/configuration/excluded_paths.rb +18 -0
  28. data/lib/reek/context/code_context.rb +19 -17
  29. data/lib/reek/examiner.rb +9 -7
  30. data/lib/reek/rake/task.rb +12 -22
  31. data/lib/reek/report/formatter.rb +6 -1
  32. data/lib/reek/report/report.rb +22 -13
  33. data/lib/reek/smells/attribute.rb +6 -53
  34. data/lib/reek/smells/control_parameter.rb +21 -13
  35. data/lib/reek/smells/data_clump.rb +17 -9
  36. data/lib/reek/smells/duplicate_method_call.rb +12 -6
  37. data/lib/reek/smells/long_parameter_list.rb +2 -2
  38. data/lib/reek/smells/long_yield_list.rb +4 -4
  39. data/lib/reek/smells/nested_iterators.rb +4 -2
  40. data/lib/reek/smells/nil_check.rb +6 -2
  41. data/lib/reek/smells/repeated_conditional.rb +3 -3
  42. data/lib/reek/smells/smell_configuration.rb +17 -7
  43. data/lib/reek/smells/smell_detector.rb +24 -11
  44. data/lib/reek/smells/smell_repository.rb +1 -1
  45. data/lib/reek/smells/smell_warning.rb +6 -6
  46. data/lib/reek/smells/too_many_instance_variables.rb +2 -2
  47. data/lib/reek/smells/too_many_methods.rb +4 -4
  48. data/lib/reek/smells/too_many_statements.rb +4 -4
  49. data/lib/reek/smells/uncommunicative_method_name.rb +5 -5
  50. data/lib/reek/smells/uncommunicative_module_name.rb +6 -6
  51. data/lib/reek/smells/uncommunicative_parameter_name.rb +8 -4
  52. data/lib/reek/smells/uncommunicative_variable_name.rb +9 -5
  53. data/lib/reek/smells/utility_function.rb +1 -1
  54. data/lib/reek/source/source_code.rb +5 -1
  55. data/lib/reek/source/source_locator.rb +3 -2
  56. data/lib/reek/spec.rb +3 -3
  57. data/lib/reek/spec/should_reek.rb +10 -5
  58. data/lib/reek/spec/should_reek_of.rb +9 -6
  59. data/lib/reek/spec/should_reek_only_of.rb +13 -8
  60. data/lib/reek/tree_dresser.rb +6 -2
  61. data/lib/reek/tree_walker.rb +40 -32
  62. data/lib/reek/version.rb +1 -1
  63. data/reek.gemspec +1 -1
  64. data/spec/reek/ast/node_spec.rb +1 -2
  65. data/spec/reek/ast/object_refs_spec.rb +40 -42
  66. data/spec/reek/ast/sexp_extensions_spec.rb +98 -104
  67. data/spec/reek/cli/warning_collector_spec.rb +8 -12
  68. data/spec/reek/code_comment_spec.rb +3 -5
  69. data/spec/reek/configuration/app_configuration_spec.rb +43 -57
  70. data/spec/reek/configuration/configuration_file_finder_spec.rb +5 -7
  71. data/spec/reek/configuration/default_directive_spec.rb +13 -0
  72. data/spec/reek/configuration/directory_directives_spec.rb +89 -0
  73. data/spec/reek/configuration/excluded_paths_spec.rb +30 -0
  74. data/spec/reek/context/code_context_spec.rb +63 -62
  75. data/spec/reek/context/method_context_spec.rb +8 -12
  76. data/spec/reek/context/module_context_spec.rb +1 -1
  77. data/spec/reek/context/root_context_spec.rb +3 -7
  78. data/spec/reek/examiner_spec.rb +14 -25
  79. data/spec/reek/smells/attribute_spec.rb +2 -4
  80. data/spec/reek/smells/boolean_parameter_spec.rb +5 -7
  81. data/spec/reek/smells/class_variable_spec.rb +29 -44
  82. data/spec/reek/smells/control_parameter_spec.rb +7 -9
  83. data/spec/reek/smells/data_clump_spec.rb +25 -32
  84. data/spec/reek/smells/duplicate_method_call_spec.rb +8 -7
  85. data/spec/reek/smells/feature_envy_spec.rb +16 -17
  86. data/spec/reek/smells/irresponsible_module_spec.rb +2 -4
  87. data/spec/reek/smells/long_parameter_list_spec.rb +6 -9
  88. data/spec/reek/smells/long_yield_list_spec.rb +6 -9
  89. data/spec/reek/smells/nested_iterators_spec.rb +14 -16
  90. data/spec/reek/smells/repeated_conditional_spec.rb +25 -25
  91. data/spec/reek/smells/smell_configuration_spec.rb +32 -27
  92. data/spec/reek/smells/smell_detector_shared.rb +12 -13
  93. data/spec/reek/smells/smell_warning_spec.rb +54 -58
  94. data/spec/reek/smells/too_many_instance_variables_spec.rb +9 -9
  95. data/spec/reek/smells/too_many_methods_spec.rb +13 -14
  96. data/spec/reek/smells/too_many_statements_spec.rb +8 -10
  97. data/spec/reek/smells/uncommunicative_method_name_spec.rb +8 -9
  98. data/spec/reek/smells/uncommunicative_module_name_spec.rb +12 -13
  99. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +7 -10
  100. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +16 -20
  101. data/spec/reek/smells/utility_function_spec.rb +11 -15
  102. data/spec/reek/source/source_code_spec.rb +6 -11
  103. data/spec/reek/spec/should_reek_of_spec.rb +19 -30
  104. data/spec/reek/spec/should_reek_only_of_spec.rb +28 -34
  105. data/spec/reek/tree_walker_spec.rb +14 -2
  106. data/spec/spec_helper.rb +2 -3
  107. data/tasks/test.rake +0 -5
  108. metadata +10 -6
  109. data/docs/Configuration-Files.md +0 -49
  110. data/spec/gem/updates_spec.rb +0 -25
  111. data/spec/gem/yard_spec.rb +0 -11
  112. data/spec/reek/smells/behaves_like_variable_detector.rb +0 -39
@@ -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
- @klass_map.klass_for(type).new(type, children,
29
- location: sexp.loc, comments: comments, parent: parent)
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
@@ -24,14 +24,20 @@ module Reek
24
24
  end
25
25
 
26
26
  def walk
27
- @result ||= process(@exp)
28
- @result.each do |element|
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
- @element
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? exp
89
- @element.track_visibility(exp.method_name, exp.arg_names)
94
+ if exp.visibility_modifier?
95
+ element.track_visibility(exp.method_name, exp.arg_names)
90
96
  end
91
- @element.record_call_to(exp)
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
- @element.record_call_to(exp)
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
- @element.record_use_of_self
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
- @element.record_use_of_self
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
- @element.count_statements(-1)
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
- @element.count_statements(-1)
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
- @element.count_statements(-1)
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
- @element.count_statements(-1)
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
- @element.count_statements(-1)
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
- @element.count_statements(-1)
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
- @element.count_statements(1) if sexp
192
+ element.count_statements(1) if sexp
181
193
  end
182
194
 
183
195
  def count_statement_list(statement_list)
184
- @element.count_statements statement_list.length
196
+ element.count_statements statement_list.length
185
197
  end
186
198
 
187
199
  def inside_new_context(klass, exp)
188
- scope = klass.new(@element, exp)
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 push(scope)
197
- orig = @element
198
- @element = scope
199
- yield
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
- # FIXME: Move to SendNode?
204
- def visibility_modifier?(call_node)
205
- VISIBILITY_MODIFIERS.include?(call_node.method_name)
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
@@ -3,6 +3,6 @@ module Reek
3
3
  # This module holds the Reek version informations
4
4
  #
5
5
  module Version
6
- STRING = '3.2.1'
6
+ STRING = '3.3.0'
7
7
  end
8
8
  end
@@ -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
@@ -4,8 +4,7 @@ require_relative '../../../lib/reek/ast/node'
4
4
  RSpec.describe Reek::AST::Node do
5
5
  context 'format' do
6
6
  it 'formats self' do
7
- @node = s(:self)
8
- expect(@node.format_to_ruby).to eq('self')
7
+ expect(s(:self).format_to_ruby).to eq('self')
9
8
  end
10
9
  end
11
10
 
@@ -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
- before(:each) do
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(@refs.references_to(:self)).to be_empty
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
- @refs.record_reference_to(:a)
19
- @refs.record_reference_to(:b)
20
- @refs.record_reference_to(:a)
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(@refs.references_to(:self)).to be_empty
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(@refs.most_popular).to include(:a)
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(@refs.self_is_max?).to eq(false)
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
- @refs.record_reference_to(:self)
35
+ refs.record_reference_to(:self)
38
36
  end
39
37
 
40
38
  it 'should report 1 ref to self' do
41
- expect(@refs.references_to(:self).size).to eq(1)
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(@refs.most_popular).to include(:a)
46
- expect(@refs.most_popular).not_to include(:self)
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(@refs.self_is_max?).to eq(false)
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
- @refs.record_reference_to(:self)
59
- @refs.record_reference_to(:self)
60
- @refs.record_reference_to(:a)
61
- @refs.record_reference_to(:self)
62
- @refs.record_reference_to(:b)
63
- @refs.record_reference_to(:a)
64
- @refs.record_reference_to(:self)
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(@refs.references_to(:self).size).to eq(4)
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(@refs.most_popular).to include(:self)
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(@refs.self_is_max?).to eq(true)
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
- @refs.record_reference_to(:a)
83
- @refs.record_reference_to(:self)
84
- @refs.record_reference_to(:self)
85
- @refs.record_reference_to(:b)
86
- @refs.record_reference_to(:a)
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(@refs.references_to(:self).size).to eq(2)
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(@refs.most_popular).to include(:a)
95
- expect(@refs.most_popular).to include(:self)
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(@refs.self_is_max?).to eq(true)
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
- @refs.record_reference_to(:a)
106
- @refs.record_reference_to(:b)
107
- @refs.record_reference_to(:a)
108
- @refs.record_reference_to(:b)
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(@refs.references_to(:self).size).to eq(0)
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(@refs.most_popular).to include(:a)
117
- expect(@refs.most_popular).to include(:b)
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(@refs.self_is_max?).to eq(false)
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
- before :each do
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(@node.arg_names).to eq []
9
+ expect(node.arg_names).to eq []
12
10
  end
13
11
 
14
12
  it 'has no parameter names' do
15
- expect(@node.parameter_names).to eq []
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(@node.full_name('Fred')).to eq 'Fred#hello'
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(@node.full_name('')).to eq 'hello'
21
+ expect(node.full_name('')).to eq 'hello'
24
22
  end
25
23
  end
26
24
 
27
25
  context 'with 1 parameter' do
28
- before :each do
29
- @node = s(:def, :hello,
30
- s(:args, s(:arg, :param)))
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(@node.arg_names).to eq [:param]
32
+ expect(node.arg_names).to eq [:param]
35
33
  end
36
34
 
37
35
  it 'has 1 parameter name' do
38
- expect(@node.parameter_names).to eq [:param]
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(@node.full_name('Fred')).to eq 'Fred#hello'
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(@node.full_name('')).to eq 'hello'
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
- before :each do
52
- @node = s(:def, :hello,
53
- s(:args,
54
- s(:arg, :param),
55
- s(:blockarg, :blk)))
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(@node.arg_names).to eq [:param]
57
+ expect(node.arg_names).to eq [:param]
60
58
  end
61
59
 
62
60
  it 'has 2 parameter names' do
63
- expect(@node.parameter_names).to eq [:param, :blk]
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(@node.full_name('Fred')).to eq 'Fred#hello'
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(@node.full_name('')).to eq 'hello'
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
- before :each do
77
- @node = s(:def, :hello,
78
- s(:args,
79
- s(:optarg, :param, s(:array))))
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(@node.arg_names).to eq [:param]
81
+ expect(node.arg_names).to eq [:param]
84
82
  end
85
83
 
86
84
  it 'has 1 parameter name' do
87
- expect(@node.parameter_names).to eq [:param]
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(@node.full_name('Fred')).to eq 'Fred#hello'
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(@node.full_name('')).to eq 'hello'
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
- before :each do
101
- @node = s(:def, :hello, s(:args),
102
- s(:begin,
103
- s(:first),
104
- s(:second)))
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(@node.body).to eq s(:begin, s(:first), s(:second))
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(@node.body_nodes([:first])).to eq [s(:first)]
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
- before :each do
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(@node.body).to be_nil
118
+ expect(node.body).to be_nil
123
119
  end
124
120
 
125
121
  it 'finds no nodes in the body' do
126
- expect(@node.body_nodes([:foo])).to eq []
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
- before :each do
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(@node.arg_names).to eq []
132
+ expect(node.arg_names).to eq []
139
133
  end
140
134
 
141
135
  it 'has no parameter names' do
142
- expect(@node.parameter_names).to eq []
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(@node.full_name('Fred')).to eq 'Fred#obj.hello'
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(@node.full_name('')).to eq 'obj.hello'
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
- before :each do
156
- @node = s(:defs, s(:lvar, :obj), :hello,
157
- s(:args, s(:arg, :param)))
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(@node.arg_names).to eq [:param]
155
+ expect(node.arg_names).to eq [:param]
162
156
  end
163
157
 
164
158
  it 'has 1 parameter name' do
165
- expect(@node.parameter_names).to eq [:param]
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(@node.full_name('Fred')).to eq 'Fred#obj.hello'
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(@node.full_name('')).to eq 'obj.hello'
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
- before :each do
179
- @node = s(:defs, s(:lvar, :obj), :hello,
180
- s(:args,
181
- s(:arg, :param),
182
- s(:blockarg, :blk)))
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(@node.arg_names).to eq [:param]
180
+ expect(node.arg_names).to eq [:param]
187
181
  end
188
182
 
189
183
  it 'has 2 parameter names' do
190
- expect(@node.parameter_names).to eq [:param, :blk]
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(@node.full_name('Fred')).to eq 'Fred#obj.hello'
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(@node.full_name('')).to eq 'obj.hello'
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
- before :each do
204
- @node = s(:defs, s(:lvar, :obj), :hello,
205
- s(:args,
206
- s(:optarg, :param, s(:array))))
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(@node.arg_names).to eq [:param]
204
+ expect(node.arg_names).to eq [:param]
211
205
  end
212
206
 
213
207
  it 'has 1 parameter name' do
214
- expect(@node.parameter_names).to eq [:param]
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(@node.full_name('Fred')).to eq 'Fred#obj.hello'
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(@node.full_name('')).to eq 'obj.hello'
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
- before :each do
228
- @node = s(:defs, s(:self), :hello, s(:args),
229
- s(:begin,
230
- s(:first),
231
- s(:second)))
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(@node.body).to eq s(:begin, s(:first), s(:second))
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
- before :each do
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(@node.arg_names).to eq []
239
+ expect(node.arg_names).to eq []
248
240
  end
249
241
  end
250
242
 
251
243
  context 'with 1 literal parameter' do
252
- before :each do
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(@node.arg_names).to eq [:param]
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
- before :each do
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(@node.arg_names).to eq [:x, :y]
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
- before :each do
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(@node.parameter_names).to eq []
265
+ expect(node.parameter_names).to eq []
280
266
  end
281
267
  end
282
268
 
283
269
  context 'with 1 parameter' do
284
- before :each do
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(@node.parameter_names).to eq [:param]
273
+ expect(node.parameter_names).to eq [:param]
290
274
  end
291
275
  end
292
276
 
293
277
  context 'with 2 parameters' do
294
- before :each do
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(@node.parameter_names).to eq [:x, :y]
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