Module: Reek::Smells::NilCheck::NilCallNodeDetector

Defined in:
lib/reek/smells/nil_check.rb

Overview

Detect 'call' nodes which perform a nil check.

Class Method Summary collapse

Class Method Details

.comparison_call?(call) ⇒ Boolean

Returns:

  • (Boolean)

58
59
60
# File 'lib/reek/smells/nil_check.rb', line 58

def comparison_call?(call)
  comparison_methods.include? call.method_name
end

.comparison_methodsObject


66
67
68
# File 'lib/reek/smells/nil_check.rb', line 66

def comparison_methods
  [:==, :===]
end

.detect(node) ⇒ Object


46
47
48
# File 'lib/reek/smells/nil_check.rb', line 46

def detect(node)
  nil_query?(node) || nil_comparison?(node)
end

.involves_nil?(call) ⇒ Boolean

Returns:

  • (Boolean)

62
63
64
# File 'lib/reek/smells/nil_check.rb', line 62

def involves_nil?(call)
  call.participants.any? { |it| it.type == :nil }
end

.nil_comparison?(call) ⇒ Boolean

Returns:

  • (Boolean)

54
55
56
# File 'lib/reek/smells/nil_check.rb', line 54

def nil_comparison?(call)
  comparison_call?(call) && involves_nil?(call)
end

.nil_query?(call) ⇒ Boolean

Returns:

  • (Boolean)

50
51
52
# File 'lib/reek/smells/nil_check.rb', line 50

def nil_query?(call)
  call.method_name == :nil?
end