class Object

Constants

TOP_SCOPE_FACTS_VAR_TYPES

Public Instance Methods

check() click to toggle source
# File lib/puppet-lint/plugins/top_scope_facts.rb, line 3
def check
  whitelist = ['trusted', 'facts'] + (PuppetLint.configuration.top_scope_variables || [])
  whitelist = whitelist.join('|')
  tokens.select { |x| TOP_SCOPE_FACTS_VAR_TYPES.include?(x.type) }.each do |token|
    if token.value.match(/^::/) and not token.value.match(/^::(#{whitelist})\[?/)
      notify :warning, {
        :message => 'top scope fact instead of facts hash',
        :line    => token.line,
        :column  => token.column,
        :token   => token,
      }
    end
  end
end
fix(problem) click to toggle source
# File lib/puppet-lint/plugins/top_scope_facts.rb, line 19
def fix(problem)
  # This probably should never occur, but if it does then bail out:
  raise PuppetLint::NoFix if problem[:token].raw and problem[:token].value != problem[:token].raw

  problem[:token].value = "facts['" + problem[:token].value.sub(/^::/, '') + "']"
  problem[:token].raw = problem[:token].value unless problem[:token].raw.nil?
end