class RuboCop::Cop::Style::ClosingParenthesisIndentation
)
y
x,
def func(
# bad
)
y
a = b * (x +
# good: when x follows opening parenthesis, align parentheses
)
y
x,
func(
# good: when x is on its own line, indent this way
@example
closing parenthesis means ‘)` preceded by a line break.
method calls, method definitions, and grouped expressions. A hanging
This cops checks the indentation of hanging closing parentheses in
def check(node, elements)
def check(node, elements) right_paren = node.loc.end return unless right_paren return unless begins_its_line?(right_paren) correct_column = expected_column(node, elements) @column_delta = correct_column - right_paren.column return if @column_delta == 0 left_paren = node.loc.begin msg = correct_column == left_paren.column ? MSG_ALIGN : MSG_INDENT add_offense(right_paren, right_paren, msg) end
def expected_column(node, elements)
def expected_column(node, elements) left_paren = node.loc.begin if node.send_type? && fixed_parameter_indentation? || line_break_after_left_paren?(left_paren, elements) left_paren.source_line =~ /\S/ else left_paren.column end end
def fixed_parameter_indentation?
def fixed_parameter_indentation? config.for_cop('Style/AlignParameters')['EnforcedStyle'] == 'with_fixed_indentation' end
def line_break_after_left_paren?(left_paren, elements)
def line_break_after_left_paren?(left_paren, elements) elements.first && elements.first.loc.line > left_paren.line end
def on_begin(node)
def on_begin(node) check(node, node.children) end
def on_method_def(_node, _method_name, args, _body)
def on_method_def(_node, _method_name, args, _body) check(args, args.children) end
def on_send(node)
def on_send(node) _receiver, _method_name, *args = *node check(node, args) end