Module: RuboCop::Cop::MultilineLiteralBraceLayout

Overview

Common functionality for checking the closing brace of a literal is either on the same line as the last contained elements, or a new line.

Instance Method Summary collapse

Methods included from ConfigurableEnforcedStyle

#alternative_style, #alternative_styles, #ambiguous_style_detected, #correct_style_detected, #detected_style, #detected_style=, #no_acceptable_style!, #no_acceptable_style?, #opposite_style_detected, #style, #style_detected, #style_parameter_name, #supported_styles, #unexpected_style_detected

Instance Method Details

#autocorrect(node) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb', line 20

def autocorrect(node)
  if closing_brace_on_same_line?(node)
    lambda do |corrector|
      corrector.insert_before(node.loc.end, "\n".freeze)
    end
  else
    lambda do |corrector|
      corrector.remove(range_with_surrounding_space(node.loc.end,
                                                    :left))

      corrector.insert_after(last_element_range_with_trailing_comma(node),
                             node.loc.end.source)
    end
  end
end

#check_brace_layout(node) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb', line 10

def check_brace_layout(node)
  return if ignored_literal?(node)

  # If the last node is or contains a conflicting HEREDOC, we don't want
  # to adjust the brace layout because this will result in invalid code.
  return if last_line_heredoc?(node.children.last)

  check(node)
end