chore(hooks): clippy gate falls back to a nix-shell toolchain
Desktop migration: the home-manager rust here ships without the clippy component. Prefer an installed cargo-clippy; otherwise run clippy from an ephemeral nix-shell with a separate target dir (mixed-compiler artifacts are an E0514 hard error). MSRV keeps the shell's older toolchain a legitimate gate.
This commit is contained in:
@@ -2,7 +2,23 @@
|
|||||||
# smarm pre-commit gate: clippy the library (src/) with warnings as errors.
|
# smarm pre-commit gate: clippy the library (src/) with warnings as errors.
|
||||||
# unwrap_used / expect_used are denied (Cargo.toml [lints.clippy]): library
|
# unwrap_used / expect_used are denied (Cargo.toml [lints.clippy]): library
|
||||||
# code must not hide a panic behind unwrap/expect. Tests/examples are not gated.
|
# code must not hide a panic behind unwrap/expect. Tests/examples are not gated.
|
||||||
|
#
|
||||||
|
# Toolchain resolution: prefer an installed cargo-clippy; on machines whose
|
||||||
|
# rust comes without the clippy component (e.g. NixOS home-manager), fall
|
||||||
|
# back to an ephemeral nix-shell toolchain. The fallback uses its own target
|
||||||
|
# dir (target/clippy) because the shell's rustc version may differ from the
|
||||||
|
# default toolchain's — mixed-compiler artifacts in one target dir are an
|
||||||
|
# E0514 hard error. MSRV (Cargo.toml rust-version) keeps the older shell
|
||||||
|
# toolchain a legitimate gate.
|
||||||
set -eu
|
set -eu
|
||||||
[ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env"
|
[ -f "$HOME/.cargo/env" ] && . "$HOME/.cargo/env"
|
||||||
cd "$(git rev-parse --show-toplevel)"
|
cd "$(git rev-parse --show-toplevel)"
|
||||||
|
if cargo clippy --version >/dev/null 2>&1; then
|
||||||
cargo clippy --lib -- -D warnings
|
cargo clippy --lib -- -D warnings
|
||||||
|
elif command -v nix-shell >/dev/null 2>&1; then
|
||||||
|
nix-shell -p clippy -p cargo -p rustc \
|
||||||
|
--run 'CARGO_TARGET_DIR=target/clippy cargo clippy --lib -- -D warnings'
|
||||||
|
else
|
||||||
|
echo "pre-commit: cargo clippy unavailable and no nix-shell fallback" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user