Class: RuboCop::Cop::MultilineLiteralBraceCorrector

Inherits:
Object
  • Object
show all
Includes:
MultilineLiteralBraceLayout, RangeHelp
Defined in:
lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb

Overview

Autocorrection logic for the closing brace of a literal either on the same line as the last contained elements, or a new line.

Constant Summary

Constants included from RangeHelp

RangeHelp::BYTE_ORDER_MARK, RangeHelp::NOT_GIVEN

Class Method Summary collapse

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_configured?, #style_detected, #style_parameter_name, #supported_styles, #unexpected_style_detected

Constructor Details

#initialize(corrector, node, processed_source) ⇒ MultilineLiteralBraceCorrector

Returns a new instance of MultilineLiteralBraceCorrector.

 15 16 17 18 19
# File 'lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb', line 15 def initialize(corrector, node, processed_source) @corrector = corrector @node = node @processed_source = processed_source end

Class Method Details

.correct(corrector, node, processed_source) ⇒ Object

 11 12 13
# File 'lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb', line 11 def self.correct(corrector, node, processed_source) new(corrector, node, processed_source).call end

Instance Method Details

#callObject

 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
# File 'lib/rubocop/cop/correctors/multiline_literal_brace_corrector.rb', line 21 def call if closing_brace_on_same_line?(node) correct_same_line_brace(corrector) else # When a comment immediately before the closing brace gets in the  # way of an easy correction, the offense is reported but not auto-  # corrected. The user must handle the delicate decision of where to  # put the comment.  return if new_line_needed_before_closing_brace?(node) end_range = last_element_range_with_trailing_comma(node).end correct_next_line_brace(corrector, end_range) correct_heredoc_argument_method_chain(corrector, end_range) end end