diff --git a/lib/rbi/printer.rb b/lib/rbi/printer.rb index ac2589b7..9d179ee4 100644 --- a/lib/rbi/printer.rb +++ b/lib/rbi/printer.rb @@ -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 diff --git a/test/rbi/printer_test.rb b/test/rbi/printer_test.rb index 19842ec6..9c565ef7 100644 --- a/test/rbi/printer_test.rb +++ b/test/rbi/printer_test.rb @@ -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")]