class RuboCop::Cop::Lint::TrailingCommaInAttributeDeclaration


end
end
puts “No problem!”
def bar
attr_reader :foo
class Foo
# good
end
end
puts “Unreachable.”
def bar
attr_reader :foo,
class Foo
# bad
@example
definition by overriding it with a getter method.
‘#attr_reader`. Leaving a trailing comma will nullify the next method
This cop checks for trailing commas in attribute declarations, such as

def on_send(node)

def on_send(node)
  return unless node.attribute_accessor? && node.arguments.last.def_type?
  trailing_comma = trailing_comma_range(node)
  add_offense(trailing_comma) { |corrector| corrector.remove(trailing_comma) }
end

def trailing_comma_range(node)

def trailing_comma_range(node)
  range_with_surrounding_space(
    range: node.arguments[-2].source_range,
    side: :right
  ).end.resize(1)
end