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.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -0
- data/.travis.yml +0 -1
- data/CHANGELOG.md +13 -1
- data/README.md +0 -1
- data/bin/code_climate_reek +1 -0
- data/bin/reek +1 -0
- data/docs/API.md +2 -2
- data/docs/RSpec-matchers.md +4 -7
- data/features/reports/json.feature +0 -4
- data/features/reports/yaml.feature +4 -8
- data/lib/reek.rb +1 -0
- data/lib/reek/ast/ast_node_class_map.rb +1 -0
- data/lib/reek/ast/node.rb +1 -0
- data/lib/reek/ast/object_refs.rb +2 -1
- data/lib/reek/ast/reference_collector.rb +1 -0
- data/lib/reek/ast/sexp_extensions.rb +1 -0
- data/lib/reek/ast/sexp_extensions/arguments.rb +1 -0
- data/lib/reek/ast/sexp_extensions/attribute_assignments.rb +1 -0
- data/lib/reek/ast/sexp_extensions/block.rb +1 -0
- data/lib/reek/ast/sexp_extensions/case.rb +1 -0
- data/lib/reek/ast/sexp_extensions/constant.rb +1 -0
- data/lib/reek/ast/sexp_extensions/if.rb +1 -0
- data/lib/reek/ast/sexp_extensions/literal.rb +1 -0
- data/lib/reek/ast/sexp_extensions/logical_operators.rb +1 -0
- data/lib/reek/ast/sexp_extensions/methods.rb +1 -0
- data/lib/reek/ast/sexp_extensions/module.rb +1 -0
- data/lib/reek/ast/sexp_extensions/nested_assignables.rb +1 -0
- data/lib/reek/ast/sexp_extensions/self.rb +1 -0
- data/lib/reek/ast/sexp_extensions/send.rb +1 -0
- data/lib/reek/ast/sexp_extensions/super.rb +1 -0
- data/lib/reek/ast/sexp_extensions/symbols.rb +1 -0
- data/lib/reek/ast/sexp_extensions/variables.rb +1 -0
- data/lib/reek/ast/sexp_extensions/when.rb +1 -0
- data/lib/reek/ast/sexp_extensions/yield.rb +1 -0
- data/lib/reek/cli/application.rb +1 -0
- data/lib/reek/cli/command/base_command.rb +1 -0
- data/lib/reek/cli/command/report_command.rb +2 -1
- data/lib/reek/cli/command/todo_list_command.rb +2 -1
- data/lib/reek/cli/input.rb +1 -0
- data/lib/reek/cli/option_interpreter.rb +1 -0
- data/lib/reek/cli/options.rb +1 -0
- data/lib/reek/cli/silencer.rb +1 -0
- data/lib/reek/cli/warning_collector.rb +1 -0
- data/lib/reek/code_comment.rb +1 -0
- data/lib/reek/configuration/app_configuration.rb +1 -0
- data/lib/reek/configuration/configuration_file_finder.rb +1 -0
- data/lib/reek/configuration/configuration_validator.rb +1 -0
- data/lib/reek/configuration/default_directive.rb +1 -0
- data/lib/reek/configuration/directory_directives.rb +1 -0
- data/lib/reek/configuration/excluded_paths.rb +1 -0
- data/lib/reek/context/attribute_context.rb +1 -0
- data/lib/reek/context/class_context.rb +1 -0
- data/lib/reek/context/code_context.rb +1 -0
- data/lib/reek/context/ghost_context.rb +1 -0
- data/lib/reek/context/method_context.rb +1 -0
- data/lib/reek/context/module_context.rb +1 -0
- data/lib/reek/context/root_context.rb +1 -0
- data/lib/reek/context/send_context.rb +1 -0
- data/lib/reek/context/singleton_attribute_context.rb +1 -0
- data/lib/reek/context/singleton_method_context.rb +1 -0
- data/lib/reek/context/statement_counter.rb +1 -0
- data/lib/reek/context/visibility_tracker.rb +3 -2
- data/lib/reek/context_builder.rb +1 -0
- data/lib/reek/examiner.rb +2 -1
- data/lib/reek/rake/task.rb +1 -0
- data/lib/reek/report.rb +1 -0
- data/lib/reek/report/code_climate/code_climate_formatter.rb +2 -2
- data/lib/reek/report/formatter.rb +1 -0
- data/lib/reek/report/heading_formatter.rb +1 -0
- data/lib/reek/report/location_formatter.rb +1 -0
- data/lib/reek/report/report.rb +3 -3
- data/lib/reek/smells.rb +1 -0
- data/lib/reek/smells/attribute.rb +1 -0
- data/lib/reek/smells/boolean_parameter.rb +1 -4
- data/lib/reek/smells/class_variable.rb +1 -0
- data/lib/reek/smells/control_parameter.rb +7 -4
- data/lib/reek/smells/data_clump.rb +1 -0
- data/lib/reek/smells/duplicate_method_call.rb +5 -4
- data/lib/reek/smells/feature_envy.rb +1 -4
- data/lib/reek/smells/irresponsible_module.rb +1 -0
- data/lib/reek/smells/long_parameter_list.rb +1 -0
- data/lib/reek/smells/long_yield_list.rb +1 -4
- data/lib/reek/smells/module_initialize.rb +1 -0
- data/lib/reek/smells/nested_iterators.rb +2 -1
- data/lib/reek/smells/nil_check.rb +3 -4
- data/lib/reek/smells/prima_donna_method.rb +1 -0
- data/lib/reek/smells/repeated_conditional.rb +1 -4
- data/lib/reek/smells/smell_configuration.rb +1 -0
- data/lib/reek/smells/smell_detector.rb +2 -13
- data/lib/reek/smells/smell_repository.rb +1 -0
- data/lib/reek/smells/smell_warning.rb +4 -6
- data/lib/reek/smells/too_many_instance_variables.rb +1 -4
- data/lib/reek/smells/too_many_methods.rb +1 -4
- data/lib/reek/smells/too_many_statements.rb +1 -4
- data/lib/reek/smells/uncommunicative_method_name.rb +2 -5
- data/lib/reek/smells/uncommunicative_module_name.rb +2 -6
- data/lib/reek/smells/uncommunicative_parameter_name.rb +3 -6
- data/lib/reek/smells/uncommunicative_variable_name.rb +1 -4
- data/lib/reek/smells/unused_parameters.rb +1 -4
- data/lib/reek/smells/unused_private_method.rb +1 -0
- data/lib/reek/smells/utility_function.rb +1 -4
- data/lib/reek/source/source_code.rb +2 -1
- data/lib/reek/source/source_locator.rb +1 -0
- data/lib/reek/spec.rb +16 -23
- data/lib/reek/spec/should_reek.rb +3 -2
- data/lib/reek/spec/should_reek_of.rb +18 -15
- data/lib/reek/spec/should_reek_only_of.rb +6 -5
- data/lib/reek/spec/smell_matcher.rb +3 -7
- data/lib/reek/tree_dresser.rb +1 -0
- data/lib/reek/version.rb +2 -1
- data/reek.gemspec +1 -1
- data/spec/reek/examiner_spec.rb +8 -4
- data/spec/reek/report/code_climate_formatter_spec.rb +1 -1
- data/spec/reek/report/code_climate_report_spec.rb +2 -2
- data/spec/reek/report/html_report_spec.rb +1 -6
- data/spec/reek/report/json_report_spec.rb +0 -4
- data/spec/reek/report/yaml_report_spec.rb +0 -4
- data/spec/reek/smells/data_clump_spec.rb +2 -2
- data/spec/reek/smells/feature_envy_spec.rb +3 -3
- data/spec/reek/smells/nested_iterators_spec.rb +0 -1
- data/spec/reek/smells/prima_donna_method_spec.rb +0 -1
- data/spec/reek/smells/smell_detector_shared.rb +1 -5
- data/spec/reek/smells/too_many_methods_spec.rb +0 -1
- data/spec/reek/smells/uncommunicative_module_name_spec.rb +0 -1
- data/spec/reek/smells/unused_private_method_spec.rb +6 -4
- data/spec/reek/smells/utility_function_spec.rb +1 -1
- data/spec/reek/spec/should_reek_of_spec.rb +7 -3
- data/spec/reek/spec/smell_matcher_spec.rb +0 -4
- 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
|
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 ||=
|
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 '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, :
|
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
|
28
|
-
source
|
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
|
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
|
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
|
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
|
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 '../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
|
25
|
+
def initialize(code:, origin:, parser: Parser::Ruby23)
|
25
26
|
@source = code
|
26
27
|
@origin = origin
|
27
28
|
@parser = parser
|
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
|
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
|
-
#
|
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
|
-
# -
|
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
|
-
#
|
71
|
-
# smells_details
|
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
|
-
#
|
68
|
+
# @example Without smell_details
|
76
69
|
#
|
77
70
|
# reek_of(:FeatureEnvy)
|
78
71
|
# reek_of(Reek::Smells::UtilityFunction)
|
79
72
|
#
|
80
|
-
#
|
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
|
-
#
|
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(
|
85
|
+
def reek_of(smell_type,
|
93
86
|
smell_details = {},
|
94
87
|
configuration = Configuration::AppConfiguration.default)
|
95
|
-
ShouldReekOf.new(
|
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
|
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(
|
110
|
-
ShouldReekOnlyOf.new(
|
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?(
|
15
|
-
self.examiner = Examiner.new(
|
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(
|
14
|
+
def initialize(smell_type_or_class,
|
14
15
|
smell_details = {},
|
15
16
|
configuration = Configuration::AppConfiguration.default)
|
16
|
-
@
|
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?(
|
22
|
-
self.examiner = Examiner.new(
|
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, :
|
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?(
|
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 #{
|
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 #{
|
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 #{
|
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
|
-
"#{
|
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(
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|