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

Instance Method Summary collapse

Class Method Details

.comparison_call?(call) ⇒ Boolean

Returns:

  • (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_methodsObject



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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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_methodsObject (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