Sha256: d82b05efa581ed43ceb63d9b74d058e28c55ce3df897e9b4b03a81910b8bf719

Contents?: true

Size: 1.04 KB

Versions: 5

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # This cop checks for empty `ensure` blocks
      #
      # @example
      #
      #   # bad
      #
      #   def some_method
      #     do_something
      #   ensure
      #   end
      #
      # @example
      #
      #   # bad
      #
      #   begin
      #     do_something
      #   ensure
      #   end
      #
      # @example
      #
      #   # good
      #
      #   def some_method
      #     do_something
      #   ensure
      #     do_something_else
      #   end
      #
      # @example
      #
      #   # good
      #
      #   begin
      #     do_something
      #   ensure
      #     do_something_else
      #   end
      class EmptyEnsure < Cop
        MSG = 'Empty `ensure` block detected.'.freeze

        def on_ensure(node)
          add_offense(node, :keyword) unless node.body
        end

        def autocorrect(node)
          lambda do |corrector|
            corrector.remove(node.loc.keyword)
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rubocop-0.50.0 lib/rubocop/cop/lint/empty_ensure.rb
rubocop-0.49.1 lib/rubocop/cop/lint/empty_ensure.rb
rubocop-0.49.0 lib/rubocop/cop/lint/empty_ensure.rb
rubocop-0.48.1 lib/rubocop/cop/lint/empty_ensure.rb
rubocop-0.48.0 lib/rubocop/cop/lint/empty_ensure.rb