Sha256: 01a1808bab9e1d3a05bbf48473e7e134fc5ee8f8ce70c48bdf2e02edd97a0d3d

Contents?: true

Size: 988 Bytes

Versions: 30

Compression:

Stored size: 988 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # @example
      #   # 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
      class NoBangStateMachineEvents < Cop
        MSG = 'Event names ending with a `!` define `!`-ended methods that do not raise'

        def_node_matcher :is_state_machine_event?, '(send nil? :event (sym $_))'
        def_node_matcher :is_state_machine?, '(block (send nil? :state_machine ...) ...)'

        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
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
rf-stylez-1.0.1 lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-1.0.0 lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-0.16.0 lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-0.15.0 lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-0.14.0 lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-0.13.0 lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-0.12.0 lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-0.11.1 lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-0.11.0 lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-0.10.0 lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-0.9.0 lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-0.8.0 lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-0.8.0.pre2 lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-0.8.0.pre lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-0.7.2 lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-0.7.2.pre2 lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-0.7.2.pre lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-0.7.1 lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-0.7.1.pre lib/rubocop/cop/lint/no_bang_state_machine_events.rb
rf-stylez-0.7.0 lib/rubocop/cop/lint/no_bang_state_machine_events.rb