Module: Reek::SmellDetectors::NilCheck::NilCallNodeDetector
- Defined in:
- lib/reek/smell_detectors/nil_check.rb
Overview
Detect ‘call’ nodes which perform a nil check.
Class Method Summary collapse
- .comparison_call?(call) ⇒ Boolean
- .comparison_methods ⇒ Object
- .detect(node) ⇒ Object
- .involves_nil?(call) ⇒ Boolean
- .nil_comparison?(call) ⇒ Boolean
- .nil_query?(call) ⇒ Boolean
Instance Method Summary collapse
- #comparison_call?(call) ⇒ Object private
- #comparison_methods ⇒ Object private
- #detect(node) ⇒ Object private
- #involves_nil?(call) ⇒ Object private
- #nil_comparison?(call) ⇒ Object private
- #nil_query?(call) ⇒ Object private
Class Method Details
.comparison_call?(call) ⇒ Boolean
69 70 71 |
# File 'lib/reek/smell_detectors/nil_check.rb', line 69 def comparison_call?(call) comparison_methods.include? call.name end |
.comparison_methods ⇒ Object
77 78 79 |
# File 'lib/reek/smell_detectors/nil_check.rb', line 77 def comparison_methods [:==, :===] end |
.detect(node) ⇒ Object
57 58 59 |
# File 'lib/reek/smell_detectors/nil_check.rb', line 57 def detect(node) nil_query?(node) || nil_comparison?(node) end |
.involves_nil?(call) ⇒ Boolean
73 74 75 |
# File 'lib/reek/smell_detectors/nil_check.rb', line 73 def involves_nil?(call) call.participants.any? { |it| it.type == :nil } end |
.nil_comparison?(call) ⇒ Boolean
65 66 67 |
# File 'lib/reek/smell_detectors/nil_check.rb', line 65 def nil_comparison?(call) comparison_call?(call) && involves_nil?(call) end |
.nil_query?(call) ⇒ Boolean
61 62 63 |
# File 'lib/reek/smell_detectors/nil_check.rb', line 61 def nil_query?(call) call.name == :nil? end |
Instance Method Details
#comparison_call?(call) ⇒ Object (private)
69 70 71 |
# File 'lib/reek/smell_detectors/nil_check.rb', line 69 def comparison_call?(call) comparison_methods.include? call.name end |
#comparison_methods ⇒ Object (private)
77 78 79 |
# File 'lib/reek/smell_detectors/nil_check.rb', line 77 def comparison_methods [:==, :===] end |
#detect(node) ⇒ Object (private)
57 58 59 |
# File 'lib/reek/smell_detectors/nil_check.rb', line 57 def detect(node) nil_query?(node) || nil_comparison?(node) end |
#involves_nil?(call) ⇒ Object (private)
73 74 75 |
# File 'lib/reek/smell_detectors/nil_check.rb', line 73 def involves_nil?(call) call.participants.any? { |it| it.type == :nil } end |
#nil_comparison?(call) ⇒ Object (private)
65 66 67 |
# File 'lib/reek/smell_detectors/nil_check.rb', line 65 def nil_comparison?(call) comparison_call?(call) && involves_nil?(call) end |
#nil_query?(call) ⇒ Object (private)
61 62 63 |
# File 'lib/reek/smell_detectors/nil_check.rb', line 61 def nil_query?(call) call.name == :nil? end |