class RuboCop::Cop::Lint::UselessElseWithoutRescue

Checks for useless ‘else` in `begin..end` without `rescue`.

NOTE: This syntax is no longer valid on Ruby 2.6 or higher.

@example

# bad
begin
  do_something
else
  do_something_else # This will never be run.
end

# good
begin
  do_something
rescue
  handle_errors
else
  do_something_else
end

Constants

MSG

Public Instance Methods

on_new_investigation() click to toggle source
# File lib/rubocop/cop/lint/useless_else_without_rescue.rb, line 30
def on_new_investigation
  processed_source.diagnostics.each do |diagnostic|
    next unless diagnostic.reason == :useless_else

    add_offense(diagnostic.location, severity: diagnostic.level)
  end
end