reek 4.2.3 → 4.2.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -1
  3. data/CHANGELOG.md +6 -0
  4. data/CONTRIBUTING.md +7 -6
  5. data/Gemfile +2 -2
  6. data/README.md +8 -15
  7. data/Rakefile +1 -1
  8. data/defaults.reek +1 -0
  9. data/features/command_line_interface/basic_usage.feature +8 -14
  10. data/features/command_line_interface/smell_selection.feature +4 -4
  11. data/features/command_line_interface/smells_count.feature +12 -14
  12. data/features/configuration_files/masking_smells.feature +31 -24
  13. data/features/configuration_loading.feature +15 -18
  14. data/features/programmatic_access.feature +7 -9
  15. data/features/rake_task/rake_task.feature +20 -24
  16. data/features/reports/json.feature +16 -28
  17. data/features/reports/reports.feature +56 -67
  18. data/features/reports/yaml.feature +13 -26
  19. data/features/samples.feature +3 -3
  20. data/features/step_definitions/sample_file_steps.rb +22 -156
  21. data/features/todo_list.feature +13 -14
  22. data/lib/reek/cli/options.rb +1 -1
  23. data/lib/reek/examiner.rb +45 -10
  24. data/lib/reek/smells/attribute.rb +3 -4
  25. data/lib/reek/smells/boolean_parameter.rb +2 -2
  26. data/lib/reek/smells/class_variable.rb +1 -1
  27. data/lib/reek/smells/control_parameter.rb +4 -4
  28. data/lib/reek/smells/data_clump.rb +2 -3
  29. data/lib/reek/smells/duplicate_method_call.rb +1 -1
  30. data/lib/reek/smells/feature_envy.rb +2 -2
  31. data/lib/reek/smells/irresponsible_module.rb +2 -3
  32. data/lib/reek/smells/long_parameter_list.rb +1 -1
  33. data/lib/reek/smells/long_yield_list.rb +1 -1
  34. data/lib/reek/smells/module_initialize.rb +1 -1
  35. data/lib/reek/smells/nested_iterators.rb +2 -2
  36. data/lib/reek/smells/nil_check.rb +1 -1
  37. data/lib/reek/smells/prima_donna_method.rb +5 -2
  38. data/lib/reek/smells/repeated_conditional.rb +1 -1
  39. data/lib/reek/smells/smell_detector.rb +1 -1
  40. data/lib/reek/smells/smell_warning.rb +6 -5
  41. data/lib/reek/smells/subclassed_from_core_class.rb +3 -3
  42. data/lib/reek/smells/too_many_constants.rb +1 -1
  43. data/lib/reek/smells/too_many_instance_variables.rb +1 -1
  44. data/lib/reek/smells/too_many_methods.rb +1 -1
  45. data/lib/reek/smells/too_many_statements.rb +1 -1
  46. data/lib/reek/smells/uncommunicative_method_name.rb +1 -1
  47. data/lib/reek/smells/uncommunicative_module_name.rb +1 -1
  48. data/lib/reek/smells/uncommunicative_parameter_name.rb +1 -1
  49. data/lib/reek/smells/uncommunicative_variable_name.rb +1 -1
  50. data/lib/reek/smells/unused_parameters.rb +1 -1
  51. data/lib/reek/smells/unused_private_method.rb +1 -1
  52. data/lib/reek/smells/utility_function.rb +2 -3
  53. data/lib/reek/spec/should_reek_of.rb +14 -1
  54. data/lib/reek/version.rb +1 -1
  55. data/samples/checkstyle.xml +7 -0
  56. data/samples/clean.rb +6 -0
  57. data/samples/configuration/.reek +0 -0
  58. data/samples/configuration/corrupt.reek +1 -0
  59. data/samples/configuration/empty.reek +0 -0
  60. data/samples/configuration/full_configuration.reek +9 -0
  61. data/{spec/samples/configuration/simple_configuration.reek → samples/configuration/full_mask.reek} +2 -2
  62. data/samples/configuration/non_public_modifiers_mask.reek +3 -0
  63. data/samples/configuration/partial_mask.reek +3 -0
  64. data/samples/configuration/with_excluded_paths.reek +4 -0
  65. data/{spec/samples → samples}/exceptions.reek +0 -0
  66. data/{spec/samples → samples}/inline.rb +0 -0
  67. data/{spec/samples → samples}/optparse.rb +0 -0
  68. data/samples/paths.rb +4 -0
  69. data/{spec/samples → samples}/redcloth.rb +0 -0
  70. data/samples/smelly.rb +7 -0
  71. data/samples/smelly_with_inline_mask.rb +8 -0
  72. data/samples/smelly_with_modifiers.rb +12 -0
  73. data/{spec/samples → samples}/source_with_exclude_paths/ignore_me/uncommunicative_method_name.rb +0 -0
  74. data/{spec/samples → samples}/source_with_exclude_paths/nested/ignore_me_as_well/irresponsible_module.rb +0 -0
  75. data/{spec/samples → samples}/source_with_exclude_paths/nested/uncommunicative_parameter_name.rb +0 -0
  76. data/{spec/samples → samples}/source_with_hidden_directories/.hidden/uncommunicative_method_name.rb +0 -0
  77. data/{spec/samples → samples}/source_with_hidden_directories/uncommunicative_parameter_name.rb +0 -0
  78. data/{spec/samples → samples}/source_with_non_ruby_files/gibberish +0 -0
  79. data/{spec/samples → samples}/source_with_non_ruby_files/python_source.py +0 -0
  80. data/{spec/samples → samples}/source_with_non_ruby_files/uncommunicative_parameter_name.rb +0 -0
  81. data/spec/reek/cli/application_spec.rb +1 -1
  82. data/spec/reek/cli/command/report_command_spec.rb +2 -5
  83. data/spec/reek/configuration/app_configuration_spec.rb +10 -8
  84. data/spec/reek/configuration/configuration_file_finder_spec.rb +24 -17
  85. data/spec/reek/examiner_spec.rb +84 -5
  86. data/spec/reek/report/json_report_spec.rb +1 -3
  87. data/spec/reek/report/xml_report_spec.rb +2 -3
  88. data/spec/reek/report/yaml_report_spec.rb +0 -2
  89. data/spec/reek/smells/attribute_spec.rb +21 -10
  90. data/spec/reek/smells/boolean_parameter_spec.rb +13 -12
  91. data/spec/reek/smells/class_variable_spec.rb +4 -4
  92. data/spec/reek/smells/control_parameter_spec.rb +25 -18
  93. data/spec/reek/smells/data_clump_spec.rb +5 -5
  94. data/spec/reek/smells/duplicate_method_call_spec.rb +1 -1
  95. data/spec/reek/smells/feature_envy_spec.rb +8 -2
  96. data/spec/reek/smells/irresponsible_module_spec.rb +16 -14
  97. data/spec/reek/smells/long_parameter_list_spec.rb +5 -1
  98. data/spec/reek/smells/long_yield_list_spec.rb +5 -2
  99. data/spec/reek/smells/nested_iterators_spec.rb +37 -13
  100. data/spec/reek/smells/nil_check_spec.rb +50 -53
  101. data/spec/reek/smells/prima_donna_method_spec.rb +9 -1
  102. data/spec/reek/smells/too_many_instance_variables_spec.rb +1 -1
  103. data/spec/reek/smells/too_many_methods_spec.rb +4 -4
  104. data/spec/reek/smells/too_many_statements_spec.rb +1 -1
  105. data/spec/reek/smells/uncommunicative_method_name_spec.rb +3 -3
  106. data/spec/reek/smells/uncommunicative_module_name_spec.rb +3 -3
  107. data/spec/reek/smells/uncommunicative_parameter_name_spec.rb +3 -3
  108. data/spec/reek/smells/uncommunicative_variable_name_spec.rb +3 -3
  109. data/spec/reek/smells/utility_function_spec.rb +12 -8
  110. data/spec/reek/source/source_locator_spec.rb +5 -1
  111. data/spec/reek/spec/should_reek_of_spec.rb +20 -13
  112. data/spec/reek/spec/should_reek_spec.rb +6 -11
  113. data/spec/spec_helper.rb +2 -2
  114. metadata +28 -36
  115. data/spec/samples/all_but_one_masked/clean_one.rb +0 -7
  116. data/spec/samples/all_but_one_masked/dirty.rb +0 -8
  117. data/spec/samples/all_but_one_masked/masked.reek +0 -9
  118. data/spec/samples/checkstyle.xml +0 -13
  119. data/spec/samples/clean_due_to_masking/clean_one.rb +0 -7
  120. data/spec/samples/clean_due_to_masking/clean_three.rb +0 -7
  121. data/spec/samples/clean_due_to_masking/clean_two.rb +0 -7
  122. data/spec/samples/clean_due_to_masking/dirty_one.rb +0 -7
  123. data/spec/samples/clean_due_to_masking/dirty_two.rb +0 -7
  124. data/spec/samples/clean_due_to_masking/masked.reek +0 -11
  125. data/spec/samples/configuration/full_configuration.reek +0 -9
  126. data/spec/samples/configuration/with_excluded_paths.reek +0 -4
  127. data/spec/samples/masked_by_dotfile/.reek +0 -9
  128. data/spec/samples/masked_by_dotfile/dirty.rb +0 -8
  129. data/spec/samples/no_config_file/dirty.rb +0 -8
  130. data/spec/samples/three_clean_files/clean_one.rb +0 -7
  131. data/spec/samples/three_clean_files/clean_three.rb +0 -7
  132. data/spec/samples/three_clean_files/clean_two.rb +0 -7
  133. data/spec/samples/two_smelly_files/dirty_one.rb +0 -8
  134. data/spec/samples/two_smelly_files/dirty_two.rb +0 -8
@@ -10,15 +10,14 @@ Feature:
10
10
  - get rid of the todo file
11
11
 
12
12
  Scenario: Generate a proper todo file that disables all found smells
13
- Given a smelly file called 'smelly.rb'
13
+ Given the smelly file 'smelly.rb'
14
14
  When I run reek smelly.rb
15
15
  Then the exit status indicates smells
16
16
  And it reports:
17
17
  """
18
- smelly.rb -- 3 warnings:
19
- [4, 5]:DuplicateMethodCall: Smelly#m calls @foo.bar 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
20
- [4, 5]:DuplicateMethodCall: Smelly#m calls puts @foo.bar 2 times [https://github.com/troessner/reek/blob/master/docs/Duplicate-Method-Call.md]
21
- [3]:UncommunicativeMethodName: Smelly#m has the name 'm' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Method-Name.md]
18
+ smelly.rb -- 2 warnings:
19
+ [4]:UncommunicativeMethodName: Smelly#x has the name 'x' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Method-Name.md]
20
+ [5]:UncommunicativeVariableName: Smelly#x has the variable name 'y' [https://github.com/troessner/reek/blob/master/docs/Uncommunicative-Variable-Name.md]
22
21
  """
23
22
  When I run reek --todo smelly.rb
24
23
  Then it succeeds
@@ -31,28 +30,28 @@ Feature:
31
30
  And the file ".todo.reek" should contain:
32
31
  """
33
32
  ---
34
- DuplicateMethodCall:
35
- exclude:
36
- - Smelly#m
37
33
  UncommunicativeMethodName:
38
34
  exclude:
39
- - Smelly#m
35
+ - Smelly#x
36
+ UncommunicativeVariableName:
37
+ exclude:
38
+ - Smelly#x
40
39
  """
41
40
  When I run reek -c .todo.reek smelly.rb
42
41
  Then it succeeds
43
42
 
44
43
  Scenario: Respects a configuration file
45
- Given a smelly file called 'smelly.rb'
46
- And a configuration file disabling DuplicateMethodCall called 'config.reek'
47
- When I run reek -c config.reek --todo smelly.rb
44
+ Given the smelly file 'smelly.rb'
45
+ And a configuration file 'partial_mask.reek'
46
+ When I run reek -c partial_mask.reek --todo smelly.rb
48
47
  Then it succeeds
49
48
  And a file named ".todo.reek" should exist
50
49
  And the file ".todo.reek" should contain:
51
50
  """
52
51
  ---
53
- UncommunicativeMethodName:
52
+ UncommunicativeVariableName:
54
53
  exclude:
55
- - Smelly#m
54
+ - Smelly#x
56
55
  """
57
56
 
58
57
  Scenario: Reacts appropiately when there are no smells
@@ -97,7 +97,7 @@ module Reek
97
97
  end
98
98
 
99
99
  def set_generate_todo_list_options
100
- parser.separator '\nGenerate a todo list:'
100
+ parser.separator "\nGenerate a todo list:"
101
101
  parser.on('-t', '--todo', 'Generate a todo list') do
102
102
  self.generate_todo_list = true
103
103
  end
data/lib/reek/examiner.rb CHANGED
@@ -10,8 +10,21 @@ module Reek
10
10
  #
11
11
  # @public
12
12
  #
13
- # :reek:TooManyInstanceVariables: { max_instance_variables: 6 }
13
+ # :reek:TooManyInstanceVariables: { max_instance_variables: 7 }
14
14
  class Examiner
15
+ INCOMPREHENSIBLE_SOURCE_TEMPLATE = <<-EOS.freeze
16
+ !!!
17
+ Source %s can not be processed by Reek.
18
+ This is most likely a Reek bug.
19
+ It would be great if you could report this back to the Reek team
20
+ by opening up a corresponding issue at https://github.com/troessner/reek/issues
21
+ Make sure to include the source in question, the Reek version
22
+ and the original exception below.
23
+
24
+ Original exception:
25
+ %s
26
+ !!!
27
+ EOS
15
28
  #
16
29
  # Creates an Examiner which scans the given +source+ for code smells.
17
30
  #
@@ -28,13 +41,13 @@ module Reek
28
41
  # @public
29
42
  def initialize(source,
30
43
  filter_by_smells: [],
31
- configuration: Configuration::AppConfiguration.default)
44
+ configuration: Configuration::AppConfiguration.default,
45
+ smell_repository_class: Smells::SmellRepository)
32
46
  @source = Source::SourceCode.from(source)
33
47
  @collector = CLI::WarningCollector.new
34
- @smell_types = Smells::SmellRepository.eligible_smell_types(filter_by_smells)
35
- @smell_repository = Smells::SmellRepository.new(smell_types: @smell_types,
36
- configuration: configuration.directive_for(description))
37
- run
48
+ @smell_types = smell_repository_class.eligible_smell_types(filter_by_smells)
49
+ @smell_repository = smell_repository_class.new(smell_types: @smell_types,
50
+ configuration: configuration.directive_for(description))
38
51
  end
39
52
 
40
53
  # FIXME: Should be named "origin"
@@ -51,6 +64,7 @@ module Reek
51
64
  #
52
65
  # @public
53
66
  def smells
67
+ run
54
68
  @smells ||= collector.warnings
55
69
  end
56
70
 
@@ -74,14 +88,35 @@ module Reek
74
88
 
75
89
  attr_reader :collector, :source, :smell_repository
76
90
 
91
+ # Runs the Examiner on the given source to scan for code smells
92
+ # and returns the corresponding Examiner instance.
93
+ #
94
+ # In case one of the smell detectors raises an exception we probably hit a Reek bug.
95
+ # So we catch the exception here, let the user know something went wrong
96
+ # and continue with the analysis.
97
+ #
98
+ # @return an instance of Examiner
99
+ #
100
+ # :reek:TooManyStatements: { max_statements: 6 }
77
101
  def run
78
- syntax_tree = source.syntax_tree
79
- return unless syntax_tree
102
+ @run ||= begin
103
+ syntax_tree = source.syntax_tree
104
+ return self unless syntax_tree
105
+ begin
106
+ examine syntax_tree
107
+ rescue StandardError => exception
108
+ $stderr.puts format(INCOMPREHENSIBLE_SOURCE_TEMPLATE, source.origin, exception.inspect)
109
+ else
110
+ smell_repository.report_on(collector)
111
+ end
112
+ self
113
+ end
114
+ end
115
+
116
+ def examine(syntax_tree)
80
117
  ContextBuilder.new(syntax_tree).context_tree.each do |element|
81
118
  smell_repository.examine(element)
82
119
  end
83
-
84
- smell_repository.report_on(collector)
85
120
  end
86
121
  end
87
122
  end
@@ -30,13 +30,12 @@ module Reek
30
30
  #
31
31
  # @return [Array<SmellWarning>]
32
32
  #
33
- def inspect(ctx)
34
- attributes_in(ctx).map do |attribute, line|
33
+ def sniff(ctx)
34
+ attributes_in(ctx).map do |_attribute, line|
35
35
  smell_warning(
36
36
  context: ctx,
37
37
  lines: [line],
38
- message: 'is a writable attribute',
39
- parameters: { name: attribute.to_s })
38
+ message: 'is a writable attribute')
40
39
  end
41
40
  end
42
41
 
@@ -20,7 +20,7 @@ module Reek
20
20
  # @return [Array<SmellWarning>]
21
21
  #
22
22
  # :reek:FeatureEnvy
23
- def inspect(ctx)
23
+ def sniff(ctx)
24
24
  ctx.default_assignments.select do |_param, value|
25
25
  [:true, :false].include?(value.type)
26
26
  end.map do |parameter, _value|
@@ -28,7 +28,7 @@ module Reek
28
28
  context: ctx,
29
29
  lines: [ctx.exp.line],
30
30
  message: "has boolean parameter '#{parameter}'",
31
- parameters: { name: parameter.to_s })
31
+ parameters: { parameter: parameter.to_s })
32
32
  end
33
33
  end
34
34
  end
@@ -24,7 +24,7 @@ module Reek
24
24
  #
25
25
  # @return [Array<SmellWarning>]
26
26
  #
27
- def inspect(ctx)
27
+ def sniff(ctx)
28
28
  class_variables_in(ctx.exp).map do |variable, lines|
29
29
  smell_warning(
30
30
  context: ctx,
@@ -50,14 +50,14 @@ module Reek
50
50
  # @return [Array<SmellWarning>]
51
51
  #
52
52
  # :reek:FeatureEnvy
53
- def inspect(ctx)
53
+ def sniff(ctx)
54
54
  ControlParameterCollector.new(ctx).control_parameters.map do |control_parameter|
55
- name = control_parameter.name.to_s
55
+ argument = control_parameter.name.to_s
56
56
  smell_warning(
57
57
  context: ctx,
58
58
  lines: control_parameter.lines,
59
- message: "is controlled by argument #{name}",
60
- parameters: { name: name })
59
+ message: "is controlled by argument #{argument}",
60
+ parameters: { argument: argument })
61
61
  end
62
62
  end
63
63
 
@@ -51,7 +51,7 @@ module Reek
51
51
  # @return [Array<SmellWarning>]
52
52
  #
53
53
  # :reek:FeatureEnvy
54
- def inspect(ctx)
54
+ def sniff(ctx)
55
55
  max_copies = value(MAX_COPIES_KEY, ctx)
56
56
  min_clump_size = value(MIN_CLUMP_SIZE_KEY, ctx)
57
57
  MethodGroup.new(ctx, min_clump_size, max_copies).clumps.map do |clump, methods|
@@ -63,8 +63,7 @@ module Reek
63
63
  "to #{methods_length} methods",
64
64
  parameters: {
65
65
  parameters: clump.map(&:to_s),
66
- count: methods_length,
67
- methods: methods.map(&:name)
66
+ count: methods_length
68
67
  })
69
68
  end
70
69
  end
@@ -43,7 +43,7 @@ module Reek
43
43
  #
44
44
  # :reek:FeatureEnvy
45
45
  # :reek:DuplicateMethodCall: { max_calls: 2 }
46
- def inspect(ctx)
46
+ def sniff(ctx)
47
47
  max_allowed_calls = value(MAX_ALLOWED_CALLS_KEY, ctx)
48
48
  allow_calls = value(ALLOW_CALLS_KEY, ctx)
49
49
 
@@ -42,14 +42,14 @@ module Reek
42
42
  #
43
43
  # @return [Array<SmellWarning>]
44
44
  #
45
- def inspect(ctx)
45
+ def sniff(ctx)
46
46
  return [] unless ctx.references_self?
47
47
  envious_receivers(ctx).map do |name, lines|
48
48
  smell_warning(
49
49
  context: ctx,
50
50
  lines: lines,
51
51
  message: "refers to #{name} more than self (maybe move it to another class?)",
52
- parameters: { name: name.to_s, count: lines.size })
52
+ parameters: { name: name.to_s })
53
53
  end
54
54
  end
55
55
 
@@ -19,14 +19,13 @@ module Reek
19
19
  #
20
20
  # @return [Array<SmellWarning>]
21
21
  #
22
- def inspect(ctx)
22
+ def sniff(ctx)
23
23
  return [] if descriptive?(ctx) || ctx.namespace_module?
24
24
  expression = ctx.exp
25
25
  [smell_warning(
26
26
  context: ctx,
27
27
  lines: [expression.line],
28
- message: 'has no descriptive comment',
29
- parameters: { name: expression.name })]
28
+ message: 'has no descriptive comment')]
30
29
  end
31
30
 
32
31
  private
@@ -33,7 +33,7 @@ module Reek
33
33
  #
34
34
  # @return [Array<SmellWarning>]
35
35
  #
36
- def inspect(ctx)
36
+ def sniff(ctx)
37
37
  max_allowed_params = value(MAX_ALLOWED_PARAMS_KEY, ctx)
38
38
  exp = ctx.exp
39
39
  count = exp.arg_names.length
@@ -26,7 +26,7 @@ module Reek
26
26
  #
27
27
  # :reek:FeatureEnvy
28
28
  # :reek:DuplicateMethodCall: { max_calls: 2 }
29
- def inspect(ctx)
29
+ def sniff(ctx)
30
30
  max_allowed_params = value(MAX_ALLOWED_PARAMS_KEY, ctx)
31
31
  ctx.local_nodes(:yield).select do |yield_node|
32
32
  yield_node.args.length > max_allowed_params
@@ -21,7 +21,7 @@ module Reek
21
21
  # @return [Array<SmellWarning>]
22
22
  #
23
23
  # :reek:FeatureEnvy
24
- def inspect(ctx)
24
+ def sniff(ctx)
25
25
  ctx.local_nodes(:def) do |node|
26
26
  if node.name.to_s == 'initialize'
27
27
  return [
@@ -41,7 +41,7 @@ module Reek
41
41
  #
42
42
  # @return [Array<SmellWarning>]
43
43
  #
44
- def inspect(ctx)
44
+ def sniff(ctx)
45
45
  configure_ignore_iterators ctx
46
46
  violations = find_violations ctx
47
47
 
@@ -51,7 +51,7 @@ module Reek
51
51
  context: ctx,
52
52
  lines: lines,
53
53
  message: "contains iterators nested #{depth} deep",
54
- parameters: { name: ctx.full_name, count: depth })
54
+ parameters: { depth: depth })
55
55
  end
56
56
  end
57
57
 
@@ -9,7 +9,7 @@ module Reek
9
9
  #
10
10
  # See {file:docs/Nil-Check.md} for details.
11
11
  class NilCheck < SmellDetector
12
- def inspect(ctx)
12
+ def sniff(ctx)
13
13
  call_node_finder = NodeFinder.new(ctx, :send, NilCallNodeDetector)
14
14
  case_node_finder = NodeFinder.new(ctx, :when, NilWhenNodeDetector)
15
15
  smelly_nodes = call_node_finder.smelly_nodes + case_node_finder.smelly_nodes
@@ -29,7 +29,7 @@ module Reek
29
29
  [:class]
30
30
  end
31
31
 
32
- def inspect(ctx)
32
+ def sniff(ctx)
33
33
  ctx.node_instance_methods.map do |method_sexp|
34
34
  check_for_smells(method_sexp, ctx)
35
35
  end.compact
@@ -38,6 +38,7 @@ module Reek
38
38
  private
39
39
 
40
40
  # :reek:FeatureEnvy
41
+ # :reek:TooManyStatements: { max_statements: 6 }
41
42
  def check_for_smells(method_sexp, ctx)
42
43
  return unless method_sexp.ends_with_bang?
43
44
 
@@ -47,10 +48,12 @@ module Reek
47
48
 
48
49
  return if version_without_bang
49
50
 
51
+ name = method_sexp.name
50
52
  smell_warning(
51
53
  context: ctx,
52
54
  lines: [ctx.exp.line],
53
- message: "has prima donna method `#{method_sexp.name}`")
55
+ message: "has prima donna method `#{name}`",
56
+ parameters: { name: name })
54
57
  end
55
58
  end
56
59
  end
@@ -48,7 +48,7 @@ module Reek
48
48
  #
49
49
  # :reek:TooManyStatements: { max_statements: 6 }
50
50
  # :reek:DuplicateMethodCall: { max_calls: 2 }
51
- def inspect(ctx)
51
+ def sniff(ctx)
52
52
  max_identical_ifs = value(MAX_IDENTICAL_IFS_KEY, ctx)
53
53
  conditional_counts(ctx).select do |_key, lines|
54
54
  lines.length > max_identical_ifs
@@ -44,7 +44,7 @@ module Reek
44
44
  return unless enabled_for?(context)
45
45
  return if exception?(context)
46
46
 
47
- self.smells_found = smells_found + inspect(context)
47
+ self.smells_found = smells_found + sniff(context)
48
48
  end
49
49
 
50
50
  def report_on(collector)
@@ -45,7 +45,7 @@ module Reek
45
45
 
46
46
  # @public
47
47
  def eql?(other)
48
- (self <=> other) == 0
48
+ (self <=> other).zero?
49
49
  end
50
50
 
51
51
  def report_on(listener)
@@ -53,12 +53,13 @@ module Reek
53
53
  end
54
54
 
55
55
  # @public
56
- def yaml_hash
56
+ def to_hash
57
57
  stringified_params = Hash[parameters.map { |key, val| [key.to_s, val] }]
58
- core_yaml_hash.
59
- merge(stringified_params)
58
+ base_hash.merge(stringified_params)
60
59
  end
61
60
 
61
+ alias yaml_hash to_hash
62
+
62
63
  def base_message
63
64
  "#{smell_type}: #{context} #{message}"
64
65
  end
@@ -75,7 +76,7 @@ module Reek
75
76
 
76
77
  private
77
78
 
78
- def core_yaml_hash
79
+ def base_hash
79
80
  {
80
81
  'context' => context,
81
82
  'lines' => lines,
@@ -26,17 +26,17 @@ module Reek
26
26
  # class Foo < Bar; end;
27
27
  #
28
28
  # @return [Array<SmellWarning>]
29
- def inspect(ctx)
29
+ def sniff(ctx)
30
30
  superclass = ctx.exp.superclass
31
31
 
32
32
  return [] unless superclass
33
33
 
34
- inspect_superclass(ctx, superclass.name)
34
+ sniff_superclass(ctx, superclass.name)
35
35
  end
36
36
 
37
37
  private
38
38
 
39
- def inspect_superclass(ctx, superclass_name)
39
+ def sniff_superclass(ctx, superclass_name)
40
40
  return [] unless CORE_CLASSES.include?(superclass_name)
41
41
 
42
42
  [build_smell_warning(ctx, superclass_name)]