Sha256: 81ffe050c1b5ac0f7a15723fd115e724a901dd656a554795fd762c763efcee12
Contents?: true
Size: 828 Bytes
Versions: 3
Compression:
Stored size: 828 Bytes
Contents
# encoding: utf-8 module Rubocop module Cop module Lint # This cop checks for *rescue* blocks targeting the Exception class. 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.expression, 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 end
Version data entries
3 entries across 3 versions & 2 rubygems
Version | Path |
---|---|
rubocop-0.9.1 | lib/rubocop/cop/lint/rescue_exception.rb |
sabat-rubocop-0.9.0 | lib/rubocop/cop/lint/rescue_exception.rb |
rubocop-0.9.0 | lib/rubocop/cop/lint/rescue_exception.rb |