Class: Reek::SmellDetectors::LongYieldList
- Inherits:
-
BaseDetector
- Object
- BaseDetector
- Reek::SmellDetectors::LongYieldList
- Defined in:
- lib/reek/smell_detectors/long_yield_list.rb
Overview
A variant on LongParameterList that checks the number of items passed to a block by a yield
call.
See Long-Yield-List for details.
Constant Summary collapse
- MAX_ALLOWED_PARAMS_KEY =
The name of the config field that sets the maximum number of parameters permitted in any method or block.
'max_params'
- DEFAULT_MAX_ALLOWED_PARAMS =
3
Constants inherited from BaseDetector
BaseDetector::DEFAULT_EXCLUDE_SET, BaseDetector::EXCLUDE_KEY
Instance Attribute Summary
Attributes inherited from BaseDetector
Class Method Summary collapse
Instance Method Summary collapse
- #max_allowed_params ⇒ Object private
-
#sniff ⇒ Array<SmellWarning>
Checks the number of parameters in the given scope.
Methods inherited from BaseDetector
#config_for, configuration_keys, contexts, descendants, #enabled?, #exception?, #expression, inherited, #initialize, #run, #smell_type, smell_type, #smell_warning, #source_line, to_detector, todo_configuration_for, #value
Constructor Details
This class inherits a constructor from Reek::SmellDetectors::BaseDetector
Class Method Details
.default_config ⇒ Object
18 19 20 |
# File 'lib/reek/smell_detectors/long_yield_list.rb', line 18 def self.default_config super.merge MAX_ALLOWED_PARAMS_KEY => DEFAULT_MAX_ALLOWED_PARAMS end |
Instance Method Details
#max_allowed_params ⇒ Object (private)
42 43 44 |
# File 'lib/reek/smell_detectors/long_yield_list.rb', line 42 def max_allowed_params value(MAX_ALLOWED_PARAMS_KEY, context) end |
#sniff ⇒ Array<SmellWarning>
Checks the number of parameters in the given scope.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/reek/smell_detectors/long_yield_list.rb', line 28 def sniff context.local_nodes(:yield).select do |yield_node| yield_node.args.length > max_allowed_params end.map do |yield_node| count = yield_node.args.length smell_warning( lines: [yield_node.line], message: "yields #{count} parameters", parameters: { count: count }) end end |