reek 3.11 → 4.0.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -0
  3. data/.travis.yml +0 -1
  4. data/CHANGELOG.md +13 -1
  5. data/README.md +0 -1
  6. data/bin/code_climate_reek +1 -0
  7. data/bin/reek +1 -0
  8. data/docs/API.md +2 -2
  9. data/docs/RSpec-matchers.md +4 -7
  10. data/features/reports/json.feature +0 -4
  11. data/features/reports/yaml.feature +4 -8
  12. data/lib/reek.rb +1 -0
  13. data/lib/reek/ast/ast_node_class_map.rb +1 -0
  14. data/lib/reek/ast/node.rb +1 -0
  15. data/lib/reek/ast/object_refs.rb +2 -1
  16. data/lib/reek/ast/reference_collector.rb +1 -0
  17. data/lib/reek/ast/sexp_extensions.rb +1 -0
  18. data/lib/reek/ast/sexp_extensions/arguments.rb +1 -0
  19. data/lib/reek/ast/sexp_extensions/attribute_assignments.rb +1 -0
  20. data/lib/reek/ast/sexp_extensions/block.rb +1 -0
  21. data/lib/reek/ast/sexp_extensions/case.rb +1 -0
  22. data/lib/reek/ast/sexp_extensions/constant.rb +1 -0
  23. data/lib/reek/ast/sexp_extensions/if.rb +1 -0
  24. data/lib/reek/ast/sexp_extensions/literal.rb +1 -0
  25. data/lib/reek/ast/sexp_extensions/logical_operators.rb +1 -0
  26. data/lib/reek/ast/sexp_extensions/methods.rb +1 -0
  27. data/lib/reek/ast/sexp_extensions/module.rb +1 -0
  28. data/lib/reek/ast/sexp_extensions/nested_assignables.rb +1 -0
  29. data/lib/reek/ast/sexp_extensions/self.rb +1 -0
  30. data/lib/reek/ast/sexp_extensions/send.rb +1 -0
  31. data/lib/reek/ast/sexp_extensions/super.rb +1 -0
  32. data/lib/reek/ast/sexp_extensions/symbols.rb +1 -0
  33. data/lib/reek/ast/sexp_extensions/variables.rb +1 -0
  34. data/lib/reek/ast/sexp_extensions/when.rb +1 -0
  35. data/lib/reek/ast/sexp_extensions/yield.rb +1 -0
  36. data/lib/reek/cli/application.rb +1 -0
  37. data/lib/reek/cli/command/base_command.rb +1 -0
  38. data/lib/reek/cli/command/report_command.rb +2 -1
  39. data/lib/reek/cli/command/todo_list_command.rb +2 -1
  40. data/lib/reek/cli/input.rb +1 -0
  41. data/lib/reek/cli/option_interpreter.rb +1 -0
  42. data/lib/reek/cli/options.rb +1 -0
  43. data/lib/reek/cli/silencer.rb +1 -0
  44. data/lib/reek/cli/warning_collector.rb +1 -0
  45. data/lib/reek/code_comment.rb +1 -0
  46. data/lib/reek/configuration/app_configuration.rb +1 -0
  47. data/lib/reek/configuration/configuration_file_finder.rb +1 -0
  48. data/lib/reek/configuration/configuration_validator.rb +1 -0
  49. data/lib/reek/configuration/default_directive.rb +1 -0
  50. data/lib/reek/configuration/directory_directives.rb +1 -0
  51. data/lib/reek/configuration/excluded_paths.rb +1 -0
  52. data/lib/reek/context/attribute_context.rb +1 -0
  53. data/lib/reek/context/class_context.rb +1 -0
  54. data/lib/reek/context/code_context.rb +1 -0
  55. data/lib/reek/context/ghost_context.rb +1 -0
  56. data/lib/reek/context/method_context.rb +1 -0
  57. data/lib/reek/context/module_context.rb +1 -0
  58. data/lib/reek/context/root_context.rb +1 -0
  59. data/lib/reek/context/send_context.rb +1 -0
  60. data/lib/reek/context/singleton_attribute_context.rb +1 -0
  61. data/lib/reek/context/singleton_method_context.rb +1 -0
  62. data/lib/reek/context/statement_counter.rb +1 -0
  63. data/lib/reek/context/visibility_tracker.rb +3 -2
  64. data/lib/reek/context_builder.rb +1 -0
  65. data/lib/reek/examiner.rb +2 -1
  66. data/lib/reek/rake/task.rb +1 -0
  67. data/lib/reek/report.rb +1 -0
  68. data/lib/reek/report/code_climate/code_climate_formatter.rb +2 -2
  69. data/lib/reek/report/formatter.rb +1 -0
  70. data/lib/reek/report/heading_formatter.rb +1 -0
  71. data/lib/reek/report/location_formatter.rb +1 -0
  72. data/lib/reek/report/report.rb +3 -3
  73. data/lib/reek/smells.rb +1 -0
  74. data/lib/reek/smells/attribute.rb +1 -0
  75. data/lib/reek/smells/boolean_parameter.rb +1 -4
  76. data/lib/reek/smells/class_variable.rb +1 -0
  77. data/lib/reek/smells/control_parameter.rb +7 -4
  78. data/lib/reek/smells/data_clump.rb +1 -0
  79. data/lib/reek/smells/duplicate_method_call.rb +5 -4
  80. data/lib/reek/smells/feature_envy.rb +1 -4
  81. data/lib/reek/smells/irresponsible_module.rb +1 -0
  82. data/lib/reek/smells/long_parameter_list.rb +1 -0
  83. data/lib/reek/smells/long_yield_list.rb +1 -4
  84. data/lib/reek/smells/module_initialize.rb +1 -0
  85. data/lib/reek/smells/nested_iterators.rb +2 -1
  86. data/lib/reek/smells/nil_check.rb +3 -4
  87. data/lib/reek/smells/prima_donna_method.rb +1 -0
  88. data/lib/reek/smells/repeated_conditional.rb +1 -4
  89. data/lib/reek/smells/smell_configuration.rb +1 -0
  90. data/lib/reek/smells/smell_detector.rb +2 -13
  91. data/lib/reek/smells/smell_repository.rb +1 -0
  92. data/lib/reek/smells/smell_warning.rb +4 -6
  93. data/lib/reek/smells/too_many_instance_variables.rb +1 -4
  94. data/lib/reek/smells/too_many_methods.rb +1 -4
  95. data/lib/reek/smells/too_many_statements.rb +1 -4
  96. data/lib/reek/smells/uncommunicative_method_name.rb +2 -5
  97. data/lib/reek/smells/uncommunicative_module_name.rb +2 -6
  98. data/lib/reek/smells/uncommunicative_parameter_name.rb +3 -6
  99. data/lib/reek/smells/uncommunicative_variable_name.rb +1 -4
  100. data/lib/reek/smells/unused_parameters.rb +1 -4
  101. data/lib/reek/smells/unused_private_method.rb +1 -0
  102. data/lib/reek/smells/utility_function.rb +1 -4
  103. data/lib/reek/source/source_code.rb +2 -1
  104. data/lib/reek/source/source_locator.rb +1 -0
  105. data/lib/reek/spec.rb +16 -23
  106. data/lib/reek/spec/should_reek.rb +3 -2
  107. data/lib/reek/spec/should_reek_of.rb +18 -15
  108. data/lib/reek/spec/should_reek_only_of.rb +6 -5
  109. data/lib/reek/spec/smell_matcher.rb +3 -7
  110. data/lib/reek/tree_dresser.rb +1 -0
  111. data/lib/reek/version.rb +2 -1
  112. data/reek.gemspec +1 -1
  113. data/spec/reek/examiner_spec.rb +8 -4
  114. data/spec/reek/report/code_climate_formatter_spec.rb +1 -1
  115. data/spec/reek/report/code_climate_report_spec.rb +2 -2
  116. data/spec/reek/report/html_report_spec.rb +1 -6
  117. data/spec/reek/report/json_report_spec.rb +0 -4
  118. data/spec/reek/report/yaml_report_spec.rb +0 -4
  119. data/spec/reek/smells/data_clump_spec.rb +2 -2
  120. data/spec/reek/smells/feature_envy_spec.rb +3 -3
  121. data/spec/reek/smells/nested_iterators_spec.rb +0 -1
  122. data/spec/reek/smells/prima_donna_method_spec.rb +0 -1
  123. data/spec/reek/smells/smell_detector_shared.rb +1 -5
  124. data/spec/reek/smells/too_many_methods_spec.rb +0 -1
  125. data/spec/reek/smells/uncommunicative_module_name_spec.rb +0 -1
  126. data/spec/reek/smells/unused_private_method_spec.rb +6 -4
  127. data/spec/reek/smells/utility_function_spec.rb +1 -1
  128. data/spec/reek/spec/should_reek_of_spec.rb +7 -3
  129. data/spec/reek/spec/smell_matcher_spec.rb +0 -4
  130. metadata +6 -6
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative '../ast/node'
2
3
  require_relative 'smell_detector'
3
4
  require_relative 'smell_warning'
@@ -30,10 +31,6 @@ module Reek
30
31
  MAX_IDENTICAL_IFS_KEY = 'max_ifs'.freeze
31
32
  DEFAULT_MAX_IFS = 2
32
33
 
33
- def self.smell_category
34
- 'SimulatedPolymorphism'
35
- end
36
-
37
34
  BLOCK_GIVEN_CONDITION = ::Parser::AST::Node.new(:send, [nil, :block_given?])
38
35
 
39
36
  def self.contexts # :nodoc:
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Reek
2
3
  module Smells
3
4
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'set'
2
3
  require_relative 'smell_configuration'
3
4
 
@@ -31,10 +32,6 @@ module Reek
31
32
  @smells_found = []
32
33
  end
33
34
 
34
- def smell_category
35
- self.class.smell_category
36
- end
37
-
38
35
  def smell_type
39
36
  self.class.smell_type
40
37
  end
@@ -88,16 +85,8 @@ module Reek
88
85
  end
89
86
 
90
87
  class << self
91
- def smell_category
92
- @smell_category ||= default_smell_category
93
- end
94
-
95
88
  def smell_type
96
- @smell_type ||= default_smell_category
97
- end
98
-
99
- def default_smell_category
100
- name.split(/::/)[-1]
89
+ @smell_type ||= name.split(/::/).last
101
90
  end
102
91
 
103
92
  def contexts
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative '../smells'
2
3
  require_relative 'smell_detector'
3
4
  require_relative '../configuration/app_configuration'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'forwardable'
2
3
 
3
4
  module Reek
@@ -15,17 +16,15 @@ module Reek
15
16
 
16
17
  # @public
17
18
  attr_reader :context, :lines, :message, :parameters, :smell_detector, :source
18
- def_delegators :smell_detector, :smell_category, :smell_type
19
+ def_delegators :smell_detector, :smell_type
19
20
 
20
21
  # @note When using Reek's public API, you should not create SmellWarning
21
22
  # objects yourself. This is why the initializer is not part of the
22
23
  # public API.
23
24
  #
24
- # FIXME: switch to required kwargs when dropping Ruby 2.0 compatibility
25
- #
26
25
  # :reek:LongParameterList: { max_params: 6 }
27
- def initialize(smell_detector, context: '', lines: raise, message: raise,
28
- source: raise, parameters: {})
26
+ def initialize(smell_detector, context: '', lines:, message:,
27
+ source:, parameters: {})
29
28
  @smell_detector = smell_detector
30
29
  @source = source
31
30
  @context = context.to_s
@@ -77,7 +76,6 @@ module Reek
77
76
  'context' => context,
78
77
  'lines' => lines,
79
78
  'message' => message,
80
- 'smell_category' => smell_category,
81
79
  'smell_type' => smell_type,
82
80
  'source' => source
83
81
  }
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
 
@@ -17,10 +18,6 @@ module Reek
17
18
  MAX_ALLOWED_IVARS_KEY = 'max_instance_variables'.freeze
18
19
  DEFAULT_MAX_IVARS = 4
19
20
 
20
- def self.smell_category
21
- 'LargeClass'
22
- end
23
-
24
21
  def self.contexts
25
22
  [:class]
26
23
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
 
@@ -19,10 +20,6 @@ module Reek
19
20
  MAX_ALLOWED_METHODS_KEY = 'max_methods'.freeze
20
21
  DEFAULT_MAX_METHODS = 15
21
22
 
22
- def self.smell_category
23
- 'LargeClass'
24
- end
25
-
26
23
  def self.contexts
27
24
  [:class]
28
25
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
 
@@ -15,10 +16,6 @@ module Reek
15
16
  MAX_ALLOWED_STATEMENTS_KEY = 'max_statements'.freeze
16
17
  DEFAULT_MAX_STATEMENTS = 5
17
18
 
18
- def self.smell_category
19
- 'LongMethod'
20
- end
21
-
22
19
  def self.default_config
23
20
  super.merge(
24
21
  MAX_ALLOWED_STATEMENTS_KEY => DEFAULT_MAX_STATEMENTS,
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
 
@@ -23,10 +24,6 @@ module Reek
23
24
  DEFAULT_REJECT_PATTERNS = [/^[a-z]$/, /[0-9]$/, /[A-Z]/].freeze
24
25
  DEFAULT_ACCEPT_NAMES = [].freeze
25
26
 
26
- def self.smell_category
27
- 'UncommunicativeName'
28
- end
29
-
30
27
  def self.default_config
31
28
  super.merge(
32
29
  REJECT_KEY => DEFAULT_REJECT_PATTERNS,
@@ -52,7 +49,7 @@ module Reek
52
49
 
53
50
  private
54
51
 
55
- def acceptable_name?(name: raise, context: raise)
52
+ def acceptable_name?(name:, context:)
56
53
  accept_names(context).any? { |accept_name| name == accept_name } ||
57
54
  reject_patterns(context).none? { |pattern| name.match pattern }
58
55
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
 
@@ -29,10 +30,6 @@ module Reek
29
30
  ACCEPT_KEY = 'accept'.freeze
30
31
  DEFAULT_ACCEPT_NAMES = [].freeze
31
32
 
32
- def self.smell_category
33
- 'UncommunicativeName'
34
- end
35
-
36
33
  def self.default_config
37
34
  super.merge(
38
35
  REJECT_KEY => DEFAULT_REJECT_PATTERNS,
@@ -67,9 +64,8 @@ module Reek
67
64
 
68
65
  private
69
66
 
70
- # FIXME: switch to required kwargs when dropping Ruby 2.0 compatibility
71
67
  # :reek:ControlParameter
72
- def acceptable_name?(context: raise, module_name: raise, fully_qualified_name: raise)
68
+ def acceptable_name?(context:, module_name:, fully_qualified_name:)
73
69
  accept_names(context).any? { |accept_name| fully_qualified_name == accept_name } ||
74
70
  reject_patterns(context).none? { |pattern| module_name.match pattern }
75
71
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
 
@@ -24,10 +25,6 @@ module Reek
24
25
  ACCEPT_KEY = 'accept'.freeze
25
26
  DEFAULT_ACCEPT_NAMES = [].freeze
26
27
 
27
- def self.smell_category
28
- 'UncommunicativeName'
29
- end
30
-
31
28
  def self.default_config
32
29
  super.merge(
33
30
  REJECT_KEY => DEFAULT_REJECT_PATTERNS,
@@ -56,11 +53,11 @@ module Reek
56
53
 
57
54
  private
58
55
 
59
- def uncommunicative_parameter_name?(name: raise, context: raise)
56
+ def uncommunicative_parameter_name?(name:, context:)
60
57
  !acceptable_name?(name: name, context: context) && context.uses_param?(name)
61
58
  end
62
59
 
63
- def acceptable_name?(name: raise, context: raise)
60
+ def acceptable_name?(name:, context:)
64
61
  accept_names(context).any? { |accept_name| name == accept_name } ||
65
62
  reject_patterns(context).none? { |pattern| name.match pattern }
66
63
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
 
@@ -31,10 +32,6 @@ module Reek
31
32
  ACCEPT_KEY = 'accept'.freeze
32
33
  DEFAULT_ACCEPT_SET = ['_'].freeze
33
34
 
34
- def self.smell_category
35
- 'UncommunicativeName'
36
- end
37
-
38
35
  def self.default_config
39
36
  super.merge(
40
37
  REJECT_KEY => DEFAULT_REJECT_SET,
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
 
@@ -8,10 +9,6 @@ module Reek
8
9
  #
9
10
  # See {file:docs/Unused-Parameters.md} for details.
10
11
  class UnusedParameters < SmellDetector
11
- def self.smell_category
12
- 'UnusedCode'
13
- end
14
-
15
12
  #
16
13
  # Checks whether the given method has any unused parameters.
17
14
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'smell_detector'
2
3
  require_relative 'smell_warning'
3
4
  require_relative '../context/method_context'
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative '../ast/reference_collector'
2
3
  require_relative 'smell_detector'
3
4
  require_relative 'smell_warning'
@@ -40,10 +41,6 @@ module Reek
40
41
  PUBLIC_METHODS_ONLY_KEY = 'public_methods_only'.freeze
41
42
  PUBLIC_METHODS_ONLY_DEFAULT = false
42
43
 
43
- def self.smell_category
44
- 'LowCohesion'
45
- end
46
-
47
44
  class << self
48
45
  def contexts # :nodoc:
49
46
  [:def]
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative '../cli/silencer'
2
3
  Reek::CLI::Silencer.silently do
3
4
  require 'parser/ruby23'
@@ -21,7 +22,7 @@ module Reek
21
22
  # code - Ruby code as String
22
23
  # origin - 'STDIN', 'string' or a filepath as String
23
24
  # parser - the parser to use for generating AST's out of the given source
24
- def initialize(code: raise, origin: raise, parser: Parser::Ruby23)
25
+ def initialize(code:, origin:, parser: Parser::Ruby23)
25
26
  @source = code
26
27
  @origin = origin
27
28
  @parser = parser
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'find'
2
3
  require 'pathname'
3
4
 
data/lib/reek/spec.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative 'spec/should_reek'
2
3
  require_relative 'spec/should_reek_of'
3
4
  require_relative 'spec/should_reek_only_of'
@@ -42,19 +43,13 @@ module Reek
42
43
  # @public
43
44
  module Spec
44
45
  #
45
- # Checks the target source code for instances of "smell category"
46
+ # Checks the target source code for instances of "smell type"
46
47
  # and returns true only if it can find one of them that matches.
47
48
  #
48
- # Remember that this includes our "smell types" as well. So it could be the
49
- # "smell type" UtilityFunction, which is represented as a concrete class
50
- # in Reek but it could also be "Duplication" which is a "smell categgory".
51
- #
52
- # In theory you could pass many different types of input here:
49
+ # You could pass many different types of input here:
53
50
  # - :UtilityFunction
54
51
  # - "UtilityFunction"
55
- # - UtilityFunction (this works in our specs because we tend to do "include Reek:Smells")
56
- # - Reek::Smells::UtilityFunction (the right way if you really want to pass a class)
57
- # - "Duplication" or :Duplication which is an abstract "smell category"
52
+ # - Reek::Smells::UtilityFunction
58
53
  #
59
54
  # It is recommended to pass this as a symbol like :UtilityFunction. However we don't
60
55
  # enforce this.
@@ -67,47 +62,45 @@ module Reek
67
62
  # raise an ArgumentError to give you a hint that you passed something that doesn't make
68
63
  # much sense.
69
64
  #
70
- # smell_category - The "smell category" or "smell_type" we check for.
71
- # smells_details - A hash containing "smell warning" parameters
72
- #
73
- # Examples
65
+ # @param smell_type [Symbol, String, Class] The "smell type" to check for.
66
+ # @param smells_details [Hash] A hash containing "smell warning" parameters
74
67
  #
75
- # Without smell_details:
68
+ # @example Without smell_details
76
69
  #
77
70
  # reek_of(:FeatureEnvy)
78
71
  # reek_of(Reek::Smells::UtilityFunction)
79
72
  #
80
- # With smell_details:
73
+ # @example With smell_details
81
74
  #
82
- # reek_of(UncommunicativeParameterName, name: 'x2')
83
- # reek_of(DataClump, count: 3)
75
+ # reek_of(:UncommunicativeParameterName, name: 'x2')
76
+ # reek_of(:DataClump, count: 3)
84
77
  #
85
- # Examples from a real spec
78
+ # @example From a real spec
86
79
  #
87
80
  # expect(src).to reek_of(Reek::Smells::DuplicateMethodCall, name: '@other.thing')
88
81
  #
89
82
  # @public
90
83
  #
91
84
  # :reek:UtilityFunction
92
- def reek_of(smell_category,
85
+ def reek_of(smell_type,
93
86
  smell_details = {},
94
87
  configuration = Configuration::AppConfiguration.default)
95
- ShouldReekOf.new(smell_category, smell_details, configuration)
88
+ ShouldReekOf.new(smell_type, smell_details, configuration)
96
89
  end
97
90
 
98
91
  #
99
92
  # See the documentaton for "reek_of".
100
93
  #
101
94
  # Notable differences to reek_of:
102
- # 1.) "reek_of" doesn't mind if there are other smells of a different category.
95
+ # 1.) "reek_of" doesn't mind if there are other smells of a different type.
103
96
  # "reek_only_of" will fail in that case.
104
97
  # 2.) "reek_only_of" doesn't support the additional smell_details hash.
105
98
  #
106
99
  # @public
107
100
  #
108
101
  # :reek:UtilityFunction
109
- def reek_only_of(smell_category, configuration = Configuration::AppConfiguration.default)
110
- ShouldReekOnlyOf.new(smell_category, configuration)
102
+ def reek_only_of(smell_type, configuration = Configuration::AppConfiguration.default)
103
+ ShouldReekOnlyOf.new(smell_type, configuration)
111
104
  end
112
105
 
113
106
  #
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative '../examiner'
2
3
  require_relative '../report/formatter'
3
4
 
@@ -11,8 +12,8 @@ module Reek
11
12
  @configuration = configuration
12
13
  end
13
14
 
14
- def matches?(actual)
15
- self.examiner = Examiner.new(actual, configuration: configuration)
15
+ def matches?(source)
16
+ self.examiner = Examiner.new(source, configuration: configuration)
16
17
  examiner.smelly?
17
18
  end
18
19
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require_relative '../examiner'
2
3
  require_relative 'smell_matcher'
3
4
 
@@ -10,23 +11,23 @@ module Reek
10
11
  class ShouldReekOf
11
12
  attr_reader :failure_message, :failure_message_when_negated
12
13
 
13
- def initialize(smell_category,
14
+ def initialize(smell_type_or_class,
14
15
  smell_details = {},
15
16
  configuration = Configuration::AppConfiguration.default)
16
- @smell_category = normalize smell_category
17
+ @smell_type = normalize smell_type_or_class
17
18
  @smell_details = smell_details
18
19
  @configuration = configuration
19
20
  end
20
21
 
21
- def matches?(actual)
22
- self.examiner = Examiner.new(actual, configuration: configuration)
22
+ def matches?(source)
23
+ self.examiner = Examiner.new(source, configuration: configuration)
23
24
  set_failure_messages
24
25
  matching_smell_types? && matching_smell_details?
25
26
  end
26
27
 
27
28
  private
28
29
 
29
- attr_reader :configuration, :smell_category, :smell_details
30
+ attr_reader :configuration, :smell_type, :smell_details
30
31
  attr_writer :failure_message, :failure_message_when_negated
31
32
  attr_accessor :examiner
32
33
 
@@ -41,7 +42,7 @@ module Reek
41
42
 
42
43
  def matching_smell_types
43
44
  @matching_smell_types ||= smell_matchers.
44
- select { |it| it.matches_smell_type?(smell_category) }
45
+ select { |it| it.matches_smell_type?(smell_type) }
45
46
  end
46
47
 
47
48
  def smell_matchers
@@ -57,17 +58,17 @@ module Reek
57
58
  end
58
59
 
59
60
  def set_failure_messages_for_smell_type
60
- self.failure_message = "Expected #{origin} to reek of #{smell_category}, "\
61
+ self.failure_message = "Expected #{origin} to reek of #{smell_type}, "\
61
62
  'but it didn\'t'
62
63
  self.failure_message_when_negated = "Expected #{origin} not to reek "\
63
- "of #{smell_category}, but it did"
64
+ "of #{smell_type}, but it did"
64
65
  end
65
66
 
66
67
  def set_failure_messages_for_smell_details
67
- self.failure_message = "Expected #{origin} to reek of #{smell_category} "\
68
+ self.failure_message = "Expected #{origin} to reek of #{smell_type} "\
68
69
  "(which it did) with smell details #{smell_details}, which it didn't"
69
70
  self.failure_message_when_negated = "Expected #{origin} not to reek of "\
70
- "#{smell_category} with smell details #{smell_details}, but it did"
71
+ "#{smell_type} with smell details #{smell_details}, but it did"
71
72
  end
72
73
 
73
74
  def origin
@@ -75,11 +76,13 @@ module Reek
75
76
  end
76
77
 
77
78
  # :reek:UtilityFunction
78
- def normalize(smell_category_or_type)
79
- # In theory, users can give us many different types of input (see the documentation for
80
- # reek_of below), however we're basically ignoring all of those subleties and just
81
- # return a string with the prepending namespace stripped.
82
- smell_category_or_type.to_s.split(/::/)[-1]
79
+ def normalize(smell_type_or_class)
80
+ case smell_type_or_class
81
+ when Class
82
+ smell_type_or_class.smell_type
83
+ else
84
+ smell_type_or_class.to_s
85
+ end
83
86
  end
84
87
  end
85
88
  end