Skip to content

Fail on yaml lint errors #738

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

Merged
merged 6 commits into from
Mar 2, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix if/else syntax to use elsif
  • Loading branch information
Gui13 authored Feb 16, 2021
commit 5accf2f00cb709c83fc570e1b8029fc49a83440e
10 changes: 4 additions & 6 deletions lib/overcommit/hook/pre_commit/yaml_lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@ def run
result = execute(command, args: applicable_files)

if result.success?
:pass
:pass
elsif result.stdout.include?("error")
[:fail, result.stdout]
else
if result.stdout.include? "error"
return [:fail, result.stdout]
else
return [:warn, result.stdout]
end
[:warn, result.stdout]
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.

end
end
Expand Down