lib/puppet-check/data_parser.rb in puppet-check-1.4.0 vs lib/puppet-check/data_parser.rb in puppet-check-1.4.1

- old
+ new

@@ -9,22 +9,22 @@ files.each do |file| # check yaml syntax begin parsed = YAML.load_file(file) rescue StandardError => err - PuppetCheck.error_files.push("#{file}:\n#{err.to_s.gsub("(#{file}): ", '')}") + PuppetCheck.settings[:error_files].push("#{file}:\n#{err.to_s.gsub("(#{file}): ", '')}") else warnings = [] # perform some rudimentary hiera checks if data exists and is hieradata warnings = hiera(parsed) unless (parsed.class.to_s == 'NilClass') || (File.basename(file) == 'hiera.yaml') # check that '---' does not show up more than once in the hieradata warnings.push('The string --- appears more than once in this data and Hiera will fail to parse it correctly.') if File.read(file).scan(/---/).count >= 2 - next PuppetCheck.warning_files.push("#{file}:\n#{warnings.join("\n")}") unless warnings.empty? - PuppetCheck.clean_files.push(file.to_s) + next PuppetCheck.settings[:warning_files].push("#{file}:\n#{warnings.join("\n")}") unless warnings.empty? + PuppetCheck.settings[:clean_files].push(file.to_s) end end end # checks json (.json) @@ -34,11 +34,11 @@ files.each do |file| # check json syntax begin parsed = JSON.parse(File.read(file)) rescue JSON::ParserError => err - PuppetCheck.error_files.push("#{file}:\n#{err.to_s.lines.first.strip}") + PuppetCheck.settings[:error_files].push("#{file}:\n#{err.to_s.lines.first.strip}") else warnings = [] # check metadata.json if File.basename(file) == 'metadata.json' @@ -47,16 +47,16 @@ # check for errors errors = [] # check for required keys - %w(name version author license summary source dependencies).each do |key| + %w[name version author license summary source dependencies].each do |key| errors.push("Required field '#{key}' not found.") unless parsed.key?(key) end # check requirements and dependencies keys - %w(requirements dependencies).each do |key| + %w[requirements dependencies].each do |key| # skip if key is missing or or value is an empty string, array, or hash next unless parsed.key?(key) next if parsed[key].empty? # check that dependencies and requirements are an array of hashes @@ -82,18 +82,18 @@ end end end # check for deprecated fields - %w(types checksum).each do |key| + %w[types checksum].each do |key| errors.push("Deprecated field '#{key}' found.") if parsed.key?(key) end # check for summary under 144 character errors.push('Summary exceeds 144 characters.') if parsed.key?('summary') && parsed['summary'].size > 144 - next PuppetCheck.error_files.push("#{file}:\n#{errors.join("\n")}") unless errors.empty? + next PuppetCheck.settings[:error_files].push("#{file}:\n#{errors.join("\n")}") unless errors.empty? # check for warnings # check for operatingsystem_support hash array if parsed.key?('operatingsystem_support') # check if operatingsystem_support array is actually empty @@ -126,11 +126,11 @@ # assume this is hieradata else # perform some rudimentary hiera checks if data exists warnings = hiera(parsed) unless parsed.class.to_s == 'NilClass' end - next PuppetCheck.warning_files.push("#{file}:\n#{warnings.join("\n")}") unless warnings.empty? - PuppetCheck.clean_files.push(file.to_s) + next PuppetCheck.settings[:warning_files].push("#{file}:\n#{warnings.join("\n")}") unless warnings.empty? + PuppetCheck.settings[:clean_files].push(file.to_s) end end end # checks hieradata