-
Notifications
You must be signed in to change notification settings - Fork 3
/
clean_files_go_js_vue.py
executable file
·67 lines (40 loc) · 1.34 KB
/
clean_files_go_js_vue.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env python3
# SPDX-FileCopyrightText: 2021 Lightmeter <[email protected]>
#
# SPDX-License-Identifier: AGPL-3.0-only
# -*- coding:utf-8 -*-
"""
To add this script as a pre-commit git hook, simply run:
chmod +x clean_files_go_js_vue.py
pushd .git/hooks/
ln -s ../../clean_files_go_js_vue.py pre-commit
popd
"""
import subprocess, re, os, sys
git_output = subprocess.run(['git','status','--porcelain'], capture_output=True, text=True)
files = filter(lambda f: f!='', re.split('\n', str(git_output.stdout)))
files = map(lambda f: re.sub('^..\s', '', f), files)
files = set(files)
retval = 0
def run_and_check(cmd):
print("\n",cmd)
res = subprocess.run(cmd)
if res.returncode != 0:
print("[ERROR] Command exited with return code",res.returncode)
return res.returncode
print("\n##### vue/js files #####")
os.chdir('frontend/controlcenter/')
for f in files:
if re.match('^frontend/controlcenter/.*\.(vue|js)$', f) == None:
continue
f = re.sub('^frontend/controlcenter/', './', f)
retval += run_and_check(["./node_modules/.bin/eslint","--fix",f])
os.chdir('../../')
print("\n##### go files #####")
for f in files:
if re.match('^.*\.go$', f) == None:
continue
retval += run_and_check(["gofmt","-l","-w","-s",f])
retval += run_and_check(["golangci-lint","run",f])
print("\n##### end checks #####\n\n")
sys.exit(retval)