Class: DatarocketsStyle::Cop::Layout::ArrayAlignmentExtended

Inherits:
RuboCop::Cop::Base
  • Object
show all
Extended by:
RuboCop::Cop::AutoCorrector
Includes:
RuboCop::Cop::Alignment
Defined in:
lib/datarockets_style/cop/layout/array_alignment_extended.rb

Overview

Here we check if the elements of a multi-line array literal are aligned.

Examples:

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']

EnforcedStyle: with_fixed_indentation

# good

array = [1, 2, 3,
  4, 5, 6]

# bad

array = [1, 2, 3,
         4, 5, 6]

Constant Summary collapse

ALIGN_PARAMS_MSG =
"Align the elements of an array literal if they span more than one line."
FIXED_INDENT_MSG =
"Use one level of indentation for elements " \
"following the first line of a multi-line array."

Instance Method Summary collapse

Instance Method Details

#autocorrect(corrector, node) ⇒ Object



51
52
53
# File 'lib/datarockets_style/cop/layout/array_alignment_extended.rb', line 51

def autocorrect(corrector, node)
  RuboCop::Cop::AlignmentCorrector.correct(corrector, processed_source, node, column_delta)
end

#on_array(node) ⇒ Object



45
46
47
48
49
# File 'lib/datarockets_style/cop/layout/array_alignment_extended.rb', line 45

def on_array(node)
  return if node.children.size < 2

  check_alignment(node.children, base_column(node, node.children))
end