Class: HamlLint::RubyExtraction::HamlCommentChunk
- Defined in:
- lib/haml_lint/ruby_extraction/haml_comment_chunk.rb
Overview
Chunk for haml comments. Lines like ‘ -# Some commenting!`. Only deals with indentation while correcting, but can also be fused to a ScriptChunk.
Constant Summary
Constants inherited from BaseChunk
BaseChunk::COMMA_CHANGES_LINES
Instance Attribute Summary
Attributes inherited from BaseChunk
#end_marker_indent, #haml_line_index, #node, #ruby_lines, #start_marker_line_number
Instance Method Summary collapse
- #fuse(following_chunk) ⇒ Object
- #min_indent_of(lines) ⇒ Object
- #transfer_correction_logic(_coordinator, to_ruby_lines, haml_lines) ⇒ Object
Methods inherited from BaseChunk
#assemble_in, #full_assemble, #haml_end_line_index, #initialize, #nb_haml_lines, #skip_line_indexes_in_source_map, #start_marker_indent, #transfer_correction, #wrap_in_markers
Constructor Details
This class inherits a constructor from HamlLint::RubyExtraction::BaseChunk
Instance Method Details
#fuse(following_chunk) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/haml_lint/ruby_extraction/haml_comment_chunk.rb', line 7 def fuse(following_chunk) return unless following_chunk.is_a?(HamlCommentChunk) # We only merge consecutive comments # The main reason to want to at least merge those is # so that an empty comment doesn't get removed by rubocop by mistake return if @haml_line_index + 1 != following_chunk.haml_line_index HamlCommentChunk.new(node, @ruby_lines + following_chunk.ruby_lines, end_marker_indent: end_marker_indent) end |
#min_indent_of(lines) ⇒ Object
30 31 32 |
# File 'lib/haml_lint/ruby_extraction/haml_comment_chunk.rb', line 30 def min_indent_of(lines) lines.map { |l| l.index(/\S/) }.compact.min end |
#transfer_correction_logic(_coordinator, to_ruby_lines, haml_lines) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/haml_lint/ruby_extraction/haml_comment_chunk.rb', line 18 def transfer_correction_logic(_coordinator, to_ruby_lines, haml_lines) if to_ruby_lines.empty? haml_lines.slice!(@haml_line_index..haml_end_line_index) return end delta_indent = min_indent_of(to_ruby_lines) - min_indent_of(@ruby_lines) HamlLint::Utils.map_subset!(haml_lines, @haml_line_index..haml_end_line_index) do |l| HamlLint::Utils.indent(l, delta_indent) end end |