Sha256: 088ec6afb4f0b6d6d41caa547c4e75fb8d2adcfe80f82b186fa1c11d9adb19d6
Contents?: true
Size: 923 Bytes
Versions: 9
Compression:
Stored size: 923 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 return unless rescue_args.any? { |a| targets_exception?(a) } add_offense(node, :expression) end def targets_exception?(rescue_arg_node) Util.const_name(rescue_arg_node) == 'Exception' end def autocorrect(node) @corrections << lambda do |corrector| corrector.remove( range_with_surrounding_space( node.children.first.children.first.loc.expression, :left ) ) end end end end end end
Version data entries
9 entries across 9 versions & 2 rubygems