Skip to content

Commit 192c84b

Browse files
authored
Fail on yaml lint errors (sds#738)
* Fail on yaml lint errors Fixes sds#737 * Fix yaml lint spec after enabling failure on YamlLint * Fix syntax error in yaml_lint.rb * Use fail_hook instead of fail for spec file * Fix if/else syntax to use elsif * Fix yaml_lint linter errors
1 parent 3d5c5db commit 192c84b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

lib/overcommit/hook/pre_commit/yaml_lint.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ def run
1010

1111
if result.success?
1212
:pass
13+
elsif result.stdout.include?('error')
14+
[:fail, result.stdout]
1315
else
14-
return [:warn, result.stdout]
16+
[:warn, result.stdout]
1517
end
1618
end
1719
end

spec/overcommit/hook/pre_commit/yaml_lint_spec.rb

+14-1
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,22 @@
3434
)
3535
end
3636

37-
it { should warn }
37+
it { should fail_hook }
3838
end
3939

40+
context 'and has 1 error and 1 warning' do
41+
let(:result) do
42+
double(
43+
success?: false,
44+
stdout: <<-MSG
45+
file1.yaml:3:81: [error] line too long (253 > 80 characters) (line-length)
46+
file2.yml:41:81: [warning] missing document start "---" (document-start)
47+
MSG
48+
)
49+
end
50+
51+
it { should fail_hook }
52+
end
4053
context 'and has single suggestion for missing file header' do
4154
let(:result) do
4255
double(

0 commit comments

Comments
 (0)