Class: Reek::SmellDetectors::NilCheck
- Inherits:
-
BaseDetector
- Object
- BaseDetector
- Reek::SmellDetectors::NilCheck
- Defined in:
- lib/reek/smell_detectors/nil_check.rb
Overview
Checking for nil is a special kind of type check, and therefore a case of SimulatedPolymorphism.
See Nil-Check for details.
Defined Under Namespace
Modules: NilCallNodeDetector, NilWhenNodeDetector Classes: NodeFinder
Constant Summary
Constants inherited from BaseDetector
BaseDetector::DEFAULT_EXCLUDE_SET, BaseDetector::EXCLUDE_KEY
Instance Attribute Summary
Attributes inherited from BaseDetector
Instance Method Summary collapse
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
#detect_nodes ⇒ Object (private)
25 26 27 28 29 |
# File 'lib/reek/smell_detectors/nil_check.rb', line 25 def detect_nodes finders = [NodeFinder.new(context, :send, NilCallNodeDetector), NodeFinder.new(context, :when, NilWhenNodeDetector)] finders.flat_map(&:smelly_nodes) end |
#sniff ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/reek/smell_detectors/nil_check.rb', line 12 def sniff lines = detect_nodes.map(&:line) if lines.any? [smell_warning( lines: lines, message: 'performs a nil-check')] else [] end end |