Sha256: 8f4d555032c2546bb77daf10e18ff9138d7c7daf9a9c0b7800f5fbaf7cb66eee

Contents?: true

Size: 1.01 KB

Versions: 46

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # This cop checks for useless `else` in `begin..end` without `rescue`.
      #
      # Note: This syntax is no longer valid on Ruby 2.6 or higher and
      # this cop is going to be removed at some point the future.
      #
      # @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 < Cop
        include ParserDiagnostic

        MSG = '`else` without `rescue` is useless.'

        private

        def relevant_diagnostic?(diagnostic)
          diagnostic.reason == :useless_else
        end

        def alternative_message(_diagnostic)
          MSG
        end
      end
    end
  end
end

Version data entries

46 entries across 27 versions & 3 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/useless_else_without_rescue.rb
rubocop-0.82.0 lib/rubocop/cop/lint/useless_else_without_rescue.rb
rubocop-0.81.0 lib/rubocop/cop/lint/useless_else_without_rescue.rb
rubocop-0.80.1 lib/rubocop/cop/lint/useless_else_without_rescue.rb
rubocop-0.80.0 lib/rubocop/cop/lint/useless_else_without_rescue.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/useless_else_without_rescue.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/lint/useless_else_without_rescue.rb
rubocop-0.79.0 lib/rubocop/cop/lint/useless_else_without_rescue.rb
rubocop-0.78.0 lib/rubocop/cop/lint/useless_else_without_rescue.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/cop/lint/useless_else_without_rescue.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/cop/lint/useless_else_without_rescue.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/lint/useless_else_without_rescue.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/lint/useless_else_without_rescue.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.77.0/lib/rubocop/cop/lint/useless_else_without_rescue.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/lint/useless_else_without_rescue.rb
rubocop-0.77.0 lib/rubocop/cop/lint/useless_else_without_rescue.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.75.1/lib/rubocop/cop/lint/useless_else_without_rescue.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.72.0/lib/rubocop/cop/lint/useless_else_without_rescue.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/cop/lint/useless_else_without_rescue.rb
zuora_connect_ui-0.9.2 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/lint/useless_else_without_rescue.rb