class PuppetLint

Constants

VERSION

Attributes

code[R]
file[R]

Public Class Methods

configuration() click to toggle source
# File lib/puppet-lint.rb, line 87
def self.configuration
  @configuration ||= PuppetLint::Configuration.new
end
new() click to toggle source
# File lib/puppet-lint.rb, line 81
def initialize
  @data = nil
  @statistics = {:error => 0, :warning => 0}
  @fileinfo = {:path => ''}
end

Public Instance Methods

checks() click to toggle source
# File lib/puppet-lint.rb, line 146
def checks
  PuppetLint::CheckPlugin.repository.map do |plugin|
    plugin.new.checks
  end.flatten
end
code=(value) click to toggle source
# File lib/puppet-lint.rb, line 104
def code=(value)
  @data = value
end
configuration() click to toggle source
# File lib/puppet-lint.rb, line 91
def configuration
  self.class.configuration
end
errors?() click to toggle source
# File lib/puppet-lint.rb, line 138
def errors?
  @statistics[:error] != 0
end
file=(path) click to toggle source
# File lib/puppet-lint.rb, line 95
def file=(path)
  if File.exist? path
    @fileinfo[:path] = path
    @fileinfo[:fullpath] = File.expand_path(path)
    @fileinfo[:filename] = File.basename(path)
    @data = File.read(path)
  end
end
format_message(message) click to toggle source
# File lib/puppet-lint.rb, line 120
def format_message(message)
  format = log_format
  puts format % message
end
log_format() click to toggle source
# File lib/puppet-lint.rb, line 108
def log_format
  if configuration.log_format == ''
    ## recreate previous old log format as far as thats possible.
    format = '%{KIND}: %{message} on line %{linenumber}'
    if configuration.with_filename
      format.prepend '%{path} - '
    end
    configuration.log_format = format
  end
  return configuration.log_format
end
report(problems) click to toggle source
# File lib/puppet-lint.rb, line 125
def report(problems)
  problems.each do |message|
    @statistics[message[:kind]] += 1
    ## Add some default attributes.
    message.merge!(@fileinfo) {|key, v1, v2| v1 }
    message[:KIND] = message[:kind].to_s.upcase

    if configuration.error_level == message[:kind] or configuration.error_level == :all
      format_message message
    end
  end
end
run() click to toggle source
# File lib/puppet-lint.rb, line 152
def run
  if @data.nil?
    raise PuppetLint::NoCodeError
  end

  PuppetLint::CheckPlugin.repository.each do |plugin|
    report plugin.new.run(@fileinfo, @data)
  end
end
warnings?() click to toggle source
# File lib/puppet-lint.rb, line 142
def warnings?
  @statistics[:warning] != 0
end