Created
January 4, 2013 23:32
-
-
Save ryan-blunden/4458479 to your computer and use it in GitHub Desktop.
Run jshint over JavaScript files currently staged.
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
#!/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