-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·38 lines (26 loc) · 841 Bytes
/
pre-commit
File metadata and controls
executable file
·38 lines (26 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/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()