Skip to content

Commit 96c2d0e

Browse files
authored
Merge pull request #268 from tiandrey/main
Do not fail in case return tag has no type specified
2 parents 2954c84 + 63220a7 commit 96c2d0e

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/puppet-strings/yard/handlers/puppet/function_handler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class PuppetStrings::Yard::Handlers::Puppet::FunctionHandler < PuppetStrings::Ya
3939
def add_return_tag(object, type=nil)
4040
tag = object.tag(:return)
4141
if tag
42-
if (type && tag.types.first) && (type != tag.types.first)
42+
if (type && tag.types && tag.types.first) && (type != tag.types.first)
4343
log.warn "Documented return type does not match return type in function definition near #{statement.file}:#{statement.line}."
4444
end
4545

spec/unit/puppet-strings/yard/handlers/puppet/function_handler_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,29 @@
256256
end
257257
end
258258

259+
describe 'parsing a function with return tag without type', if: TEST_FUNCTION_RETURN_TYPE do
260+
let(:source) { <<-SOURCE
261+
# A simple foo function.
262+
# @return This is something.
263+
function foo() >> Struct[{'a' => Integer[1, 10]}] {
264+
notice 'hello world'
265+
}
266+
SOURCE
267+
}
268+
269+
it 'should get the return type from the function definition' do
270+
expect{ subject }.to output('').to_stdout_from_any_process
271+
expect(subject.size).to eq(1)
272+
object = subject.first
273+
expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
274+
tags = object.docstring.tags(:return)
275+
expect(tags.size).to eq(1)
276+
expect(tags[0].tag_name).to eq('return')
277+
expect(tags[0].text).to eq('This is something.')
278+
expect(tags[0].types).to eq(["Struct[{'a' => Integer[1, 10]}]"])
279+
end
280+
end
281+
259282
describe 'parsing a function without a return tag or return type in the function definition' do
260283
let(:source) { <<-SOURCE
261284
# A simple foo function.

0 commit comments

Comments
 (0)