Sha256: 88515f5b5d0c79996639fee97c6da86d25a73599f15febb6206d920824b37549

Contents?: true

Size: 1.01 KB

Versions: 6494

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # This cop checks for *return* from an *ensure* block.
      # Explicit return from an ensure block alters the control flow
      # as the return will take precedence over any exception being raised,
      # and the exception will be silently thrown away as if it were rescued.
      #
      # @example
      #
      #   # bad
      #
      #   begin
      #     do_something
      #   ensure
      #     do_something_else
      #     return
      #   end
      #
      # @example
      #
      #   # good
      #
      #   begin
      #     do_something
      #   ensure
      #     do_something_else
      #   end
      class EnsureReturn < Cop
        MSG = 'Do not return from an `ensure` block.'.freeze

        def on_ensure(node)
          ensure_body = node.body

          return unless ensure_body

          ensure_body.each_node(:return) do |return_node|
            add_offense(return_node)
          end
        end
      end
    end
  end
end

Version data entries

6,494 entries across 6,488 versions & 24 rubygems

Version Path
cybrid_api_organization_ruby-0.122.48 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
cybrid_api_bank_ruby-0.122.47 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
cybrid_api_id_ruby-0.122.47 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
cybrid_api_organization_ruby-0.122.47 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
cybrid_api_id_ruby-0.122.46 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
cybrid_api_bank_ruby-0.122.46 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
cybrid_api_organization_ruby-0.122.46 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
cybrid_api_organization_ruby-0.122.45 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
cybrid_api_id_ruby-0.122.45 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
cybrid_api_bank_ruby-0.122.45 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
cybrid_api_bank_ruby-0.122.44 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
cybrid_api_id_ruby-0.122.44 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
cybrid_api_organization_ruby-0.122.44 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
cybrid_api_bank_ruby-0.122.43 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
cybrid_api_organization_ruby-0.122.43 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
cybrid_api_id_ruby-0.122.43 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
cybrid_api_bank_ruby-0.122.42 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
cybrid_api_id_ruby-0.122.42 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
cybrid_api_organization_ruby-0.122.42 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb
ory-client-1.15.10 vendor/bundle/ruby/3.1.0/gems/rubocop-0.66.0/lib/rubocop/cop/lint/ensure_return.rb