Class: PuppetLint
- Inherits:
-
Object
show all
- Defined in:
- lib/puppet-lint/lexer.rb,
lib/puppet-lint/plugins.rb,
lib/puppet-lint/version.rb,
lib/puppet-lint/lexer/token.rb,
lib/puppet-lint/configuration.rb,
lib/puppet-lint/tasks/puppet-lint.rb,
lib/puppet-lint.rb
Defined Under Namespace
Classes: Bin, CheckPlugin, Checks, Configuration, Lexer, LexerError, NoCodeError, Plugins, RakeTask
Constant Summary
collapse
- VERSION =
'0.3.2'
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of PuppetLint.
73
74
75
76
77
|
# File 'lib/puppet-lint.rb', line 73
def initialize
@data = nil
@statistics = {:error => 0, :warning => 0}
@fileinfo = {:path => ''}
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
71
72
73
|
# File 'lib/puppet-lint.rb', line 71
def data
@data
end
|
Instance Method Details
#code=(value) ⇒ Object
96
97
98
|
# File 'lib/puppet-lint.rb', line 96
def code=(value)
@data = value
end
|
#configuration ⇒ Object
83
84
85
|
# File 'lib/puppet-lint.rb', line 83
def configuration
self.class.configuration
end
|
#errors? ⇒ Boolean
141
142
143
|
# File 'lib/puppet-lint.rb', line 141
def errors?
@statistics[:error] != 0
end
|
#file=(path) ⇒ Object
87
88
89
90
91
92
93
94
|
# File 'lib/puppet-lint.rb', line 87
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
|
112
113
114
115
|
# File 'lib/puppet-lint.rb', line 112
def format_message(message)
format = log_format
puts format % message
end
|
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/puppet-lint.rb', line 100
def log_format
if configuration.log_format == ''
format = '%{KIND}: %{message} on line %{linenumber}'
if configuration.with_filename
format.prepend '%{path} - '
end
configuration.log_format = format
end
return configuration.log_format
end
|
#print_context(message, linter) ⇒ Object
117
118
119
120
121
122
123
124
125
|
# File 'lib/puppet-lint.rb', line 117
def print_context(message, linter)
return if message[:check] == 'documentation'
line = linter.manifest_lines[message[:linenumber] - 1]
offset = line.index(/\S/)
puts "\n #{line.strip}"
printf "%#{message[:column] + 2 - offset}s\n\n", '^'
end
|
#report(problems, linter) ⇒ Object
127
128
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/puppet-lint.rb', line 127
def report(problems, linter)
problems.each do |message|
@statistics[message[:kind]] += 1
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
print_context(message, linter) if configuration.with_context
end
end
end
|
#run ⇒ Object
149
150
151
152
153
154
155
156
157
|
# File 'lib/puppet-lint.rb', line 149
def run
if @data.nil?
raise PuppetLint::NoCodeError
end
linter = PuppetLint::Checks.new
problems = linter.run(@fileinfo, @data)
report problems, linter
end
|
#warnings? ⇒ Boolean
145
146
147
|
# File 'lib/puppet-lint.rb', line 145
def warnings?
@statistics[:warning] != 0
end
|