Skip to content

Commit

Permalink
Print empty trees with comments
Browse files Browse the repository at this point in the history
Fixes #84.

Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
  • Loading branch information
Morriar committed Oct 5, 2021
1 parent 5de3f47 commit a7c39a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rbi/printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def accept_printer(v)
v.visit_all(comments)
end

unless root.empty?
unless root.empty? && root.comments.empty?
v.printn if strictness || !comments.empty?
v.visit(root)
end
Expand Down
11 changes: 11 additions & 0 deletions test/rbi/printer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,17 @@ def test_print_empty_comments
RBI
end

def test_print_empty_trees_with_comments
rbi = RBI::File.new(strictness: "true")
rbi.root.comments << RBI::Comment.new("foo")

assert_equal(<<~RBI, rbi.string)
# typed: true
# foo
RBI
end

def test_print_params_inline_comments
comments = [RBI::Comment.new("comment")]

Expand Down

0 comments on commit a7c39a1

Please sign in to comment.