-
-
Save kysnm/e5c289b2f64712a0706a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
# filter by extension | |
def extname_filter(files, extnames = ['.rb']) | |
files.split($/).select do |path| | |
extnames.include?(File.extname(path)) | |
end | |
end | |
# grep 'binding.pry' (avoid a comment out) | |
def include_debug_code?(files) | |
extname_filter(files).any? do |path| | |
return false unless File.exist? path | |
!File.readlines(path).grep(/\A\s*(?!#\s*)binding.pry/).empty? | |
end | |
end | |
# check binding.pry | |
cached_files = `git diff --cached --name-only` | |
if include_debug_code?(cached_files) | |
puts 'ERROR: binding.pry is found.' | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment