Sha256: d81ec3eea0a548d08874c82fb651b0b8549026fe65c015df62cd1a8a4562b8aa
Contents?: true
Size: 1.78 KB
Versions: 8
Compression:
Stored size: 1.78 KB
Contents
require 'puppet-ghostbuster/puppetdb' class PuppetLint::Checks def load_data(path, content) lexer = PuppetLint::Lexer.new PuppetLint::Data.path = path begin PuppetLint::Data.manifest_lines = content.split("\n", -1) PuppetLint::Data.tokens = lexer.tokenise(content) PuppetLint::Data.parse_control_comments rescue PuppetLint::Data.tokens = [] end end end PuppetLint.new_check(:ghostbuster_files) do def manifests Dir.glob('./**/manifests/**/*.pp') end def check m = path.match(%r{.*/([^/]+)/files/(.+)$}) return if m.nil? puppetdb = PuppetGhostbuster::PuppetDB.new module_name, file_name = m.captures return if puppetdb.client.request('resources', [:'=', ['parameter', 'source'], "puppet:///modules/#{module_name}/#{file_name}"],).data.size > 0 dir_name = File.dirname(file_name) while dir_name != '.' do return if puppetdb.client.request( 'resources', [:'and', [:'or', [:'=', ['parameter', 'source'], "puppet:///modules/#{module_name}/#{dir_name}"], [:'=', ['parameter', 'source'], "puppet:///modules/#{module_name}/#{dir_name}/"], ], [:'=', ['parameter', 'recurse'], true], ], ).data.size > 0 dir_name = File.dirname(dir_name) end manifests.each do |manifest| return if File.readlines(manifest).grep(%r{["']#{module_name}/#{file_name}["']}).size > 0 if match = manifest.match(%r{.*/([^/]+)/manifests/.+$}) if match.captures[0] == module_name return if File.readlines(manifest).grep(/["']\$\{module_name\}\/#{file_name}["']/).size > 0 end end end notify :warning, { :message => "File #{module_name}/#{file_name} seems unused", :line => 1, :column => 1, } end end
Version data entries
8 entries across 8 versions & 1 rubygems