class RuboCop::Cop::Lint::ConstantOverwrittenInRescue
Checks for overwriting an exception with an exception result by use “rescue =>“.
You intended to write as ‘rescue StandardError`. However, you have written `rescue => StandardError`. In that case, the result of `rescue` will overwrite `StandardError`.
@example
# bad begin something rescue => StandardError end # good begin something rescue StandardError end
Constants
- MSG
Public Class Methods
autocorrect_incompatible_with()
click to toggle source
# File lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb, line 37 def self.autocorrect_incompatible_with [Naming::RescuedExceptionsVariableName, Style::RescueStandardError] end
Public Instance Methods
on_resbody(node)
click to toggle source
# File lib/rubocop/cop/lint/constant_overwritten_in_rescue.rb, line 41 def on_resbody(node) return unless (constant = overwritten_constant(node)) add_offense(node.loc.assoc, message: format(MSG, constant: constant)) do |corrector| corrector.remove(range_between(node.loc.keyword.end_pos, node.loc.assoc.end_pos)) end end