lib/puppet-lint/data.rb
# Internal: Calculate the positions of all resource declarations within the
# tokenised manifest. These positions only point to the content of the
# resource declarations, they do not include resource types or titles.
#
# Returns an Array of Hashes, each containing:
#   :start - An Integer position in the `tokens` Array pointing to the
#            first Token of a resource declaration.
#   :end   - An Integer position in the `tokens` Array pointing to the last
#            Token of a resource declaration.
Calculate the positions of all resource declarations within the
tokenised manifest. These positions only point to the content of the
resource declarations, they do not include resource types or titles.

Returns an Array of Hashes, each containing:
:start - An Integer position in the `tokens` Array pointing to the
first Token of a resource declaration.
:end   - An Integer position in the `tokens` Array pointing to the last
Token of a resource declaration.
Calculate the positions of all resource declarations within the tokenised manifest . These positions only point to the content of the resource declarations they do not include resource types or titles . Returns an Array of Hashes each containing : : start - An Integer position in the ` tokens ` Array pointing to the first Token of a resource declaration . : end - An Integer position in the ` tokens ` Array pointing to the last Token of a resource declaration .
def resource_indexes
      @resource_indexes ||= Proc.new do
        result = []
        tokens.each_index do |token_idx|
          if tokens[token_idx].type == :COLON
            next_token = tokens[token_idx].next_code_token
            depth = 1
            if next_token.type != :LBRACE
              tokens[(token_idx + 1)..-1].each_index do |idx|
                real_idx = token_idx + idx + 1
                if tokens[real_idx].type == :LBRACE
                  depth += 1
                elsif {:SEMIC => true, :RBRACE => true}.include? tokens[real_idx].type
                  unless tokens[real_idx].type == :SEMIC && depth > 1
                    depth -= 1
                    if depth == 0
                      result << {
                        :start        => token_idx + 1,
                        :end          => real_idx,
                        :tokens       => tokens[(token_idx + 1)..real_idx],
                        :type         => find_resource_type_token(token_idx),
                        :param_tokens => find_resource_param_tokens(tokens[(token_idx + 1)..real_idx]),
                      }
                      break
                    end
                  end
                end
              end
            end
          end
        end
        result
      end.call
    end
def resource_indexes @resource_indexes ||= Proc . new do result = [ ] tokens . each_index do | token_idx | if tokens [ token_idx ] . type == :COLON next_token = tokens [ token_idx ] . next_code_token depth = 1 if next_token . type != :LBRACE tokens [ ( token_idx + 1 ) .. - 1 ] . each_index do | idx | real_idx = token_idx + idx + 1 if tokens [ real_idx ] . type == :LBRACE depth += 1 elsif { :SEMIC => true , :RBRACE => true } . include? tokens [ real_idx ] . type unless tokens [ real_idx ] . type == :SEMIC && depth > 1 depth -= 1 if depth == 0 result << { :start => token_idx + 1 , :end => real_idx , :tokens => tokens [ ( token_idx + 1 ) .. real_idx ] , :type => find_resource_type_token ( token_idx ) , :param_tokens => find_resource_param_tokens ( tokens [ ( token_idx + 1 ) .. real_idx ] ) , } break end end end end end end end result end . call end
Internal: Calculate the positions of all resource declarations within the
tokenised manifest.
Internal : Calculate the positions of all resource declarations within the tokenised manifest .