Sha256: 3ab02f4bcb0c28e1710c021f38b5ddf2ddb797c50e20fed7ca4a2f2da6196396

Contents?: true

Size: 689 Bytes

Versions: 4

Compression:

Stored size: 689 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    class RescueException < Cop
      MSG = 'Avoid rescuing the Exception class.'

      def on_resbody(node)
        return unless node.children.first
        rescue_args = node.children.first.children
        if rescue_args.any? { |a| targets_exception?(a) }
          add_offence(:warning, node.location.line, MSG)
        end

        super
      end

      def targets_exception?(rescue_arg_node)
        return false unless rescue_arg_node.type == :const
        namespace, klass_name = *rescue_arg_node
        return false unless namespace.nil? || namespace.type == :cbase
        klass_name == :Exception
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.8.3 lib/rubocop/cop/rescue_exception.rb
rubocop-0.8.2 lib/rubocop/cop/rescue_exception.rb
rubocop-0.8.1 lib/rubocop/cop/rescue_exception.rb
rubocop-0.8.0 lib/rubocop/cop/rescue_exception.rb