Skip to content

Instantly share code, notes, and snippets.

@mdeiters
Forked from fhwang/gist:1120210
Created August 2, 2011 14:40
Show Gist options
  • Save mdeiters/1120324 to your computer and use it in GitHub Desktop.
Save mdeiters/1120324 to your computer and use it in GitHub Desktop.
Git pre-commit hook for JSHint and Rails
#!/usr/bin/env ruby
# To use this:
# * Set up the jshint Gem with your Rails app: https://github.com/liquid/jshint_on_rails
# * Copy this file to [YOURPROJECT]/.git/hooks/pre-commit
# * chmod 0755 .git/hooks/pre-commit
files_changed = `git diff --name-only HEAD`
if files_changed.any? { |line| line =~ %r|public/javascripts| }
puts "Running jshint to check changes to javascript ..."
result = `bundle exec rake jshint`
if result =~ /Found \d+ error/
puts "=========================================================================================="
puts " COMMIT ABORTED"
puts "=========================================================================================="
puts result
exit 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment