Skip to content

Instantly share code, notes, and snippets.

@adreyer
Created September 30, 2014 16:07
Show Gist options
  • Save adreyer/92e3d4c602f74346f5c2 to your computer and use it in GitHub Desktop.
Save adreyer/92e3d4c602f74346f5c2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'puppet-lint'
require 'json'
glob = File.join(ARGV[0], "**/*")
# choose only the manifests we care about
manifests = Dir.glob(glob).select {|name| name =~ /\.pp/}
manifests = manifests.reject {|name| name =~ /tests\//}
manifests = manifests.reject {|name| name =~ /spec\//}
results = manifests.inject(Hash.new {|h,k| h[k] = 0}) do |results, filename|
linter = PuppetLint.new
manifest = File.read(filename) || ''
linter.code = manifest
linter.path = filename
linter.run
linter.problems.each do |prob|
check = prob[:check]
results[check] = results[check] + 1
end
results[:line_count] = results[:line_count] + manifest.lines.count
results[:manifest_count] = results[:manifest_count] + 1
results
end
puts JSON.pretty_generate( { name: 'lint',
version: 0,
release: ARGV[1],
results: results,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment