From 5977db35c4d42ca846b6a468a7b3228b77cfdcfd Mon Sep 17 00:00:00 2001 From: Shane da Silva Date: Fri, 25 Feb 2022 22:28:17 -0800 Subject: [PATCH] Fix `YamlSyntax` to specify `aliases` option --- lib/overcommit/hook/pre_commit/yaml_syntax.rb | 10 +++++++--- spec/overcommit/hook/pre_commit/yaml_syntax_spec.rb | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/overcommit/hook/pre_commit/yaml_syntax.rb b/lib/overcommit/hook/pre_commit/yaml_syntax.rb index fa0c4e66..493e9c5a 100644 --- a/lib/overcommit/hook/pre_commit/yaml_syntax.rb +++ b/lib/overcommit/hook/pre_commit/yaml_syntax.rb @@ -8,9 +8,13 @@ def run applicable_files.each do |file| begin - YAML.load_file(file) - rescue ArgumentError, Psych::SyntaxError => e - messages << Overcommit::Hook::Message.new(:error, file, nil, e.message) + YAML.load_file(file, aliases: true) + rescue ArgumentError + begin + YAML.load_file(file) + rescue ArgumentError, Psych::SyntaxError => e + messages << Overcommit::Hook::Message.new(:error, file, nil, e.message) + end end end diff --git a/spec/overcommit/hook/pre_commit/yaml_syntax_spec.rb b/spec/overcommit/hook/pre_commit/yaml_syntax_spec.rb index 29cb7b02..a6f61f2c 100644 --- a/spec/overcommit/hook/pre_commit/yaml_syntax_spec.rb +++ b/spec/overcommit/hook/pre_commit/yaml_syntax_spec.rb @@ -22,6 +22,7 @@ context 'when YAML file has errors' do before do + YAML.stub(:load_file).with(staged_file, { aliases: true }).and_raise(ArgumentError) YAML.stub(:load_file).with(staged_file).and_raise(ArgumentError) end