Class: HamlLint::RubyExtraction::PlaceholderMarkerChunk

Inherits:
BaseChunk
  • Object
show all
Defined in:
lib/haml_lint/ruby_extraction/placeholder_marker_chunk.rb

Overview

This chunk just adds a marker (with a custom name) to the generated Ruby and only attempts to transfer the corrections it receives to the indentation of the associated lines.

Also used so that Rubocop doesn’t think that there is nothing in ‘if` and other such structures, so that it does corrections that make sense for the HAML.

Constant Summary

Constants inherited from BaseChunk

BaseChunk::COMMA_CHANGES_LINES

Instance Attribute Summary

Attributes inherited from BaseChunk

#haml_line_index, #node, #ruby_lines, #start_marker_line_number

Instance Method Summary collapse

Methods inherited from BaseChunk

#assemble_in, #fuse, #nb_haml_lines, #skip_line_indexes_in_source_map, #start_marker_indent, #transfer_correction_logic, #wrap_in_markers

Constructor Details

#initialize(node, marker_name, indent:, nb_lines: 1, **kwargs) ⇒ PlaceholderMarkerChunk

Returns a new instance of PlaceholderMarkerChunk.



10
11
12
13
14
15
# File 'lib/haml_lint/ruby_extraction/placeholder_marker_chunk.rb', line 10

def initialize(node, marker_name, indent:, nb_lines: 1, **kwargs)
  @marker_name = marker_name
  @indent = indent
  @nb_lines = nb_lines
  super(node, nil, **kwargs.merge(end_marker_indent: @indent))
end

Instance Method Details

#end_marker_indentObject



36
37
38
# File 'lib/haml_lint/ruby_extraction/placeholder_marker_chunk.rb', line 36

def end_marker_indent
  @indent
end

#full_assemble(coordinator) ⇒ Object



17
18
19
20
# File 'lib/haml_lint/ruby_extraction/placeholder_marker_chunk.rb', line 17

def full_assemble(coordinator)
  @start_marker_line_number = coordinator.add_marker(@indent, name: @marker_name,
                                                   haml_line_index: haml_line_index)
end

#haml_end_line_indexObject



32
33
34
# File 'lib/haml_lint/ruby_extraction/placeholder_marker_chunk.rb', line 32

def haml_end_line_index
  haml_line_index + @nb_lines - 1
end

#transfer_correction(coordinator, all_corrected_ruby_lines, haml_lines) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/haml_lint/ruby_extraction/placeholder_marker_chunk.rb', line 22

def transfer_correction(coordinator, all_corrected_ruby_lines, haml_lines)
  marker_index = coordinator.find_line_index_of_marker_in_corrections(@start_marker_line_number,
                                                                      name: @marker_name)
  new_indent = all_corrected_ruby_lines[marker_index].index(/\S/)
  return if new_indent == @indent
  (haml_line_index..haml_end_line_index).each do |i|
    haml_lines[i] = HamlLint::Utils.indent(haml_lines[i], new_indent - @indent)
  end
end