Class: RuboCop::Cop::LineBreakCorrector
- Inherits:
-
Object
- Object
- RuboCop::Cop::LineBreakCorrector
- Extended by:
- Alignment, TrailingBody, Util
- Defined in:
- lib/rubocop/cop/correctors/line_break_corrector.rb
Overview
This class handles autocorrection for code that needs to be moved to new lines.
Constant Summary
Constants included from Alignment
Constants included from Util
Constants included from PathUtil
Class Attribute Summary collapse
-
.processed_source ⇒ Object
readonly
Returns the value of attribute processed_source.
Class Method Summary collapse
- .break_line_before(range:, node:, corrector:, configured_width:, indent_steps: 1) ⇒ Object
- .correct_trailing_body(configured_width:, corrector:, node:, processed_source:) ⇒ Object
- .move_comment(eol_comment:, node:, corrector:) ⇒ Object
Methods included from TrailingBody
body_on_first_line?, first_part_of, trailing_body?
Methods included from Util
add_parentheses, any_descendant?, args_begin, args_end, begins_its_line?, comment_line?, comment_lines?, double_quotes_required?, escape_string, first_part_of_call_chain, indent, interpret_string_escapes, line, line_range, needs_escaping?, on_node, parentheses?, parse_regexp, same_line?, to_string_literal, to_supported_styles, trim_string_interpolation_escape_character
Methods included from PathUtil
absolute?, glob?, hidden_dir?, hidden_file?, hidden_file_in_not_hidden_dir?, match_path?, maybe_hidden_file?, relative_path, remote_file?, smart_path
Class Attribute Details
permalink .processed_source ⇒ Object (readonly)
Returns the value of attribute processed_source.
13 14 15 |
# File 'lib/rubocop/cop/correctors/line_break_corrector.rb', line 13 def processed_source @processed_source end |
Class Method Details
permalink .break_line_before(range:, node:, corrector:, configured_width:, indent_steps: 1) ⇒ Object
[View source]
27 28 29 30 31 32 33 |
# File 'lib/rubocop/cop/correctors/line_break_corrector.rb', line 27 def break_line_before(range:, node:, corrector:, configured_width:, indent_steps: 1) corrector.insert_before( range, "\n#{' ' * (node.loc.keyword.column + (indent_steps * configured_width))}" ) end |
permalink .correct_trailing_body(configured_width:, corrector:, node:, processed_source:) ⇒ Object
[View source]
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rubocop/cop/correctors/line_break_corrector.rb', line 15 def correct_trailing_body(configured_width:, corrector:, node:, processed_source:) @processed_source = processed_source range = first_part_of(node.to_a.last) eol_comment = processed_source.comment_at_line(node.source_range.line) break_line_before(range: range, node: node, corrector: corrector, configured_width: configured_width) move_comment(eol_comment: eol_comment, node: node, corrector: corrector) remove_semicolon(node, corrector) end |
permalink .move_comment(eol_comment:, node:, corrector:) ⇒ Object
[View source]
35 36 37 38 39 40 41 |
# File 'lib/rubocop/cop/correctors/line_break_corrector.rb', line 35 def move_comment(eol_comment:, node:, corrector:) return unless eol_comment text = eol_comment.source corrector.insert_before(node, "#{text}\n#{' ' * node.loc.keyword.column}") corrector.remove(eol_comment) end |