class RuboCop::Cop::Layout::ArrayAlignment
4, 5, 6]
array = [1, 2, 3,
# bad
4, 5, 6]
array = [1, 2, 3,
# good
@example EnforcedStyle: with_fixed_indentation
’run’]
‘forrest’,
array = [‘run’,
4, 5, 6]
array = [1, 2, 3,
# bad
’run’]
‘forrest’,
array = [‘run’,
4, 5, 6]
array = [1, 2, 3,
# good
@example EnforcedStyle: with_first_element (default)
aligned.
Check that the elements of a multi-line array literal are
def autocorrect(corrector, node)
def autocorrect(corrector, node) AlignmentCorrector.correct(corrector, processed_source, node, column_delta) end
def base_column(node, args)
def base_column(node, args) if fixed_indentation? lineno = target_method_lineno(node) line = node.source_range.source_buffer.source_line(lineno) indentation_of_line = /\S.*/.match(line).begin(0) indentation_of_line + configured_indentation_width else display_column(args.first.source_range) end end
def fixed_indentation?
def fixed_indentation? cop_config['EnforcedStyle'] == 'with_fixed_indentation' end
def message(_range)
def message(_range) fixed_indentation? ? FIXED_INDENT_MSG : ALIGN_ELEMENTS_MSG end
def on_array(node)
def on_array(node) return if node.children.size < 2 return if node.parent&.masgn_type? check_alignment(node.children, base_column(node, node.children)) end
def target_method_lineno(node)
def target_method_lineno(node) node.bracketed? ? node.loc.line : node.parent.loc.line end