-
-
Notifications
You must be signed in to change notification settings - Fork 339
/
lint.sh
executable file
·121 lines (106 loc) · 2.65 KB
/
lint.sh
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env bash
set -uo pipefail
# This script runs appropriate linters for all the different codebases present
# in the repository and collates their return statuses.
#
# | Language | Linter | Directory |
# |==========|========|==============|
# | Python | Flake8 | . |
# | Node.js | ESLint | mathesar_ui/ |
# Formatting sequences
bold=$(tput bold)
normal=$(tput sgr0)
red="\e[31m"
green="\e[32m"
yellow="\e[33m"
endcol="\e[0m"
indent() { sed 's/^/│ /'; } # Indents piped output with a indent guide lines
# Run switches
RUN_PYTHON="false"
CHANGED_NON_NODE_FILES=$(git diff --name-only --staged -- . :^mathesar_ui)
if [[ $CHANGED_NON_NODE_FILES != "" ]]; then
RUN_PYTHON="true"
fi
RUN_NODE="false"
CHANGED_NODE_FILES=$(git diff --name-only --staged mathesar_ui/)
if [[ $CHANGED_NODE_FILES == *"mathesar_ui/"* ]]; then
RUN_NODE="true"
fi
# Argument parsing
while getopts "p:n:" opt; do
case ${opt} in
p)
# Set whether to run or skip the linter for Python
RUN_PYTHON=${OPTARG}
;;
n)
# Set whether to run or skip the linter for Node.js
RUN_NODE=${OPTARG}
;;
[?])
printf "${bold}Bad command:${normal} You passed an invalid flag\n"
printf "${bold}Options:${normal} [-p <True|false>] [-n <True|false>]\n"
;;
esac
done
shift $((OPTIND -1))
printf "${bold}Enabled:${normal}\n"
printf " Python? ${RUN_PYTHON}\n"
printf "Node.js? ${RUN_NODE}\n"
# Lint Python
if [[ $RUN_PYTHON != 'false' ]]; then
printf "\nRunning ${bold}Flake8${normal} for Python...\n"
flake8 . | indent
PYTHON_EXIT=$?
if [[ $PYTHON_EXIT -eq 0 ]]; then
printf ${green}
else
printf ${red}
fi
printf "...done${endcol}\n"
else
PYTHON_EXIT=0 # Assume checks passed if skipped
fi
# Lint Node.js
if [[ $RUN_NODE != 'false' ]]; then
printf "\nRunning ${bold}ESLint${normal} for Node.js...\n"
cd mathesar_ui && npm run lint | indent
NODE_EXIT=$?
if [[ $NODE_EXIT -eq 0 ]]; then
printf ${green}
else
printf ${red}
fi
printf "...done${endcol}\n"
else
NODE_EXIT=0 # Assume checks passed if skipped
fi
# Show lint report
printf "\n${bold}Report:${normal}\n"
printf " Python: "
if [[ $PYTHON_EXIT -ne 0 ]]; then
printf "${red}failed"
elif [[ $RUN_PYTHON == "false" ]]; then
printf "${yellow}skipped"
else
printf "${green}passed"
fi
printf "${endcol}\n"
printf "Node.js: "
if [[ $NODE_EXIT -ne 0 ]]; then
printf "${red}failed"
elif [[ $RUN_NODE == "false" ]]; then
printf "${yellow}skipped"
else
printf "${green}passed"
fi
printf "${endcol}\n"
# Collate exit statuses
printf "\n"
if [[ $PYTHON_EXIT -eq 0 && $NODE_EXIT -eq 0 ]]; then
printf "${green}:) No lint problems!${endcol}\n"
exit 0
else
printf "${red}:'( Lint checks failed.${endcol}\n"
exit 1
fi