Sha256: e572d1426f6c3d998c353c498ed96bccd4b2c60295328bd5df5ef0982e6cecd2

Contents?: true

Size: 980 Bytes

Versions: 179

Compression:

Stored size: 980 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # 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
      #
      # @example
      #
      #   # good
      #
      #   begin
      #     do_something
      #   rescue
      #     handle_errors
      #   else
      #     do_something_else
      #   end
      class UselessElseWithoutRescue < Base
        MSG = '`else` without `rescue` is useless.'

        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
      end
    end
  end
end

Version data entries

179 entries across 172 versions & 17 rubygems

Version Path
study_line-0.2.6 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/lint/useless_else_without_rescue.rb
study_line-0.2.5 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/lint/useless_else_without_rescue.rb
study_line-0.2.4 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/lint/useless_else_without_rescue.rb
study_line-0.2.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/lint/useless_else_without_rescue.rb
study_line-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/lint/useless_else_without_rescue.rb
rubocop-1.60.1 lib/rubocop/cop/lint/useless_else_without_rescue.rb
study_line-0.2.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/lint/useless_else_without_rescue.rb
study_line-0.2.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.60.0/lib/rubocop/cop/lint/useless_else_without_rescue.rb
rubocop-1.60.0 lib/rubocop/cop/lint/useless_else_without_rescue.rb
harbr-0.2.10 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/lint/useless_else_without_rescue.rb
harbr-0.2.9 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/lint/useless_else_without_rescue.rb
harbr-0.2.8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/lint/useless_else_without_rescue.rb
harbr-0.2.7 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/lint/useless_else_without_rescue.rb
harbr-0.2.6 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/lint/useless_else_without_rescue.rb
harbr-0.2.5 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/lint/useless_else_without_rescue.rb
harbr-0.2.4 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/lint/useless_else_without_rescue.rb
harbr-0.2.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/lint/useless_else_without_rescue.rb
harbr-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/lint/useless_else_without_rescue.rb
harbr-0.2.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/lint/useless_else_without_rescue.rb
harbr-0.2.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.57.2/lib/rubocop/cop/lint/useless_else_without_rescue.rb