Skip to content

Commit

Permalink
Fix YamlSyntax to specify aliases option (sds#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
sds committed Feb 26, 2022
1 parent c142cd2 commit 33d4ae7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/overcommit/hook/pre_commit/yaml_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions spec/overcommit/hook/pre_commit/yaml_syntax_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 33d4ae7

Please sign in to comment.