class RubbyCop::Cop::Style::IfUnlessModifierOfIfUnless

Checks for if and unless statements used as modifiers of other if or unless statements.

@example

# bad
tired? ? 'stop' : 'go faster' if running?

# bad
if tired?
  "please stop"
else
  "keep going"
end if running?

# good
if running?
  tired? ? 'stop' : 'go faster'
end

Constants

MSG

Public Instance Methods

on_if(node) click to toggle source
# File lib/rubbycop/cop/style/if_unless_modifier_of_if_unless.rb, line 30
def on_if(node)
  return unless node.modifier_form? && node.body.if_type?

  add_offense(node, :keyword, format(MSG, node.keyword))
end