This repository has been archived by the owner on Mar 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style(hooks): Add flay pre-commit hook
- Loading branch information
1 parent
81227c0
commit dfd3a0c
Showing
2 changed files
with
34 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env ruby | ||
|
||
MAX_SCORE = 45 | ||
|
||
flay_lines = `flay -s ./lib/`.split("\n") | ||
|
||
errors = [] | ||
flay_lines.each_with_index do |line, index| | ||
# Skip header | ||
next if index < 2 | ||
|
||
pattern = /^ *(.*): (.*)/ | ||
matches = line.match(pattern) | ||
next if matches.nil? | ||
score = matches[1].to_f | ||
|
||
next if score < MAX_SCORE | ||
errors << { | ||
score: score, | ||
file: matches[2] | ||
} | ||
end | ||
|
||
exit 0 if errors.size == 0 | ||
|
||
puts 'Flay test failed:' | ||
errors.sort_by { |a| a[:score] }.each do |error| | ||
puts "#{error[:score]} / #{MAX_SCORE} in #{error[:file]}" | ||
end | ||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters