Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail on yaml lint errors #738

Merged
merged 6 commits into from
Mar 2, 2021
Merged

Fail on yaml lint errors #738

merged 6 commits into from
Mar 2, 2021

Conversation

Gui13
Copy link
Contributor

@Gui13 Gui13 commented Jan 13, 2021

Fixes #737

@Gui13
Copy link
Contributor Author

Gui13 commented Jan 14, 2021

I don't really know why the build fails, it seems that it fails on all the tests.

I'm not good enough in Ruby to analyze the issue though.

Copy link
Owner

@sds sds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR, @Gui13. Can you fix the syntax error?

if result.stdout.include? "error"
return [:fail, result.stdout]
else
return [:warn, result.stdout]

This comment was marked as resolved.

This comment was marked as resolved.

@@ -34,9 +34,22 @@
)
end

it { should warn }
it { should fail }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that fail is a keyword in Ruby so this test will always error (see the failing TravisCI run).

You should use the fail_hook keyword here and below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it is done. I admit ruby is not my main language. I took inspiration from the existing code in this matter.

@Gui13
Copy link
Contributor Author

Gui13 commented Feb 14, 2021

@sds I have rebased on your current master just in case.

The three failing tests are out of my scope, so I don't know what else to do.

In any case, this is what we use right now in production: it correctly handles error messages from yamllint

return [:fail, result.stdout]
else
return [:warn, result.stdout]
end
end
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test failure is because the way this if/else is written could be simplified.

You can resolve by writing as:

if result.success?
  :pass 
elsif result.stdout.include?("error")
  [:fail, result.stdout]
else
  [:warn, result.stdout]
end

Notice this is "flatter" than what is currently written.

@sds
Copy link
Owner

sds commented Feb 18, 2021

Note that there are still CI failures that should be pretty easy to fix. Can you have a look?

lib/overcommit/hook/pre_commit/yaml_lint.rb:12:14: C: Layout/TrailingWhitespace: Trailing whitespace detected.
lib/overcommit/hook/pre_commit/yaml_lint.rb:13:36: C: Style/StringLiterals: Prefer single-quoted strings when you don't need string interpolation or special symbols.

@Gui13
Copy link
Contributor Author

Gui13 commented Feb 26, 2021

OK @sds I did it!

@sds sds merged commit 192c84b into sds:master Mar 2, 2021
@sds
Copy link
Owner

sds commented Mar 2, 2021

Thank you for your help!

@sds sds added the bug label Mar 2, 2021
@Gui13 Gui13 deleted the patch-1 branch March 8, 2021 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

YamlLint seems to issue only warnings, not errors
2 participants