class RuboCop::Cop::Style::TrailingCommaInArguments

Checks for trailing comma in argument lists. The supported styles are:

for all parenthesized method calls with arguments.

parenthesized method calls where each argument is on its own line.

argument.

@example EnforcedStyleForMultiline: consistent_comma

# bad
method(1, 2,)

# good
method(1, 2)

# good
method(
  1, 2,
  3,
)

# good
method(
  1, 2, 3,
)

# good
method(
  1,
  2,
)

@example EnforcedStyleForMultiline: comma

# bad
method(1, 2,)

# good
method(1, 2)

# bad
method(
  1, 2,
  3,
)

# good
method(
  1, 2,
  3
)

# bad
method(
  1, 2, 3,
)

# good
method(
  1, 2, 3
)

# good
method(
  1,
  2,
)

@example EnforcedStyleForMultiline: no_comma (default)

# bad
method(1, 2,)

# good
method(1, 2)

# good
method(
  1,
  2
)

Public Class Methods

autocorrect_incompatible_with() click to toggle source
# File lib/rubocop/cop/style/trailing_comma_in_arguments.rb, line 91
def self.autocorrect_incompatible_with
  [Layout::HeredocArgumentClosingParenthesis]
end

Public Instance Methods

on_csend(node)
Alias for: on_send
on_send(node) click to toggle source
# File lib/rubocop/cop/style/trailing_comma_in_arguments.rb, line 95
def on_send(node)
  return unless node.arguments? && node.parenthesized?

  check(node, node.arguments, 'parameter of %<article>s method call',
        node.last_argument.source_range.end_pos,
        node.source_range.end_pos)
end
Also aliased as: on_csend