Parent

Files

Class/Module Index [+]

Quicksearch

RuboCop::Cop::Style::SingleSpaceBeforeFirstArg

Checks that exactly one space is used between a method name and the first argument for method calls without parentheses.

@example

something  x
something   y, z

Constants

MSG

Public Instance Methods

autocorrect(range) click to toggle source
# File lib/rubocop/cop/style/single_space_before_first_arg.rb, line 34
def autocorrect(range)
  @corrections << ->(corrector) { corrector.replace(range, ' ') }
end
on_send(node) click to toggle source
# File lib/rubocop/cop/style/single_space_before_first_arg.rb, line 16
def on_send(node)
  return if parentheses?(node)

  _receiver, method_name, *args = *node
  return if args.empty?
  return if operator?(method_name)
  return if method_name.to_s.end_with?('=')

  arg1 = args.first.loc.expression
  return if arg1.line > node.loc.line

  arg1_with_space = range_with_surrounding_space(arg1, :left)
  space = Parser::Source::Range.new(arg1.source_buffer,
                                    arg1_with_space.begin_pos,
                                    arg1.begin_pos)
  add_offense(space, space) if space.length > 1
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.