Sha256: 21048201331b74ed2cb448dd211b7094ac2a845d0399b4d15bd819c0b6f5f814

Contents?: true

Size: 1.22 KB

Versions: 11

Compression:

Stored size: 1.22 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 find_offense_node_by(diagnostic)
          # TODO: When implementing auto-correction, this method should return
          # an offense node passed as first argument of `add_offense` method.
        end

        def alternative_message(_diagnostic)
          MSG
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 3 rubygems

Version Path
rubocop-0.88.0 lib/rubocop/cop/lint/useless_else_without_rescue.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/lint/useless_else_without_rescue.rb
rubocop-0.87.1 lib/rubocop/cop/lint/useless_else_without_rescue.rb
rubocop-0.87.0 lib/rubocop/cop/lint/useless_else_without_rescue.rb
rubocop-0.86.0 lib/rubocop/cop/lint/useless_else_without_rescue.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/lint/useless_else_without_rescue.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/lint/useless_else_without_rescue.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/lint/useless_else_without_rescue.rb
rubocop-0.85.1 lib/rubocop/cop/lint/useless_else_without_rescue.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/lint/useless_else_without_rescue.rb
rubocop-0.85.0 lib/rubocop/cop/lint/useless_else_without_rescue.rb