(PDOC-37) Warn if parameter names don't match docs

Print the name of the parameter, the file, and the line number to stderr if the
parameter name does not match the name specified in the docs.
In order for this to be useful we need to present the user with the file name
and line number of the relevant parameters. This information needs to be
extracted from the code object and passed to the extract_param_details method.
This commit is contained in:
Ian Kronquist 2015-06-24 12:36:13 -07:00
parent 584b87e6c7
commit 49171c92b9
3 changed files with 13 additions and 6 deletions

View File

@ -18,7 +18,7 @@ def parameter_details
@param_details = []
@param_details = @template_helper.extract_param_details(params, param_tags, true)
@param_details = @template_helper.extract_param_details(params, param_tags, object.files, true)
erb(:parameter_details)
end

View File

@ -75,7 +75,7 @@ def method_details_list
# Convert the matched string into an array of strings
params = parameters.nil? ? nil : parameters[1].split(/\s*,\s*/)
param_details = @template_helper.extract_param_details(params, param_tags) unless params.nil?
param_details = @template_helper.extract_param_details(params, param_tags, object.files) unless params.nil?
else
param_details = @template_helper.comment_only_param_details(param_tags)
end

View File

@ -1,7 +1,8 @@
require "puppet"
# A class containing helper methods to aid in the extraction of relevant data
# from comments and YARD tags
class TemplateHelper
# Extracts data from comments which include the supported YARD tags
def extract_tag_data(object)
examples = Hash.new
@ -35,13 +36,12 @@ class TemplateHelper
# :desc => [String] The description provided in the comment
# :types => [Array] The parameter type(s) specified in the comment
# :exists => [Boolean] True only if the parameter exists in the documented logic and not just in a comment}
def extract_param_details(parameters, tags_hash, fq_name = false)
def extract_param_details(parameters, tags_hash, locations, fq_name = false)
parameter_info = []
# Extract the information for parameters that actually exist
# Extract the information for parameters that exist
# as opposed to parameters that are defined only in the comments
parameters.each do |param|
if fq_name
param_name = param[0]
fully_qualified_name = param[1]
@ -73,6 +73,13 @@ class TemplateHelper
end
if !param_exists
parameter_info.push({:name => tag.name, :desc => tag.text, :types => tag.types, :exists? => false})
if locations.length >= 1 and locations[0].length == 2
file_name = locations[0][0]
line_number = locations[0][1]
$stderr.puts "[warn]: The parameter #{tag.name} is documented, but doesn't exist in your code, in file #{file_name} near line #{line_number}"
else
$stderr.puts "[warn]: The parameter #{tag.name} is documented, but doesn't exist in your code. Sorry, the file and line number could not be determined."
end
end
end