Class: SyntaxTree::ArrayLiteral::EmptyWithCommentsFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/node.rb

Overview

This is a special formatter used if the array literal contains no values but does contain comments. In this case we do some special formatting to make sure the comments gets indented properly.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lbracket) ⇒ EmptyWithCommentsFormatter

Returns a new instance of EmptyWithCommentsFormatter.



875
876
877
# File 'lib/syntax_tree/node.rb', line 875

def initialize(lbracket)
  @lbracket = lbracket
end

Instance Attribute Details

#lbracketObject (readonly)

LBracket

the opening bracket



873
874
875
# File 'lib/syntax_tree/node.rb', line 873

def lbracket
  @lbracket
end

Instance Method Details

#format(q) ⇒ Object



879
880
881
882
883
884
885
886
887
888
889
890
891
# File 'lib/syntax_tree/node.rb', line 879

def format(q)
  q.group do
    q.text("[")
    q.indent do
      lbracket.comments.each do |comment|
        q.breakable(force: true)
        comment.format(q)
      end
    end
    q.breakable(force: true)
    q.text("]")
  end
end