Sha256: 70ab4db54d7f583c594b58c2dd40e8986260f77d992a4d9d6a53247ac90843c5

Contents?: true

Size: 907 Bytes

Versions: 5

Compression:

Stored size: 907 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # Checks for empty `ensure` blocks.
      #
      # @example
      #
      #   # bad
      #   def some_method
      #     do_something
      #   ensure
      #   end
      #
      #   # bad
      #   begin
      #     do_something
      #   ensure
      #   end
      #
      #   # good
      #   def some_method
      #     do_something
      #   ensure
      #     do_something_else
      #   end
      #
      #   # good
      #   begin
      #     do_something
      #   ensure
      #     do_something_else
      #   end
      class EmptyEnsure < Base
        extend AutoCorrector

        MSG = 'Empty `ensure` block detected.'

        def on_ensure(node)
          return if node.body

          add_offense(node.loc.keyword) { |corrector| corrector.remove(node.loc.keyword) }
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-1.68.0 lib/rubocop/cop/lint/empty_ensure.rb
rubocop-1.67.0 lib/rubocop/cop/lint/empty_ensure.rb
rubocop-1.66.1 lib/rubocop/cop/lint/empty_ensure.rb
rubocop-1.66.0 lib/rubocop/cop/lint/empty_ensure.rb
rubocop-1.65.1 lib/rubocop/cop/lint/empty_ensure.rb