Class: RuboCop::Cop::Yoshiki::Haml::SiblingBlankSource

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/cop/yoshiki/haml/sibling_blank_lines.rb

Overview

Walk a Haml AST and rewrite sibling blank lines.

Constant Summary collapse

MSG_MISSING =
'Add a blank line between sibling layout elements.'.freeze
MSG_EXTRA =
'Remove the blank line between packed sibling leaves.'.freeze
CONTROL =
%w[else elsif when rescue ensure].freeze

Instance Method Summary collapse

Instance Method Details

#operations(source) ⇒ Object



19
20
21
22
23
24
25
26
# File 'lib/rubocop/cop/yoshiki/haml/sibling_blank_lines.rb', line 19

def operations source
  ast = parse(source)
  return [] unless ast

  ops = []
  collect(ast, source.lines, ops)
  ops
end

#rewrite(source) ⇒ Object



15
16
17
# File 'lib/rubocop/cop/yoshiki/haml/sibling_blank_lines.rb', line 15

def rewrite source
  apply(source.lines, events_for(operations(source))).join
end