Sha256: 27c163576de00b0bc4e085abd6ffdbc1096610244e2beb1374f128c000d97056

Contents?: true

Size: 1.02 KB

Versions: 2

Compression:

Stored size: 1.02 KB

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Style
      # This cop checks for uses of `fail` and `raise`.
      class SignalException < Cop
        FAIL_MSG = 'Use `fail` instead of `raise` to signal exceptions.'
        RAISE_MSG = 'Use `raise` instead of `fail` to rethrow exceptions.'

        def on_rescue(node)
          begin_node, rescue_node = *node

          check_for_raise(begin_node)
          check_for_fail(rescue_node)
        end

        def check_for_raise(node)
          return unless node

          on_node(:send, node, :rescue) do |send_node|
            if command?(:raise, send_node)
              add_offence(:convention, send_node.loc.selector, FAIL_MSG)
            end
          end
        end

        def check_for_fail(node)
          return unless node

          on_node(:send, node, :rescue) do |send_node|
            if command?(:fail, send_node)
              add_offence(:convention, send_node.loc.selector, RAISE_MSG)
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.11.1 lib/rubocop/cop/style/signal_exception.rb
rubocop-0.11.0 lib/rubocop/cop/style/signal_exception.rb