Skip to content

Commit fcadea8

Browse files
committed
Skip RBS comments in YardDoc listener
YardDoc listener thinks they are method comments and adds it to the RBI when they are already translated to sigs.
1 parent 69ec4aa commit fcadea8

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

lib/tapioca/gem/listeners/yard_doc.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ def initialize(pipeline)
3030

3131
private
3232

33+
#: (String line) -> bool
34+
def rbs_comment?(line)
35+
line.strip.start_with?(": ", "| ")
36+
end
37+
3338
# @override
3439
#: (ConstNodeAdded event) -> void
3540
def on_const(event)
@@ -61,7 +66,7 @@ def documentation_comments(name, sigs: [])
6166
return [] if /(copyright|license)/i.match?(docstring)
6267

6368
comments = docstring.lines
64-
.reject { |line| IGNORED_COMMENTS.any? { |comment| line.include?(comment) } }
69+
.reject { |line| IGNORED_COMMENTS.any? { |comment| line.include?(comment) } || rbs_comment?(line) }
6570
.map! { |line| RBI::Comment.new(line) }
6671

6772
tags = yard_docs.tags

spec/tapioca/gem/pipeline_spec.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4722,12 +4722,28 @@ def foo; end
47224722
# typed: true
47234723
47244724
# @requires_ancestor: Kernel
4725-
class Foo; end
4725+
class Foo
4726+
#: -> void
4727+
#:comment:
4728+
def foo; end
4729+
4730+
#: -> Array[
4731+
#| String
4732+
#| ]
4733+
def bar; end
4734+
end
47264735
RUBY
47274736

47284737
output = template(<<~RBI)
47294738
class Foo
47304739
requires_ancestor { Kernel }
4740+
4741+
sig { returns(T::Array[::String]) }
4742+
def bar; end
4743+
4744+
# :comment:
4745+
sig { void }
4746+
def foo; end
47314747
end
47324748
RBI
47334749

0 commit comments

Comments
 (0)