Sha256: 14bab9be40b37ed8e88ef80fb5ce6cb513fdbf2aef76d787ce240ec07ace2bcb

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 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

1 entries across 1 versions & 1 rubygems

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