Sha256: e0fb2d8a901ad7689bd3c6d9cc5bf03e3962cdd431defaf58fa15f11daba66ae

Contents?: true

Size: 1.06 KB

Versions: 73

Compression:

Stored size: 1.06 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 < Base
        include EmptyParameter
        include RangeHelp
        extend AutoCorrector

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

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

        private

        def autocorrect(corrector, node)
          block = node.parent
          range = range_between(block.loc.begin.end_pos, node.loc.expression.end_pos)

          corrector.remove(range)
        end
      end
    end
  end
end

Version data entries

73 entries across 73 versions & 8 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/style/empty_block_parameter.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.29.1 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.29.0 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.28.2 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.28.1 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.28.0 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.27.0 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.26.1 lib/rubocop/cop/style/empty_block_parameter.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-1.26.0/lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.26.0 lib/rubocop/cop/style/empty_block_parameter.rb
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/empty_block_parameter.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.25.1 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.25.0 lib/rubocop/cop/style/empty_block_parameter.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/empty_block_parameter.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/cop/style/empty_block_parameter.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/rubocop-1.24.0/lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.24.1 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.24.0 lib/rubocop/cop/style/empty_block_parameter.rb