class RuboCop::Cop::Lint::ConstantOverwrittenInRescue
end
rescue StandardError
something
begin
# good
end
rescue => StandardError
something
begin
# bad
@example
In that case, the result of ‘rescue` will overwrite `StandardError`.
However, you have written `rescue => StandardError`.
You intended to write as `rescue StandardError`.
Checks for overwriting an exception with an exception result by use `rescue =>`.
def self.autocorrect_incompatible_with
def self.autocorrect_incompatible_with [Naming::RescuedExceptionsVariableName, Style::RescueStandardError] end
def on_resbody(node)
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