reek 3.2 → 3.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/lib/reek/ast/ast_node_class_map.rb +1 -5
  4. data/lib/reek/ast/node.rb +2 -4
  5. data/lib/reek/ast/object_refs.rb +5 -9
  6. data/lib/reek/ast/reference_collector.rb +2 -4
  7. data/lib/reek/cli/application.rb +9 -12
  8. data/lib/reek/cli/command.rb +0 -4
  9. data/lib/reek/cli/input.rb +4 -4
  10. data/lib/reek/cli/option_interpreter.rb +7 -11
  11. data/lib/reek/cli/options.rb +40 -42
  12. data/lib/reek/cli/reek_command.rb +3 -3
  13. data/lib/reek/cli/warning_collector.rb +3 -7
  14. data/lib/reek/code_comment.rb +1 -5
  15. data/lib/reek/context/code_context.rb +17 -19
  16. data/lib/reek/examiner.rb +6 -8
  17. data/lib/reek/rake/task.rb +22 -12
  18. data/lib/reek/report/formatter.rb +1 -5
  19. data/lib/reek/report/report.rb +13 -22
  20. data/lib/reek/smells/attribute.rb +6 -9
  21. data/lib/reek/smells/control_parameter.rb +13 -21
  22. data/lib/reek/smells/data_clump.rb +9 -17
  23. data/lib/reek/smells/duplicate_method_call.rb +6 -12
  24. data/lib/reek/smells/long_parameter_list.rb +2 -2
  25. data/lib/reek/smells/long_yield_list.rb +4 -4
  26. data/lib/reek/smells/nested_iterators.rb +2 -4
  27. data/lib/reek/smells/nil_check.rb +2 -6
  28. data/lib/reek/smells/repeated_conditional.rb +2 -2
  29. data/lib/reek/smells/smell_configuration.rb +7 -15
  30. data/lib/reek/smells/smell_detector.rb +10 -23
  31. data/lib/reek/smells/smell_warning.rb +6 -6
  32. data/lib/reek/smells/too_many_instance_variables.rb +2 -2
  33. data/lib/reek/smells/too_many_methods.rb +2 -2
  34. data/lib/reek/smells/too_many_statements.rb +4 -4
  35. data/lib/reek/smells/uncommunicative_method_name.rb +5 -5
  36. data/lib/reek/smells/uncommunicative_module_name.rb +5 -5
  37. data/lib/reek/smells/uncommunicative_parameter_name.rb +4 -8
  38. data/lib/reek/smells/uncommunicative_variable_name.rb +4 -8
  39. data/lib/reek/source/source_code.rb +1 -5
  40. data/lib/reek/spec/should_reek.rb +4 -9
  41. data/lib/reek/spec/should_reek_of.rb +5 -8
  42. data/lib/reek/spec/should_reek_only_of.rb +8 -12
  43. data/lib/reek/tree_dresser.rb +2 -6
  44. data/lib/reek/tree_walker.rb +22 -28
  45. data/lib/reek/version.rb +1 -1
  46. metadata +1 -1
@@ -51,8 +51,8 @@ module Reek
51
51
  # @return [Array<SmellWarning>]
52
52
  #
53
53
  def examine_context(ctx)
54
- self.reject_names = value(REJECT_KEY, ctx, DEFAULT_REJECT_SET)
55
- self.accept_names = value(ACCEPT_KEY, ctx, DEFAULT_ACCEPT_SET)
54
+ @reject_names = value(REJECT_KEY, ctx, DEFAULT_REJECT_SET)
55
+ @accept_names = value(ACCEPT_KEY, ctx, DEFAULT_ACCEPT_SET)
56
56
  variable_names(ctx.exp).select do |name, _lines|
57
57
  bad_name?(name, ctx)
58
58
  end.map do |name, lines|
@@ -66,8 +66,8 @@ module Reek
66
66
 
67
67
  def bad_name?(name, _ctx)
68
68
  var = name.to_s.gsub(/^[@\*\&]*/, '')
69
- return false if accept_names.include?(var)
70
- reject_names.find { |patt| patt =~ var }
69
+ return false if @accept_names.include?(var)
70
+ @reject_names.find { |patt| patt =~ var }
71
71
  end
72
72
 
73
73
  def variable_names(exp)
@@ -121,10 +121,6 @@ module Reek
121
121
  var = varname.to_sym
122
122
  accumulator[var].push(exp.line)
123
123
  end
124
-
125
- private
126
-
127
- private_attr_accessor :accept_names, :reject_names
128
124
  end
129
125
  end
130
126
  end
@@ -82,7 +82,7 @@ module Reek
82
82
  @syntax_tree ||=
83
83
  begin
84
84
  begin
85
- ast, comments = parser.parse_with_comments(source, description)
85
+ ast, comments = @parser.parse_with_comments(@source, @description)
86
86
  rescue Racc::ParseError, Parser::SyntaxError => error
87
87
  $stderr.puts "#{description}: #{error.class.name}: #{error}"
88
88
  end
@@ -92,10 +92,6 @@ module Reek
92
92
  TreeDresser.new.dress(ast, comment_map)
93
93
  end
94
94
  end
95
-
96
- private
97
-
98
- private_attr_reader :parser, :source
99
95
  end
100
96
  end
101
97
  end
@@ -13,23 +13,18 @@ module Reek
13
13
  end
14
14
 
15
15
  def matches?(actual)
16
- self.examiner = Examiner.new(actual, configuration: configuration)
17
- examiner.smelly?
16
+ @examiner = Examiner.new(actual, configuration: @configuration)
17
+ @examiner.smelly?
18
18
  end
19
19
 
20
20
  def failure_message
21
- "Expected #{examiner.description} to reek, but it didn't"
21
+ "Expected #{@examiner.description} to reek, but it didn't"
22
22
  end
23
23
 
24
24
  def failure_message_when_negated
25
- rpt = Report::Formatter.format_list(examiner.smells)
25
+ rpt = Report::Formatter.format_list(@examiner.smells)
26
26
  "Expected no smells, but got:\n#{rpt}"
27
27
  end
28
-
29
- private
30
-
31
- private_attr_reader :configuration
32
- private_attr_accessor :examiner
33
28
  end
34
29
  end
35
30
  end
@@ -17,24 +17,21 @@ module Reek
17
17
  end
18
18
 
19
19
  def matches?(actual)
20
- self.examiner = Examiner.new(actual, configuration: configuration)
21
- self.all_smells = examiner.smells
22
- all_smells.any? { |warning| warning.matches?(smell_category, smell_details) }
20
+ @examiner = Examiner.new(actual, configuration: @configuration)
21
+ @all_smells = @examiner.smells
22
+ @all_smells.any? { |warning| warning.matches?(@smell_category, @smell_details) }
23
23
  end
24
24
 
25
25
  def failure_message
26
- "Expected #{examiner.description} to reek of #{smell_category}, but it didn't"
26
+ "Expected #{@examiner.description} to reek of #{@smell_category}, but it didn't"
27
27
  end
28
28
 
29
29
  def failure_message_when_negated
30
- "Expected #{examiner.description} not to reek of #{smell_category}, but it did"
30
+ "Expected #{@examiner.description} not to reek of #{@smell_category}, but it did"
31
31
  end
32
32
 
33
33
  private
34
34
 
35
- private_attr_reader :configuration, :smell_category, :smell_details
36
- private_attr_accessor :all_smells, :examiner
37
-
38
35
  def normalize(smell_category_or_type)
39
36
  # In theory, users can give us many different types of input (see the documentation for
40
37
  # reek_of below), however we're basically ignoring all of those subleties and just
@@ -10,28 +10,24 @@ module Reek
10
10
  # @api private
11
11
  class ShouldReekOnlyOf < ShouldReekOf
12
12
  def matches?(actual)
13
- matches_examiner?(Examiner.new(actual, configuration: configuration))
13
+ matches_examiner?(Examiner.new(actual, configuration: @configuration))
14
14
  end
15
15
 
16
16
  def matches_examiner?(examiner)
17
- self.examiner = examiner
18
- self.warnings = examiner.smells
19
- return false if warnings.empty?
20
- warnings.all? { |warning| warning.matches?(smell_category) }
17
+ @examiner = examiner
18
+ @warnings = @examiner.smells
19
+ return false if @warnings.empty?
20
+ @warnings.all? { |warning| warning.matches?(@smell_category) }
21
21
  end
22
22
 
23
23
  def failure_message
24
- rpt = Report::Formatter.format_list(warnings)
25
- "Expected #{examiner.description} to reek only of #{smell_category}, but got:\n#{rpt}"
24
+ rpt = Report::Formatter.format_list(@warnings)
25
+ "Expected #{@examiner.description} to reek only of #{@smell_category}, but got:\n#{rpt}"
26
26
  end
27
27
 
28
28
  def failure_message_when_negated
29
- "Expected #{examiner.description} not to reek only of #{smell_category}, but it did"
29
+ "Expected #{@examiner.description} not to reek only of #{@smell_category}, but it did"
30
30
  end
31
-
32
- private
33
-
34
- private_attr_accessor :warnings
35
31
  end
36
32
  end
37
33
  end
@@ -25,12 +25,8 @@ 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
35
31
  end
36
32
  end
@@ -24,20 +24,14 @@ module Reek
24
24
  end
25
25
 
26
26
  def walk
27
- result.each do |element|
28
- smell_repository.examine(element)
27
+ @result ||= process(@exp)
28
+ @result.each do |element|
29
+ @smell_repository.examine(element)
29
30
  end
30
31
  end
31
32
 
32
33
  private
33
34
 
34
- private_attr_accessor :element
35
- private_attr_reader :exp, :smell_repository
36
-
37
- def result
38
- @result ||= process(exp)
39
- end
40
-
41
35
  def process(exp)
42
36
  context_processor = "process_#{exp.type}"
43
37
  if context_processor_exists?(context_processor)
@@ -45,7 +39,7 @@ module Reek
45
39
  else
46
40
  process_default exp
47
41
  end
48
- element
42
+ @element
49
43
  end
50
44
 
51
45
  def process_module(exp)
@@ -92,28 +86,28 @@ module Reek
92
86
 
93
87
  def process_send(exp)
94
88
  if visibility_modifier? exp
95
- element.track_visibility(exp.method_name, exp.arg_names)
89
+ @element.track_visibility(exp.method_name, exp.arg_names)
96
90
  end
97
- element.record_call_to(exp)
91
+ @element.record_call_to(exp)
98
92
  process_default(exp)
99
93
  end
100
94
 
101
95
  def process_attrasgn(exp)
102
- element.record_call_to(exp)
96
+ @element.record_call_to(exp)
103
97
  process_default(exp)
104
98
  end
105
99
 
106
100
  alias_method :process_op_asgn, :process_attrasgn
107
101
 
108
102
  def process_ivar(exp)
109
- element.record_use_of_self
103
+ @element.record_use_of_self
110
104
  process_default(exp)
111
105
  end
112
106
 
113
107
  alias_method :process_ivasgn, :process_ivar
114
108
 
115
109
  def process_self(_)
116
- element.record_use_of_self
110
+ @element.record_use_of_self
117
111
  end
118
112
 
119
113
  alias_method :process_zsuper, :process_self
@@ -129,7 +123,7 @@ module Reek
129
123
 
130
124
  def process_begin(exp)
131
125
  count_statement_list(exp.children)
132
- element.count_statements(-1)
126
+ @element.count_statements(-1)
133
127
  process_default(exp)
134
128
  end
135
129
 
@@ -138,13 +132,13 @@ module Reek
138
132
  def process_if(exp)
139
133
  count_clause(exp[2])
140
134
  count_clause(exp[3])
141
- element.count_statements(-1)
135
+ @element.count_statements(-1)
142
136
  process_default(exp)
143
137
  end
144
138
 
145
139
  def process_while(exp)
146
140
  count_clause(exp[2])
147
- element.count_statements(-1)
141
+ @element.count_statements(-1)
148
142
  process_default(exp)
149
143
  end
150
144
 
@@ -152,13 +146,13 @@ module Reek
152
146
 
153
147
  def process_for(exp)
154
148
  count_clause(exp[3])
155
- element.count_statements(-1)
149
+ @element.count_statements(-1)
156
150
  process_default(exp)
157
151
  end
158
152
 
159
153
  def process_rescue(exp)
160
154
  count_clause(exp[1])
161
- element.count_statements(-1)
155
+ @element.count_statements(-1)
162
156
  process_default(exp)
163
157
  end
164
158
 
@@ -169,7 +163,7 @@ module Reek
169
163
 
170
164
  def process_case(exp)
171
165
  count_clause(exp.else_body)
172
- element.count_statements(-1)
166
+ @element.count_statements(-1)
173
167
  process_default(exp)
174
168
  end
175
169
 
@@ -183,16 +177,16 @@ module Reek
183
177
  end
184
178
 
185
179
  def count_clause(sexp)
186
- element.count_statements(1) if sexp
180
+ @element.count_statements(1) if sexp
187
181
  end
188
182
 
189
183
  def count_statement_list(statement_list)
190
- element.count_statements statement_list.length
184
+ @element.count_statements statement_list.length
191
185
  end
192
186
 
193
187
  def inside_new_context(klass, exp)
194
- scope = klass.new(element, exp)
195
- element.append_child_context(scope)
188
+ scope = klass.new(@element, exp)
189
+ @element.append_child_context(scope)
196
190
  push(scope) do
197
191
  yield
198
192
  end
@@ -200,10 +194,10 @@ module Reek
200
194
  end
201
195
 
202
196
  def push(scope)
203
- orig = element
204
- self.element = scope
197
+ orig = @element
198
+ @element = scope
205
199
  yield
206
- self.element = orig
200
+ @element = orig
207
201
  end
208
202
 
209
203
  # FIXME: Move to SendNode?
@@ -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'
6
+ STRING = '3.2.1'
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reek
3
3
  version: !ruby/object:Gem::Version
4
- version: '3.2'
4
+ version: 3.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Rutherford