Skip to content

Commit ccd8867

Browse files
authored
Merge pull request #780 from Shopify/at-fix-type-alias
Do not associate a RBS comment to a node after a blank line
2 parents 751fac0 + 07db4aa commit ccd8867

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

lib/spoom/rbs.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,17 @@ 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+
break if comment_line < last_line - 1
86+
87+
last_line = comment_line
88+
8189
if string.start_with?("# @")
8290
string = string.delete_prefix("#").strip
8391
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)