Browse files

Check YAML files for syntax errors

Related story:
  https://www.pivotaltracker.com/story/show/18189131

Change-Id: Ie7b63bf8fa1e37050448f654544367702d4bfa65
  • Loading branch information...
1 parent 7537769 commit bb900e2dfe8acf688c148a3381042b4ab8de5620 Greg Hurrell committed Sep 12, 2011
Showing with 16 additions and 0 deletions.
  1. +16 −0 hooks/pre-commit
View
16 hooks/pre-commit
@@ -10,6 +10,7 @@ CHECKS = %w[
restricted_paths
ruby_syntax
whitespace
+ yaml_syntax
]
SCRIPTS_PATH = '.git/hooks/scripts/'
@@ -192,6 +193,21 @@ def check_whitespace
return ($?.exitstatus.zero? ? :good : :stop), output
end
+def check_yaml_syntax
+ clean = true
+ output = []
+ modified_files('yml').each do |file|
+ staged = StagedFile.new(file)
+ begin
+ YAML.load_file(staged.path)
+ rescue ArgumentError => e
+ output << "#{e.message} parsing #{file}"
+ clean = false
+ end
+ end
+ return (clean ? :good : :bad), output
+end
+
exit unless modified_files.any?
puts "Running pre-commit checks"

0 comments on commit bb900e2

Please sign in to comment.