Sha256: ee59a8852434d8e7140315f2638505b2d4b9e02afd020152c7bd557c0eaefeb0

Contents?: true

Size: 1.06 KB

Versions: 11

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # Checks for parentheses for empty lambda parameters. Parentheses
      # for empty lambda parameters do not cause syntax errors, but they are
      # redundant.
      #
      # @example
      #   # bad
      #   -> () { do_something }
      #
      #   # good
      #   -> { do_something }
      #
      #   # good
      #   -> (arg) { do_something(arg) }
      class EmptyLambdaParameter < Base
        include EmptyParameter
        include RangeHelp
        extend AutoCorrector

        MSG = 'Omit parentheses for the empty lambda parameters.'

        def on_block(node)
          send_node = node.send_node
          return unless send_node.send_type?

          check(node) if node.send_node.lambda_literal?
        end

        private

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

          corrector.remove(range)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/style/empty_lambda_parameter.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.31.2/lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-1.34.1 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-1.34.0 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-1.33.0 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-1.32.0 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-1.31.2 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-1.31.1 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-1.31.0 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-1.30.1 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-1.30.0 lib/rubocop/cop/style/empty_lambda_parameter.rb