Created
September 5, 2015 05:17
-
-
Save ianaya89/a426606784388504c724 to your computer and use it in GitHub Desktop.
Git pre-commit hook for JS Lint
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 python | |
import os, sys | |
""" | |
Checks your git commit with JSHint. Only checks staged files | |
""" | |
def jshint(): | |
errors = [] | |
# get all staged files | |
f = os.popen('git diff --cached --name-only --diff-filter=ACM') | |
for file in f.read().splitlines(): | |
# makes sure we're dealing javascript files | |
if file.endswith('.js') and not file.startswith('node_modules/'): | |
g = os.popen('jshint ' + file) | |
# add all errors from all files together | |
for error in g.readlines(): | |
errors.append(error) | |
# got errors? | |
if errors: | |
for i, error in enumerate(errors): | |
print error, | |
# Abort the commit | |
sys.exit(1) | |
# All good | |
sys.exit(0) | |
if __name__ == '__main__': | |
jshint() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment