Sha256: cb6ea1a628999f42b3eb9036c9ba84de42efbe817eacb64bbf3ab96df5e42af8

Contents?: true

Size: 1.1 KB

Versions: 62

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop 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 < Cop
        include EmptyParameter
        include RangeHelp

        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

        def autocorrect(node)
          lambda do |corrector|
            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
end

Version data entries

62 entries across 43 versions & 5 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-0.89.1 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-0.89.0 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-0.88.0 lib/rubocop/cop/style/empty_lambda_parameter.rb
rbhint-0.87.1.rc1 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-0.87.1 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-0.87.0 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-0.86.0 lib/rubocop/cop/style/empty_lambda_parameter.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/style/empty_lambda_parameter.rb
rbhint-0.85.1.rc2 lib/rubocop/cop/style/empty_lambda_parameter.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-0.85.1 lib/rubocop/cop/style/empty_lambda_parameter.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-0.85.0 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-0.84.0 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-0.83.0 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-0.82.0 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-0.81.0 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-0.80.1 lib/rubocop/cop/style/empty_lambda_parameter.rb
rubocop-0.80.0 lib/rubocop/cop/style/empty_lambda_parameter.rb