Class: PuppetLint

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet-lint/plugin.rb,
lib/puppet-lint/plugins.rb,
lib/puppet-lint/configuration.rb,
lib/puppet-lint/tasks/puppet-lint.rb,
lib/puppet-lint.rb

Defined Under Namespace

Modules: Plugin Classes: CheckPlugin, Configuration, NoCodeError, Plugins, RakeTask

Constant Summary collapse

VERSION =
'0.1.12'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePuppetLint

Returns a new instance of PuppetLint.



81
82
83
84
85
# File 'lib/puppet-lint.rb', line 81

def initialize
  @data = nil
  @statistics = {:error => 0, :warning => 0}
  @fileinfo = {:path => ''}
end

Instance Attribute Details

#codeObject

Returns the value of attribute code.



79
80
81
# File 'lib/puppet-lint.rb', line 79

def code
  @code
end

#fileObject

Returns the value of attribute file.



79
80
81
# File 'lib/puppet-lint.rb', line 79

def file
  @file
end

Class Method Details

.configurationObject



87
88
89
# File 'lib/puppet-lint.rb', line 87

def self.configuration
  @configuration ||= PuppetLint::Configuration.new
end

Instance Method Details

#checksObject



146
147
148
149
150
# File 'lib/puppet-lint.rb', line 146

def checks
  PuppetLint::CheckPlugin.repository.map do |plugin|
    plugin.new.checks
  end.flatten
end

#configurationObject



91
92
93
# File 'lib/puppet-lint.rb', line 91

def configuration
  self.class.configuration
end

#errors?Boolean

Returns:

  • (Boolean)


138
139
140
# File 'lib/puppet-lint.rb', line 138

def errors?
  @statistics[:error] != 0
end

#format_message(message) ⇒ Object



120
121
122
123
# File 'lib/puppet-lint.rb', line 120

def format_message(message)
  format = log_format
  puts format % message
end

#log_formatObject



108
109
110
111
112
113
114
115
116
117
118
# 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) ⇒ Object



125
126
127
128
129
130
131
132
133
134
135
136
# 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

#runObject



152
153
154
155
156
157
158
159
160
# 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?Boolean

Returns:

  • (Boolean)


142
143
144
# File 'lib/puppet-lint.rb', line 142

def warnings?
  @statistics[:warning] != 0
end