Sha256: 2481e6bbb6c0458f0924fe2607cfcbbf27454e3ae256a1212ecf4e8efab7c025
Contents?: true
Size: 956 Bytes
Versions: 9
Compression:
Stored size: 956 Bytes
Contents
# frozen_string_literal: true module RuboCop module Cop module Lint # Checks for `rescue` blocks targeting the Exception class. # # @example # # # bad # begin # do_something # rescue Exception # handle_exception # end # # # good # begin # do_something # rescue ArgumentError # handle_exception # end class RescueException < Base MSG = 'Avoid rescuing the `Exception` class. Perhaps you meant to rescue `StandardError`?' 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) end def targets_exception?(rescue_arg_node) rescue_arg_node.const_name == 'Exception' end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems