-
Notifications
You must be signed in to change notification settings - Fork 258
/
lint.sh
executable file
·78 lines (68 loc) · 1.77 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
#!/bin/bash
# Configuration for file types to be tested via prettier
FILE_TYPES="{graphql,yml,json,md,ts,js}"
run_cargo_fmt() {
MODE=$1
if [ "$MODE" == "check" ]; then
cargo fmt --all -- --check
else
cargo fmt --all
fi
return $?
}
run_cargo_clippy() {
MODE=$1
CMD="cargo clippy --all --all-targets --all-features"
if [ "$MODE" == "fix" ]; then
$CMD --fix --allow-staged --allow-dirty
fi
CMD="$CMD -- -D warnings"
$CMD
return $?
}
run_prettier() {
MODE=$1
if [ "$MODE" == "check" ]; then
npx prettier -c .prettierrc --check "**/*.$FILE_TYPES"
else
npx prettier -c .prettierrc --write "**/*.$FILE_TYPES"
fi
return $?
}
run_autogen_schema() {
MODE=$1
cargo run -p tailcall-typedefs $MODE
return $?
}
# Extract the mode from the argument
if [[ $1 == "--mode="* ]]; then
MODE=${1#--mode=}
else
echo "Please specify a mode with --mode=check or --mode=fix"
exit 1
fi
# Run commands based on mode
case $MODE in
check|fix)
run_autogen_schema $MODE
AUTOGEN_SCHEMA_EXIT_CODE=$?
run_prettier $MODE
PRETTIER_EXIT_CODE=$?
# Commands that uses nightly toolchains are run from `.nightly` directory
# to read the nightly version from `rust-toolchain.toml` file
pushd .nightly
run_cargo_fmt $MODE
FMT_EXIT_CODE=$?
run_cargo_clippy $MODE
CLIPPY_EXIT_CODE=$?
popd
;;
*)
echo "Invalid mode. Please use --mode=check or --mode=fix"
exit 1
;;
esac
# If any command failed, exit with a non-zero status code
if [ $FMT_EXIT_CODE -ne 0 ] || [ $CLIPPY_EXIT_CODE -ne 0 ] || [ $PRETTIER_EXIT_CODE -ne 0 ] || [ $AUTOGEN_SCHEMA_EXIT_CODE -ne 0 ]; then
exit 1
fi