Skip to content

Commit c344657

Browse files
committed
Warn on undocumentable attrs
1 parent 8759e7e commit c344657

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/yard-sorbet/node_utils.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ def self.sigable_node?(node)
6262
sig { params(attr_node: YARD::Parser::Ruby::MethodCallNode).returns(T::Array[String]) }
6363
def self.validated_attribute_names(attr_node)
6464
attr_node.parameters(false).map do |obj|
65-
case obj.type
66-
when :symbol_literal then obj.jump(:ident, :op, :kw, :const).source
67-
when :string_literal then obj.jump(:string_content).source
65+
case obj
66+
when YARD::Parser::Ruby::LiteralNode then obj.dig(0, 0).source
67+
else raise YARD::Parser::UndocumentableError, obj.source
6868
end
6969
end
7070
end

spec/yard_sorbet/handlers/sig_handler_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,4 +496,21 @@
496496
end
497497
end
498498
end
499+
500+
describe 'Unparsable sigs' do
501+
before do
502+
allow(log).to receive(:warn)
503+
YARD::Parser::SourceParser.parse_string(<<~RUBY)
504+
class Test
505+
CONST = :foo
506+
sig { returns(Integer) }
507+
attr_reader CONST
508+
end
509+
RUBY
510+
end
511+
512+
it 'warn when parsing an attr* with a constant param' do
513+
expect(log).to have_received(:warn).with(/Undocumentable CONST/).twice
514+
end
515+
end
499516
end

0 commit comments

Comments
 (0)