Class: Reek::SmellDetectors::BooleanParameter
- Inherits:
-
BaseDetector
- Object
- BaseDetector
- Reek::SmellDetectors::BooleanParameter
- Defined in:
- lib/reek/smell_detectors/boolean_parameter.rb
Overview
A Boolean parameter effectively permits a method’s caller to decide which execution path to take. The offending parameter is a kind of Control Couple.
Currently Reek can only detect a Boolean parameter when it has a default initializer.
See Boolean-Parameter for details.
Constant Summary collapse
- BOOLEAN_VALUES =
[:true, :false].freeze
Constants inherited from BaseDetector
Reek::SmellDetectors::BaseDetector::DEFAULT_EXCLUDE_SET, Reek::SmellDetectors::BaseDetector::EXCLUDE_KEY
Instance Attribute Summary
Attributes inherited from BaseDetector
Instance Method Summary collapse
-
#sniff ⇒ Array<SmellWarning>
Checks whether the given method has any Boolean parameters.
Methods inherited from BaseDetector
#config_for, configuration_keys, contexts, default_config, 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
Instance Method Details
#sniff ⇒ Array<SmellWarning>
Checks whether the given method has any Boolean parameters.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/reek/smell_detectors/boolean_parameter.rb', line 24 def sniff context.default_assignments.select do |_parameter, value| BOOLEAN_VALUES.include?(value.type) end.map do |parameter, _value| smell_warning( lines: [source_line], message: "has boolean parameter '#{parameter}'", parameters: { parameter: parameter.to_s }) end end |