Sha256: 2c68b3d79a53740e639908168f2dd972607c4a2d563103f03191883f7b4311dc

Contents?: true

Size: 1.1 KB

Versions: 12

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop checks for pipes for empty block parameters. Pipes for empty
      # block parameters do not cause syntax errors, but they are redundant.
      #
      # @example
      #   # bad
      #   a do ||
      #     do_something
      #   end
      #
      #   # bad
      #   a { || do_something }
      #
      #   # good
      #   a do
      #   end
      #
      #   # good
      #   a { do_something }
      class EmptyBlockParameter < Cop
        include EmptyParameter
        include RangeHelp

        MSG = 'Omit pipes for the empty block parameters.'.freeze

        def on_block(node)
          send_node = node.send_node
          check(node) unless send_node.send_type? && send_node.stabby_lambda?
        end

        def autocorrect(node)
          lambda do |corrector|
            block = node.parent
            range = range_between(
              block.loc.begin.end_pos,
              node.loc.expression.end_pos
            )
            corrector.remove(range)
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
rubocop-0.59.0 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-0.58.2 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-0.58.1 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-0.58.0 lib/rubocop/cop/style/empty_block_parameter.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/rubocop-0.57.2/lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-0.57.2 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-0.57.1 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-0.57.0 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-0.56.0 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-0.55.0 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-0.54.0 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-0.53.0 lib/rubocop/cop/style/empty_block_parameter.rb