Module: RuboCop::Cop::MultilineLiteralBraceLayout
- Includes:
- ConfigurableEnforcedStyle
- Included in:
- Style::MultilineArrayBraceLayout, Style::MultilineHashBraceLayout, Style::MultilineMethodCallBraceLayout, Style::MultilineMethodDefinitionBraceLayout
- Defined in:
- lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb
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, #ambiguous_style_detected, #correct_style_detected, #detected_style, #detected_style=, #no_acceptable_style!, #no_acceptable_style?, #opposite_style_detected, #parameter_name, #style, #style_detected, #supported_styles, #unexpected_style_detected
Instance Method Details
#autocorrect(node) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb', line 21 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
11 12 13 14 15 16 17 18 19 |
# File 'lib/rubocop/cop/mixin/multiline_literal_brace_layout.rb', line 11 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 |