Skip to content

Commit 2375f3f

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

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

lib/yard-sorbet/handlers/sig_handler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def parse_sig(docstring, include_params: true)
8888
NodeUtils.bfs_traverse(statement) do |node|
8989
case node.source
9090
when 'returns' then parse_return(node, docstring)
91-
when 'params' then include_params && parse_params(node, docstring)
91+
when 'params' then parse_params(node, docstring) if include_params
9292
when 'void' then TagUtils.upsert_tag(docstring, 'return', TagUtils::VOID_RETURN_TYPE)
9393
when 'abstract' then TagUtils.upsert_tag(docstring, 'abstract')
9494
end

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[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)