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.



896
897
898
# File 'lib/syntax_tree/node.rb', line 896

def initialize(lbracket)
  @lbracket = lbracket
end

Instance Attribute Details

#lbracketObject (readonly)

LBracket

the opening bracket



894
895
896
# File 'lib/syntax_tree/node.rb', line 894

def lbracket
  @lbracket
end

Instance Method Details

#format(q) ⇒ Object



900
901
902
903
904
905
906
907
908
909
910
911
912
# File 'lib/syntax_tree/node.rb', line 900

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