Sha256: de85931460944ab8831ea554e1817d6aa638d2f23e7bf052d089d3d9d5431fcb

Contents?: true

Size: 1.42 KB

Versions: 2

Compression:

Stored size: 1.42 KB

Contents

PuppetLint.new_check(:parameter_documentation) do
  def check
    class_indexes.concat(defined_type_indexes).each do |idx|
      next if idx[:param_tokens].nil?

      doc_params = []
      tokens[0..idx[:start]].reverse_each do |dtok|
        next if [:CLASS, :DEFINE, :NEWLINE, :WHITESPACE, :INDENT].include?(dtok.type)
        if [:COMMENT, :MLCOMMENT, :SLASH_COMMENT].include?(dtok.type)
          if dtok.value =~ /\A\s*\[\*([a-zA-Z0-9_]+)\*\]/ or
             dtok.value =~ /\A\s*\$([a-zA-Z0-9_]+):: +/ or
             dtok.value =~ /\A\s*@param ([a-zA-Z0-9_]+) +/
            doc_params << $1
          end
        else
          break
        end
      end

      params = []
      e = idx[:param_tokens].each
      begin
        while (ptok = e.next)
          if ptok.type == :VARIABLE
            params << ptok
            # skip to the next parameter to avoid finding default values of variables
            while true
              ptok = e.next
              break if ptok.type == :COMMA
            end
          end
        end
      rescue StopIteration; end

      params.each do |p|
        next if doc_params.include? p.value
        idx_type = idx[:type] == :CLASS ? "class" : "defined type"
        notify :warning, {
          :message => "missing documentation for #{idx_type} parameter #{idx[:name_token].value}::#{p.value}",
          :line    => p.line,
          :column  => p.column,
        }
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
puppet-lint-param-docs-1.4.1 lib/puppet-lint/plugins/check_parameter_documentation.rb
puppet-lint-param-docs-1.4.0 lib/puppet-lint/plugins/check_parameter_documentation.rb