Skip to content

Instantly share code, notes, and snippets.

@ryan-blunden
Created January 4, 2013 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryan-blunden/4458479 to your computer and use it in GitHub Desktop.
Save ryan-blunden/4458479 to your computer and use it in GitHub Desktop.
Run jshint over JavaScript files currently staged.
#!/usr/bin/env python
import subprocess
"""
Checked staged JavaScript files for jshint errors
"""
def jshint():
errors = []
output = subprocess.check_output(['git', 'diff-index', '--name-only', '--cached', 'HEAD'])
js_files = [file for file in output.split('\n') if file[-2:] == 'js']
for js_file in js_files:
try:
subprocess.check_output('jshint %s' % js_file, shell=True)
except subprocess.CalledProcessError, e:
errors.append(e.output)
if len(errors) > 0:
print '\n\n'.join(errors)
print '### JSHint errors in %s files found ###\n\n' % len(errors)
else:
print '\nNo JSHint errors found. You\'re awesome!\n'
if __name__ == '__main__':
jshint()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment