Skip to content

Commit a9d8e00

Browse files
committed
Do not associate a RBS comment to a node after a blank line
Signed-off-by: Alexandre Terrasa <alexandre.terrasa@shopify.com>
1 parent 8070574 commit a9d8e00

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

lib/spoom/rbs.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,19 @@ def node_rbs_comments(node)
7575

7676
continuation_comments = [] #: Array[Prism::Comment]
7777

78+
last_line = node.location.start_line
79+
7880
comments.each do |comment|
7981
string = comment.slice
8082

83+
comment_line = comment.location.end_line
84+
85+
if comment_line < last_line - 1
86+
break
87+
end
88+
89+
last_line = comment_line
90+
8191
if string.start_with?("# @")
8292
string = string.delete_prefix("#").strip
8393
res.annotations << Annotation.new(string, comment.location)

test/spoom/sorbet/translate/rbs_comments_to_sorbet_sigs_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,26 @@ def test_translate_to_rbi_defs_within_send
426426
RBS
427427
end
428428

429+
def test_translate_to_rbi_selects_right_comments
430+
contents = <<~RB
431+
#: -> void
432+
433+
class Foo
434+
#: -> void
435+
436+
#: -> void
437+
438+
class << self
439+
#: -> void
440+
441+
def bar; end
442+
end
443+
end
444+
RB
445+
446+
assert_equal(contents, rbs_comments_to_sorbet_sigs(contents))
447+
end
448+
429449
private
430450

431451
#: (String, ?max_line_length: Integer?) -> String

0 commit comments

Comments
 (0)