Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
wants to merge 1 commit into from

2 participants

@clowder

Hey,

Firstly, awesome tool, thanks!

Thought that it might be nice to have glob syntax be part of the [PuppetLint] class.

As a result I was able to remove all setters (OOP & encapsulation yay) and it exposed another bit of replication that could be moved to a new home (another feature branch coming soon).

Hope this looks OK to you?

Cheers,
Chris

@clowder

Rebased off current master.

@rodjek
Owner

Thanks for the submission however I'm actually trying to move it in the complete opposite direction (make PuppetLint a library that accepts manifests as strings and move all the file reading code into the bin script.

@rodjek rodjek closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
5 README.md
@@ -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
21 bin/puppet-lint
@@ -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
47 lib/puppet-lint.rb
@@ -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,11 +106,11 @@ 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
@@ -134,7 +118,7 @@ def report(problems)
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
View
8 lib/puppet-lint/tasks/puppet-lint.rb
@@ -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
Something went wrong with that request. Please try again.