Sha256: 1075752e584e3d29540753dffcb8f306515dd47c12982fd78988a0b65888c24d

Contents?: true

Size: 1.46 KB

Versions: 233

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Lint
      # Checks for the presence of a `return` inside a `begin..end` block
      # in assignment contexts.
      # In this situation, the `return` will result in an exit from the current
      # method, possibly leading to unexpected behavior.
      #
      # @example
      #
      #   # bad
      #
      #   @some_variable ||= begin
      #     return some_value if some_condition_is_met
      #
      #     do_something
      #   end
      #
      # @example
      #
      #   # good
      #
      #   @some_variable ||= begin
      #     if some_condition_is_met
      #       some_value
      #     else
      #       do_something
      #     end
      #   end
      #
      #   # good
      #
      #   some_variable = if some_condition_is_met
      #                     return if another_condition_is_met
      #
      #                     some_value
      #                   else
      #                     do_something
      #                   end
      #
      class NoReturnInBeginEndBlocks < Base
        MSG = 'Do not `return` in `begin..end` blocks in assignment contexts.'

        def on_lvasgn(node)
          node.each_node(:kwbegin) do |kwbegin_node|
            kwbegin_node.each_node(:return) do |return_node|
              add_offense(return_node)
            end
          end
        end
        alias on_or_asgn    on_lvasgn
        alias on_op_asgn    on_lvasgn
      end
    end
  end
end

Version data entries

233 entries across 224 versions & 21 rubygems

Version Path
synctera_ruby_sdk-1.1.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
synctera_ruby_sdk-1.1.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
synctera_ruby_sdk-1.1.1 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
sampero-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.1/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
rubocop-1.56.1 lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
tursodb-0.1.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
synctera_ruby_sdk-1.0.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.56.0/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
rubocop-1.56.0 lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
rubocop-1.55.1 lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
rubocop-1.55.0 lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
rubocop-1.54.2 lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
mlh-rubocop-config-1.0.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.54.1/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.52.1/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
fablicop-1.10.3 vendor/bundle/ruby/3.2.0/gems/rubocop-1.54.1/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
rubocop-1.54.1 lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
rubocop-1.54.0 lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
rubocop-1.53.1 lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
rubocop-1.53.0 lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/lint/no_return_in_begin_end_blocks.rb