-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlint.sh
More file actions
executable file
·212 lines (188 loc) · 6.21 KB
/
Copy pathlint.sh
File metadata and controls
executable file
·212 lines (188 loc) · 6.21 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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/usr/bin/env bash
# Copyright 2021-present Kensho Technologies, LLC.
# Treat undefined variables and non-zero exits in pipes as errors.
set -uo pipefail
# Ensure that the "**" glob operator is applied recursively.
# Make globs that do not match return null values.
shopt -s globstar nullglob
# Break on first error.
set -e
# Parse input arguments.
any_run_only_set=0
run_copyright_check=0
run_ruff_check=0
run_ruff_format=0
run_cargo_fmt=0
run_mypy=0
run_cargo_clippy=0
fix=0
for i in "$@"; do
case $i in
--run-only-copyright-check )
if [ "$any_run_only_set" -eq 1 ]; then
echo "Multiple run-only options set, this is not supported.";
exit 1;
fi
any_run_only_set=1
run_copyright_check=1
shift;;
--run-only-ruff-check )
if [ "$any_run_only_set" -eq 1 ]; then
echo "Multiple run-only options set, this is not supported.";
exit 1;
fi
any_run_only_set=1
run_ruff_check=1
shift;;
--run-only-ruff-format )
if [ "$any_run_only_set" -eq 1 ]; then
echo "Multiple run-only options set, this is not supported.";
exit 1;
fi
any_run_only_set=1
run_ruff_format=1
shift;;
--run-only-cargo-fmt )
if [ "$any_run_only_set" -eq 1 ]; then
echo "Multiple run-only options set, this is not supported.";
exit 1;
fi
any_run_only_set=1
run_cargo_fmt=1
shift;;
--run-only-mypy )
if [ "$any_run_only_set" -eq 1 ]; then
echo "Multiple run-only options set, this is not supported.";
exit 1;
fi
any_run_only_set=1
run_mypy=1
shift;;
--run-only-cargo-clippy )
if [ "$any_run_only_set" -eq 1 ]; then
echo "Multiple run-only options set, this is not supported.";
exit 1;
fi
any_run_only_set=1
run_cargo_clippy=1
shift;;
--fix )
fix=1
echo "running in FIX mode"
shift;;
*)
echo "Unknown option: $i";
exit 1;;
esac
done
if [ "$any_run_only_set" -eq 0 ]; then
run_copyright_check=1
run_ruff_check=1
run_ruff_format=1
run_cargo_fmt=1
run_mypy=1
run_cargo_clippy=1
fi
# Make sure the current working directory for this script is the root directory.
cd "$(git -C "$(dirname "${0}")" rev-parse --show-toplevel )"
# Continue on error to allow ignoring certain linters.
# Errors are manually aggregated at the end.
set +e
if [ "$run_copyright_check" -eq 1 ]; then
echo -e '*** Running copyright line check... ***\n'
./scripts/copyright_line_check.sh
copyright_line_check_exit_code=$?
echo -e "\n*** End of copyright line check run; exit: $copyright_line_check_exit_code ***\n"
fi
if [ "$run_ruff_check" -eq 1 ]; then
echo -e '*** Running ruff check... ***\n'
if [ "$fix" -eq 1 ]; then
ruff check --fix .
ruff_check_exit_code=$?
else
ruff check .
ruff_check_exit_code=$?
fi
echo -e "\n*** End of ruff check run; exit: $ruff_check_exit_code ***\n"
fi
if [ "$run_ruff_format" -eq 1 ]; then
echo -e '*** Running ruff format... ***\n'
if [ "$fix" -eq 1 ]; then
ruff format .
ruff_format_exit_code=$?
else
ruff format --check --diff .
ruff_format_exit_code=$?
fi
echo -e "\n*** End of ruff format run; exit: $ruff_format_exit_code ***\n"
fi
if [ "$run_cargo_fmt" -eq 1 ]; then
echo -e '\n*** Running cargo fmt...\n'
if [ "$fix" -eq 1 ]; then
cargo fmt -v --all --manifest-path=./rust/Cargo.toml
cargo_fmt_exit_code=$?
else
cargo fmt -v --all --manifest-path=./rust/Cargo.toml --check
cargo_fmt_exit_code=$?
fi
echo -e "\n*** End of cargo fmt run, exit: $cargo_fmt_exit_code ***\n"
fi
if [ "$run_mypy" -eq 1 ]; then
echo -e '*** Running mypy... ***\n'
mypy .
mypy_exit_code=$?
echo -e "\n*** End of mypy run, exit: $mypy_exit_code ***\n"
fi
if [ "$run_cargo_clippy" -eq 1 ]; then
# Warn about pedantic stuff; deny all other defaults
echo -e '\n*** Running cargo clippy...\n'
cargo_clippy_flags="--manifest-path=./rust/Cargo.toml --release -- -W clippy::pedantic -D clippy::all"
cargo_clippy_exit_code=0
if [ "$fix" -eq 1 ]; then
cargo clippy --fix --allow-dirty --allow-staged $cargo_clippy_flags
cargo_clippy_exit_code=$?
fi
if [ "$cargo_clippy_exit_code" -eq 0 ]; then
# Even if running in fix mode and the fixes "worked", may still report errors upon check
cargo clippy --no-deps $cargo_clippy_flags
cargo_clippy_exit_code=$?
fi
echo -e "\n*** End of cargo clippy run, exit: $cargo_clippy_exit_code ***\n"
fi
if [[
(
("$run_copyright_check" == 1) && ("$copyright_line_check_exit_code" != "0")
) || (
("$run_ruff_check" == 1) && ("$ruff_check_exit_code" != "0")
) || (
("$run_ruff_format" == 1) && ("$ruff_format_exit_code" != "0")
) || (
("$run_cargo_fmt" == 1) && ("$cargo_fmt_exit_code" != "0")
) || (
("$run_mypy" == 1) && ("$mypy_exit_code" != "0")
) || (
("$run_cargo_clippy" == 1) && ("$cargo_clippy_exit_code" != "0")
)
]]; then
echo -e "\n*** Lint failed. ***\n"
if [ "$run_copyright_check" -eq 1 ]; then
echo -e "copyright line check exit: $copyright_line_check_exit_code"
fi
if [ "$run_ruff_check" -eq 1 ]; then
echo -e "ruff check exit: $ruff_check_exit_code"
fi
if [ "$run_ruff_format" -eq 1 ]; then
echo -e "ruff format exit: $ruff_format_exit_code"
fi
if [ "$run_cargo_fmt" -eq 1 ]; then
echo -e "cargo fmt exit: $cargo_fmt_exit_code"
fi
if [ "$run_mypy" -eq 1 ]; then
echo -e "mypy exit: $mypy_exit_code"
fi
if [ "$run_cargo_clippy" -eq 1 ]; then
echo -e "cargo clippy exit: $cargo_clippy_exit_code"
fi
exit 1
fi
echo -e "\n*** Lint successful. ***\n"