Skip to content

Do not fail in case return tag has no type specified #268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PuppetStrings::Yard::Handlers::Puppet::FunctionHandler < PuppetStrings::Ya
def add_return_tag(object, type=nil)
tag = object.tag(:return)
if tag
if (type && tag.types.first) && (type != tag.types.first)
if (type && tag.types && tag.types.first) && (type != tag.types.first)
log.warn "Documented return type does not match return type in function definition near #{statement.file}:#{statement.line}."
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,29 @@
end
end

describe 'parsing a function with return tag without type', if: TEST_FUNCTION_RETURN_TYPE do
let(:source) { <<-SOURCE
# A simple foo function.
# @return This is something.
function foo() >> Struct[{'a' => Integer[1, 10]}] {
notice 'hello world'
}
SOURCE
}

it 'should get the return type from the function definition' do
expect{ subject }.to output('').to_stdout_from_any_process
expect(subject.size).to eq(1)
object = subject.first
expect(object).to be_a(PuppetStrings::Yard::CodeObjects::Function)
tags = object.docstring.tags(:return)
expect(tags.size).to eq(1)
expect(tags[0].tag_name).to eq('return')
expect(tags[0].text).to eq('This is something.')
expect(tags[0].types).to eq(["Struct[{'a' => Integer[1, 10]}]"])
end
end

describe 'parsing a function without a return tag or return type in the function definition' do
let(:source) { <<-SOURCE
# A simple foo function.
Expand Down