Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Build glob syntax support into the [PuppetLint] class by default. #86

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+27 −54
Split
View
@@ -19,7 +19,10 @@ guide](http://docs.puppetlabs.com/guides/style_guide.html) as practical.
You can test a single manifest file by running
- puppet-lint <path to file>
+ puppet-lint <path or glob>
+
+e.g.
+ puppet-lint ./**/*.pp
### Rake task
View
@@ -80,24 +80,7 @@ if ARGV[0].nil?
end
begin
- path = ARGV[0]
- if File.directory?(path)
- Dir.chdir(path)
- path = Dir.glob('**/*.pp')
- end
-
- path.each do |f|
- l = PuppetLint.new
- l.file = f
- l.run
- if l.errors? or (l.warnings? and PuppetLint.configuration.fail_on_warnings)
- exit 1
- end
- end
-
-rescue PuppetLint::NoCodeError
- puts "puppet-lint: no file specified or specified file does not exist"
- puts "puppet-lint: try 'puppet-lint --help' for more information"
- exit
+ l = PuppetLint.new(ARGV[0])
+ l.run
end
View
@@ -71,17 +71,14 @@ def expand opts = {}
end
end
-class PuppetLint::NoCodeError < StandardError; end
-
class PuppetLint
VERSION = '0.1.12'
- attr_reader :code, :file
+ attr_reader :path
- def initialize
- @data = nil
+ def initialize(path)
@statistics = {:error => 0, :warning => 0}
- @fileinfo = {:path => ''}
+ @path = path
end
def self.configuration
@@ -92,19 +89,6 @@ def configuration
self.class.configuration
end
- 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
-
- def code=(value)
- @data = value
- end
-
def log_format
if configuration.log_format == ''
## recreate previous old log format as far as thats possible.
@@ -122,19 +106,19 @@ def format_message(message)
puts format % message
end
- def report(problems)
+ def report(fileinfo, problems)
problems.each do |message|
@statistics[message[:kind]] += 1
## Add some default attributes.
- message.merge!(@fileinfo) {|key, v1, v2| v1 }
+ 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
-
+
def errors?
@statistics[:error] != 0
end
@@ -150,12 +134,19 @@ def checks
end
def run
- if @data.nil?
- raise PuppetLint::NoCodeError
- end
-
- PuppetLint::CheckPlugin.repository.each do |plugin|
- report plugin.new.run(@fileinfo, @data)
+ Dir.glob(path).each do |puppet_file|
+ puts "Evaluating #{puppet_file}"
+
+ # TODO: This meta-data extraction code is a perfect candidate for being
+ # moved into [PuppetLint::CheckPlugin].
+ data = File.read(puppet_file)
+ fileinfo = { :path => puppet_file,
+ :fullpath => File.expand_path(puppet_file),
+ :filename => File.basename(puppet_file) }
+
+ PuppetLint::CheckPlugin.repository.each do |plugin|
+ report(fileinfo, plugin.new.run(fileinfo, data))
+ end
end
end
end
@@ -9,12 +9,8 @@ def initialize(*args)
task :lint do
RakeFileUtils.send(:verbose, true) do
- linter = PuppetLint.new
- Dir.glob('**/*.pp').each do |puppet_file|
- puts "Evaluating #{puppet_file}"
- linter.file = puppet_file
- linter.run
- end
+ linter = PuppetLint.new('**/*.pp')
+ linter.run
fail if linter.errors?
end
end