Class: RuboCop::Cop::Airbnb::SimpleModifierConditional

Inherits:
Base
  • Object
show all
Defined in:
lib/rubocop/cop/airbnb/simple_modifier_conditional.rb

Overview

Cop to tackle prevent more complicated modifier if/unless statements github.com/airbnb/ruby#only-simple-if-unless

Constant Summary collapse

MSG =
'Modifier if/unless usage is okay when the body is simple, ' \
'the condition is simple, and the whole thing fits on one line. ' \
'Otherwise, avoid modifier if/unless.'.freeze

Instance Method Summary collapse

Instance Method Details

#on_if(node) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/rubocop/cop/airbnb/simple_modifier_conditional.rb', line 13

def on_if(node)
  return unless node.modifier_form?

  if multiple_conditionals?(node) || node.multiline?
    add_offense(node)
  end
end