From 3151e4e1b131590ea5a59fe0af48e94df9b589c2 Mon Sep 17 00:00:00 2001 From: Ian Kronquist Date: Fri, 18 Sep 2015 16:00:14 -0700 Subject: [PATCH 1/2] (PDOC-56) Fix type warning for defined types Puppet defined types would print the string representation of the ruby object, and not representation you would see in puppet. This is the difference between `Puppet::Pops::Types::PStringType` and `String`. --- .../strings/yard/templates/default/template_helper.rb | 8 ++++---- .../puppetlabs/strings/yard/host_class_handler_spec.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/puppet_x/puppetlabs/strings/yard/templates/default/template_helper.rb b/lib/puppet_x/puppetlabs/strings/yard/templates/default/template_helper.rb index 1f3608d..fab415b 100644 --- a/lib/puppet_x/puppetlabs/strings/yard/templates/default/template_helper.rb +++ b/lib/puppet_x/puppetlabs/strings/yard/templates/default/template_helper.rb @@ -118,7 +118,7 @@ class TemplateHelper function.keys.each do |key| if function[key].class == String begin - instantiated = type_parser.parse function[key].gsub(/'/, '').gsub(/"/, "") + instantiated = type_parser.parse function[key] rescue Puppet::ParseError # Likely the result of a malformed type next @@ -132,15 +132,15 @@ class TemplateHelper param_instantiated = type_parser.parse type if not type_calculator.assignable? instantiated, param_instantiated actual_types = object.type_info.map do |sig| - sig[key] - end + sig[key].to_s if sig[key] + end.compact # Get the locations where the object can be found. We only care about # the first one. locations = object.files warning = <<-EOS [warn]: @param tag types do not match the code. The #{param[:name]} parameter is declared as types #{param[:types]} in the docstring, - but the code specifies the types #{actual_types.inspect} + but the code specifies the types #{actual_types} EOS # If the locations aren't in the shape we expect then report that diff --git a/spec/unit/puppet_x/puppetlabs/strings/yard/host_class_handler_spec.rb b/spec/unit/puppet_x/puppetlabs/strings/yard/host_class_handler_spec.rb index 96e9186..c31e184 100644 --- a/spec/unit/puppet_x/puppetlabs/strings/yard/host_class_handler_spec.rb +++ b/spec/unit/puppet_x/puppetlabs/strings/yard/host_class_handler_spec.rb @@ -79,7 +79,7 @@ Puppet Types: 0 ( 0 undocumented) Puppet Providers: 0 ( 0 undocumented) 100.00% documented output - expected_stderr = "[warn]: @param tag types do not match the code. The ident\n parameter is declared as types [\"Float\"] in the docstring,\n but the code specifies the types [Puppet::Pops::Types::PStringType]\n in the file manifests/init.pp near line 2.\n" + expected_stderr = "[warn]: @param tag types do not match the code. The ident\n parameter is declared as types [\"Float\"] in the docstring,\n but the code specifies the types [\"String\"]\n in the file manifests/init.pp near line 2.\n" expect { expect { From 97acd1b0b307ba23bd9e80d8e42b93d8d26d729e Mon Sep 17 00:00:00 2001 From: Ian Kronquist Date: Fri, 18 Sep 2015 16:03:52 -0700 Subject: [PATCH 2/2] (PDOC-57) Get the content of the string We used to extract the string from the source code. We should have extracted the content of the string. This is the difference between `"String"` and `String`. --- .../strings/yard/handlers/puppet_4x_function_handler.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_4x_function_handler.rb b/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_4x_function_handler.rb index 46967fc..298c8da 100644 --- a/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_4x_function_handler.rb +++ b/lib/puppet_x/puppetlabs/strings/yard/handlers/puppet_4x_function_handler.rb @@ -30,8 +30,9 @@ class Puppet4xFunctionHandler < YARD::Handlers::Ruby::Base return [] if command.children.length < 2 or command.children[1].children.length < 2 type_specifier = command.children[1] # the parameter signature is the first child of the specifier and an - # identifier. Convert it to a string. - param_signature = type_specifier.children[0].source + # identifier. Jump to the content inside the quotes and convert it to a + # string. + param_signature = type_specifier.children[0].jump(:tstring_content).source # The parameter name is the second child of the specifier and a symbol. # convert it to a string. param_name_ident = type_specifier.jump :ident