Skip to content
This repository has been archived by the owner on Mar 21, 2018. It is now read-only.

Commit

Permalink
feat(flog): Add flog pre-commit hook
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelastic committed Jul 17, 2015
1 parent a87d9ac commit acf01fc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
30 changes: 30 additions & 0 deletions scripts/check_flog
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env ruby

MAX_SCORE=45

flog_lines = `flog ./lib/`.split("\n")

errors = []
flog_lines.each_with_index do |line, index|
# Skip header
next if index < 3

pattern = /^ *(.*): (.*) (.*):[0-9]*/
matches = line.match(pattern)
score = matches[1].to_f

next if score < MAX_SCORE
errors << {
score: score,
method: matches[2],
file: matches[3]
}
end

exit 0 if errors.size == 0

puts 'Flog test failed:'
errors.sort_by { |a| a[:score] }.each do |error|
puts "#{error[:score]} / #{MAX_SCORE}: #{error[:method]} in #{error[:file]}"
end
exit 1
5 changes: 4 additions & 1 deletion scripts/git_hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ if grep --color -r 'spec' -E -e '^( |\t)*(fit|fdescribe|xit|xdescribe)'; then
fi

# Match style guide
rubocop './lib/' './spec'
rubocop -F './lib/' './spec' || exit 1

# No over-complex methods
./scripts/check_flog

0 comments on commit acf01fc

Please sign in to comment.