Class: RuboCop::Cop::Lint::NoBangStateMachineEvents

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/lint/no_bang_state_machine_events.rb

Overview

Examples:

# bad - will define `!`-ended method that won't raise
state_machine :state do
  event :started! do
    ...
  end
end

# good
state_machine :state do
  event :started do
    ...
  end
end

Constant Summary collapse

MSG =
"Event names ending with a `!` define `!`-ended methods that do not raise"

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/rubocop/cop/lint/no_bang_state_machine_events.rb', line 26

def on_send(node)
  return unless (event_name = is_state_machine_event?(node))
  return unless is_state_machine?(node.parent.parent)
  return unless event_name.match?(/\w+!$/)

  add_offense(node)
end