lib/puppet-check/data_parser.rb in puppet-check-1.0.0 vs lib/puppet-check/data_parser.rb in puppet-check-1.1.0

- old
+ new

@@ -11,11 +11,12 @@ begin parsed = YAML.load_file(file) rescue Psych::SyntaxError, StandardError => err PuppetCheck.error_files.push("-- #{file}:\n#{err.to_s.gsub("(#{file}): ", '')}") else - warnings = hiera(parsed) + # perform some rudimentary hiera checks if data exists + warnings = parsed.class.to_s == 'NilClass' ? [] : hiera(parsed) next PuppetCheck.warning_files.push("-- #{file}:\n#{warnings.join("\n")}") unless warnings.empty? PuppetCheck.clean_files.push("-- #{file}") end end end @@ -29,10 +30,12 @@ begin parsed = JSON.parse(File.read(file)) rescue JSON::ParserError => err PuppetCheck.error_files.push("-- #{file}:\n#{err.to_s.lines.first.strip}") else + warnings = [] + # check metadata.json if file =~ /.*metadata\.json$/ # metadata-json-lint has issues and is essentially no longer maintained so here is an improved and leaner version of it require 'spdx-licenses' @@ -64,22 +67,18 @@ 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? # check for warnings - warnings = [] - # check for spdx license (rubygems/util/licenses for rubygems >= 2.5 in the far future) if parsed.key?('license') && !SpdxLicenses.exist?(parsed['license']) && parsed['license'] !~ /[pP]roprietary/ warnings.push("License identifier '#{parsed['license']}' is not in the SPDX list: http://spdx.org/licenses/") end - - next PuppetCheck.warning_files.push("-- #{file}:\n#{warnings.join("\n")}") unless warnings.empty? else - # check for questionable hieradata - warnings = hiera(parsed) - next PuppetCheck.warning_files.push("-- #{file}:\n#{warnings.join("\n")}") unless warnings.empty? + # 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}") end end end