class DatarocketsStyle::Cop::Layout::ArrayAlignmentExtended
Here we check if the elements of a multi-line array literal are aligned.
@example EnforcedStyle: with_first_argument (default)
# good array = [1, 2, 3, 4, 5, 6] array = ['run', 'forrest', 'run'] # bad array = [1, 2, 3, 4, 5, 6] array = ['run', 'forrest', 'run']
@example EnforcedStyle: with_fixed_indentation
# good array = [1, 2, 3, 4, 5, 6] # bad array = [1, 2, 3, 4, 5, 6]
Constants
- ALIGN_PARAMS_MSG
- FIXED_INDENT_MSG
Public Instance Methods
autocorrect(node)
click to toggle source
# File lib/datarockets_style/cop/layout/array_alignment_extended.rb, line 50 def autocorrect(node) RuboCop::Cop::AlignmentCorrector.correct(processed_source, node, column_delta) end
on_array(node)
click to toggle source
# File lib/datarockets_style/cop/layout/array_alignment_extended.rb, line 44 def on_array(node) return if node.children.size < 2 check_alignment(node.children, base_column(node, node.children)) end
Private Instance Methods
base_column(node, args)
click to toggle source
# File lib/datarockets_style/cop/layout/array_alignment_extended.rb, line 64 def base_column(node, args) fixed_indentation? ? line_indentation(node) : display_column(args.first.source_range) end
fixed_indentation?()
click to toggle source
# File lib/datarockets_style/cop/layout/array_alignment_extended.rb, line 60 def fixed_indentation? cop_config["EnforcedStyle"] == "with_fixed_indentation" end
line_indentation(node)
click to toggle source
# File lib/datarockets_style/cop/layout/array_alignment_extended.rb, line 68 def line_indentation(node) lineno = target_method_lineno(node) line = node.source_range.source_buffer.source_line(lineno) line_indentation = /\S.*/.match(line).begin(0) line_indentation + configured_indentation_width end
message(_node)
click to toggle source
# File lib/datarockets_style/cop/layout/array_alignment_extended.rb, line 56 def message(_node) fixed_indentation? ? FIXED_INDENT_MSG : ALIGN_PARAMS_MSG end
target_method_lineno(node)
click to toggle source
# File lib/datarockets_style/cop/layout/array_alignment_extended.rb, line 75 def target_method_lineno(node) node.loc.line end