-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path.pre-commit.sh
More file actions
executable file
·40 lines (32 loc) · 1.17 KB
/
Copy path.pre-commit.sh
File metadata and controls
executable file
·40 lines (32 loc) · 1.17 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
#!/usr/bin/env sh
set -eu
# Linking the script as the pre-commit hook
SCRIPT_PATH=$(realpath "$0")
HOOK_PATH=$(git rev-parse --git-dir)/hooks/pre-commit
if [ "$(realpath "$HOOK_PATH")" != "$SCRIPT_PATH" ]; then
printf "Link this script as the git pre-commit hook to avoid further manual running? (y/N): "
read -r link_hook
case "$link_hook" in
[Yy])
ln -sf "$SCRIPT_PATH" "$HOOK_PATH"
;;
esac
fi
set -x
# Install tools
cargo clippy --version >/dev/null 2>&1 || rustup component add clippy
cargo machete --version >/dev/null 2>&1 || cargo install --locked cargo-machete
cargo sort --version >/dev/null 2>&1 || cargo install --locked cargo-sort
typos --version >/dev/null 2>&1 || cargo install --locked typos-cli
rustup toolchain list | grep -q 'nightly' || rustup toolchain install nightly
cargo +nightly fmt --version >/dev/null 2>&1 || rustup component add rustfmt --toolchain nightly
# Checks
typos .
cargo machete
cargo +nightly fmt -- --check
cargo sort -c
cargo clippy --all-targets --all-features -- -D warnings
cargo rustdoc --all-features -- -D warnings
cargo test --doc
cargo test --all-targets
cargo test --all-targets --features forwarded-header