-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlint.sh
More file actions
executable file
·78 lines (64 loc) · 1.66 KB
/
lint.sh
File metadata and controls
executable file
·78 lines (64 loc) · 1.66 KB
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
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
USAGE="Run static code checkers (but not unit tests)
This script expects to be run from the repository's root directory so the tools
can find their configuration files.
USAGE:
bash ${0} [--help]
OPTIONS:
--help, -h: Show this help and exit
EXIT VALUES:
- 0 Success
- 1 Invalid option/argument
- 2 Python syntax error
- 4 Python format error (black, isort)
- 8 Python linter error (mypy, pylint, django)
- 16 JavaScript error (eslint)
"
if [[ "${#}" = 1 ]]
then
if [[ "${1}" = "-h" || "${1}" = "--help" ]]
then
echo "${USAGE}"
exit 0
fi
echo "Invalid argument ${@}" >&2
exit 1
elif [[ "${#}" > 1 ]]
then
echo "Invalid argument ${@}" >&2
exit 1
fi
REPO="$(dirname -- "${0}")"
black --check "${REPO}"
BLACK_STATUS="${?}"
if [[ "${BLACK_STATUS}" = 123 ]]
then
# A black exit code of 123 usually indicates a synax error.
# In that event, there's no reason to keep running the other checks.
# They'll fail for the same reason.
exit 2
fi
isort --check --diff "${REPO}"
ISORT_STATUS="${?}"
mypy "${REPO}"
MYPY_STATUS="${?}"
pylint "${REPO}"
PYLINT_STATUS="${?}"
python "${REPO}/manage.py" check
DJANGO_STATUS="${?}"
npx eslint --report-unused-disable-directives "${REPO}"
ESLINT_STATUS="${?}"
EXIT_STATUS=0
if [[ "${BLACK_STATUS}" > 0 || "${ISORT_STATUS}" > 0 ]]
then
EXIT_STATUS="$(( "${EXIT_STATUS}" + 4 ))"
fi
if [[ "${MYPY_STATUS}" > 0 || "${PYLINT_STATUS}" > 0 || "${DJANGO_STATUS}" > 0 ]]
then
EXIT_STATUS="$(( "${EXIT_STATUS}" + 8 ))"
fi
if [[ "${ESLINT_STATUS}" > 0 ]]
then
EXIT_STATUS="$(( "${EXIT_STATUS}" + 16 ))"
fi
exit "${EXIT_STATUS}"