Created
September 19, 2021 05:40
-
-
Save salopst/c6146e09f65db560a9b36ca9958ce290 to your computer and use it in GitHub Desktop.
Bulk validate YAML... in this case to track down a Jekyll error: "The value '{}' was passed to a date-related filter that expects valid dates in /_layouts/default.html or one of its layouts."
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# 2021-09-19 | |
# https://stackoverflow.com/questions/34150923/bulk-validating-yaml-files | |
require "yaml" | |
def check_file(filename) | |
YAML.parse_file(filename) | |
puts "OK" | |
0 | |
rescue Psych::SyntaxError => ex | |
puts "Error#{ex.message[/: .+/]}" | |
1 | |
end | |
exit_code = 0 | |
max_filename_length = ARGV.max_by(&:size).size | |
ARGV.each do |filename| | |
printf "%-*s ", max_filename_length, filename | |
exit_code |= check_file(filename) | |
end | |
exit exit_code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment