forked from tailcallhq/tailcall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lint.sh
executable file
·69 lines (62 loc) · 1.73 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
#!/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 +nightly fmt -- --check
else
cargo +nightly fmt
fi
return $?
}
run_cargo_clippy() {
MODE=$1
CMD="cargo +nightly clippy --all-targets --all-features"
if [ "$MODE" == "fix" ]; then
# if mode is fix first run clippy with --fix flag as usual
$CMD --fix --allow-staged --allow-dirty
fi
# call anyway check command without --fix despite actual $MODE
# this is to show error as warnings similar to check mode
# since clippy won't fail on warnings when --fix and -D warnings are used together
# see https://github.com/rust-lang/rust-clippy/issues/11241
CMD="$CMD -- -D warnings"
$CMD
return $?
}
run_prettier() {
MODE=$1
if [ "$MODE" == "check" ]; then
prettier -c .prettierrc --check "**/*.$FILE_TYPES"
else
prettier -c .prettierrc --write "**/*.$FILE_TYPES"
fi
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_cargo_fmt $MODE
FMT_EXIT_CODE=$?
run_cargo_clippy $MODE
CLIPPY_EXIT_CODE=$?
run_prettier $MODE
PRETTIER_EXIT_CODE=$?
;;
*)
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 ]; then
exit 1
fi