Sha256: 60fd2a02707b68fa53969fb4b95d07ffabced953dfd35c038b67ec9a9f8dde04

Contents?: true

Size: 1.1 KB

Versions: 25

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # 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) # rubocop:disable InternalAffairs/NumblockHandler
          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

25 entries across 23 versions & 4 rubygems

Version Path
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/style/empty_block_parameter.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/style/empty_block_parameter.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/rubocop-1.35.1/lib/rubocop/cop/style/empty_block_parameter.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.35.1/lib/rubocop/cop/style/empty_block_parameter.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.36.0/lib/rubocop/cop/style/empty_block_parameter.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.35.1/lib/rubocop/cop/style/empty_block_parameter.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.36.0/lib/rubocop/cop/style/empty_block_parameter.rb
zilla-0.2.0 vendor/bundle/ruby/3.2.0/gems/rubocop-1.46.0/lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.46.0 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.45.1 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.45.0 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.44.1 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.44.0 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.43.0 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.42.0 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.41.1 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.41.0 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.40.0 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.39.0 lib/rubocop/cop/style/empty_block_parameter.rb
rubocop-1.38.0 lib/rubocop/cop/style/empty_block_parameter.rb