Skip to content

Commit 0b1a095

Browse files
authored
Merge pull request #159 from pegasd/fix_return_type_matching
Fix return type matching for Puppet functions
2 parents 7dff756 + 4db84c8 commit 0b1a095

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

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

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

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
let(:source) { 'function foo{' }
2121

2222
it 'should log an error' do
23-
expect{ subject }.to output(/\[error\]: Failed to parse \(stdin\): Syntax error at end of file/).to_stdout_from_any_process
23+
expect{ subject }.to output(/\[error\]: Failed to parse \(stdin\): Syntax error at end of/).to_stdout_from_any_process
2424
expect(subject.empty?).to eq(true)
2525
end
2626
end
@@ -216,6 +216,21 @@
216216
end
217217
end
218218

219+
describe 'parsing a function with a non-conflicting return tag and type in function definition', if: TEST_FUNCTION_RETURN_TYPE do
220+
let(:source) { <<-SOURCE
221+
# A simple foo function
222+
# @return [String] Hi there
223+
function foo() >> String {
224+
notice 'hi there'
225+
}
226+
SOURCE
227+
}
228+
229+
it 'should not output a warning if return types match' do
230+
expect{ subject }.not_to output(/Documented return type does not match return type in function definition/).to_stdout_from_any_process
231+
end
232+
end
233+
219234
describe 'parsing a function with a conflicting return tag and type in function definition', if: TEST_FUNCTION_RETURN_TYPE do
220235
let(:source) { <<-SOURCE
221236
# A simple foo function.

0 commit comments

Comments
 (0)