Class: RuboCop::Cop::Kata::NoNilReturn

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/kata/no_nil_return.rb

Constant Summary collapse

MSG =
"Returning nil hands the caller a bomb; raise or return a real object."

Instance Method Summary collapse

Instance Method Details

#on_def(node) ⇒ Object Also known as: on_defs



10
11
12
13
# File 'lib/rubocop/cop/kata/no_nil_return.rb', line 10

def on_def(node)
  last = tail(node.body)
  add_offense(last, message: MSG) if last&.nil_type?
end

#on_return(node) ⇒ Object



6
7
8
# File 'lib/rubocop/cop/kata/no_nil_return.rb', line 6

def on_return(node)
  add_offense(node, message: MSG) if node.children.first&.nil_type?
end