Sha256: ae536b19dda91c7f7cb7d074ed22254f0ee389192df142587e27f1eaddf68b68
Contents?: true
Size: 1.23 KB
Versions: 2
Compression:
Stored size: 1.23 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 autocorrect_action(node) @corrections << lambda do |corrector| name = command?(:raise, node) ? 'fail' : 'raise' corrector.replace(node.loc.selector, name) end end private def check_for_raise(node) return unless node on_node(:send, node, :rescue) do |send_node| if command?(:raise, send_node) convention(send_node, :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) convention(send_node, :selector, RAISE_MSG) end end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rubocop-0.13.1 | lib/rubocop/cop/style/signal_exception.rb |
rubocop-0.13.0 | lib/rubocop/cop/style/signal_exception.rb |