Skip to content

Commit 65a44e8

Browse files
committed
Fix printing of multiline constants
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
1 parent d67b82e commit 65a44e8

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

lib/rbi/printer.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,13 @@ def oneline?(node)
675675
node.comments.empty? && node.empty?
676676
when Attr
677677
node.comments.empty? && node.sigs.empty?
678+
when Const
679+
return false unless node.comments.empty?
680+
681+
loc = node.loc
682+
return true unless loc
683+
684+
loc.begin_line == loc.end_line
678685
when Method
679686
node.comments.empty? && node.sigs.empty? && node.params.all? { |p| p.comments.empty? }
680687
when Sig

test/rbi/printer_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,8 +1113,10 @@ class << self; end
11131113
class TE < T::Enum; end
11141114
# file.rbi:1:3-2:4
11151115
class TS < T::Struct; end
1116+
11161117
# file.rbi:1:3-2:4
11171118
C = 42
1119+
11181120
# file.rbi:1:3-2:4
11191121
extend E
11201122
# file.rbi:1:3-2:4

0 commit comments

Comments
 (0)