Parent

Methods

Files

Class/Module Index [+]

Quicksearch

RuboCop::Cop::Style::SingleLineBlockParams

This cop checks whether the block parameters of a single-line method accepting a block match the names specified via configuration.

For instance one can configure `reduce`(`inject`) to use |a, e| as parameters.

Public Instance Methods

on_block(node) click to toggle source
# File lib/rubocop/cop/style/single_line_block_params.rb, line 11
def on_block(node)
  # we care only for single line blocks
  return unless Util.block_length(node) == 0

  method_node, args_node, _body_node = *node
  receiver, method_name, _method_args = *method_node

  # discard other scenarios
  return unless receiver
  return unless method_names.include?(method_name)

  # discard cases with argument destructuring
  args = *args_node

  return true unless args.all? { |n| n.type == :arg }
  return if args_match?(method_name, args)

  add_offense(args_node, :expression, message(method_name))
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.