-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
style.sh
executable file
·70 lines (58 loc) · 1.78 KB
/
style.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
#!/usr/bin/env bash
# See: https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_pipefail/
set -Eeuo pipefail
readonly RED='\033[0;31m'
readonly NC='\033[0m'
BLACK_ARGS=(
"--line-length=120"
"--color"
)
CLANG_FORMAT_ARGS=(
"-style=file"
)
# Just do a dry run if the "fix" argument is not passed
if [ $# -eq 0 ] || [ "$1" != "--fix" ]; then
BLACK_ARGS+=("--diff") # Show difference
BLACK_ARGS+=("--check") # Exit with non-zero code if changes are required (for CI)
CLANG_FORMAT_ARGS+=("--dry-run")
fi
function print_update_error() {
echo -e "${RED}[Error] Please update with ./ansible.sh build.yml${NC}"
exit 1
}
function find_executable() {
local readonly executable="$1"
local readonly version="$2"
local readonly path=$(which "${executable}")
if [ ! -x "${path}" ]; then
echo -e "${RED}[Error] Could not find ${executable}${NC}"
print_update_error
fi
if ! "${path}" --version | grep -q "${version}"; then
echo -e "${RED}[Error] Wrong ${executable} version${NC}"
print_update_error
fi
echo "${path}"
}
## Check that all tools are installed
readonly CLANG_FORMAT_PATH=$(find_executable clang-format-16 16.0)
readonly BLACK_PATH=$(find_executable black 24.4.2)
readonly MYPY_PATH=$(find_executable mypy 1.10.0)
## Run checks
echo "Style checking C++ ..."
readonly FOLDERS=(
./src/perception
./src/simulator
./src/util
)
for FOLDER in "${FOLDERS[@]}"; do
find "${FOLDER}" -regex '.*\.\(cpp\|hpp\|h\)' -exec "${CLANG_FORMAT_PATH}" "${CLANG_FORMAT_ARGS[@]}" -i {} \;
done
echo "Done"
echo
echo "Style checking Python with black ..."
"$BLACK_PATH" "${BLACK_ARGS[@]}" ./src ./scripts
echo
echo "Style checking Python with mypy ..."
# TODO(quintin): Add other subteam folders and scripts folder
"$MYPY_PATH" --config-file=mypy.ini --check ./src/navigation