flake/hooks: Reconfigure Git Hooks
1. Introduce a new hook to run `cargo doc` in the "pre-commit"
phase. We have to resort to wrapping the command in a shell
script, since we cannot configure environment variables via
`.pre-commit.yaml` but need `RUSTDOCFLAGS` so that `cargo doc`
actually exists non-zero when there are warnings.
2. Move `cargo check` from the "pre-push" to the "pre-commit"
phase, as it is relatively quick, and redundant to run before
`clippy`.
3. Let `cargo check` and `cargo doc` run after `rustfmt`.
4. Let a failure of `rustfmt` fail the whole check.
5. Wire through `packageOverrides` to `rustfmt` so we use the
same toolchain as the other tools.
6. Additionally enable `cargo clippy` to consider all features.
This commit is contained in:
parent
7d2f0e387c
commit
d7aa2d9da2
40
flake.nix
40
flake.nix
|
|
@ -173,17 +173,45 @@
|
|||
settings.rust.check.cargoDeps = pkgs.rustPlatform.importCargoLock {lockFile = ./Cargo.lock;};
|
||||
hooks = {
|
||||
alejandra.enable = true;
|
||||
rustfmt.enable = true;
|
||||
rustfmt = {
|
||||
enable = true;
|
||||
fail_fast = true;
|
||||
packageOverrides.rustfmt = rustup.toolchain;
|
||||
};
|
||||
cargo-check = {
|
||||
enable = true;
|
||||
stages = ["pre-push"];
|
||||
name = "cargo check";
|
||||
after = ["rustfmt"];
|
||||
fail_fast = true;
|
||||
};
|
||||
cargo-doc = let
|
||||
# We wrap `cargo` in order to set an environment variable that
|
||||
# gives us a non-zero exit on warning.
|
||||
command =
|
||||
pkgs.writeShellScript
|
||||
"cargo"
|
||||
"RUSTDOCFLAGS='--deny warnings' ${lib.getExe' rustup.toolchain "cargo"} $@";
|
||||
in {
|
||||
enable = true;
|
||||
name = "cargo doc";
|
||||
after = ["rustfmt"];
|
||||
fail_fast = true;
|
||||
entry = "${command} doc --workspace --all-features --no-deps";
|
||||
files = "\\.rs$";
|
||||
pass_filenames = false;
|
||||
};
|
||||
clippy = {
|
||||
enable = true;
|
||||
stages = ["pre-push"];
|
||||
settings.denyWarnings = true;
|
||||
packageOverrides.cargo = rustup.toolchain;
|
||||
packageOverrides.clippy = rustup.toolchain;
|
||||
name = "cargo clippy";
|
||||
stages = ["pre-push"]; # Only pre-push, because it takes a while.
|
||||
settings = {
|
||||
allFeatures = true;
|
||||
denyWarnings = true;
|
||||
};
|
||||
packageOverrides = {
|
||||
cargo = rustup.toolchain;
|
||||
clippy = rustup.toolchain;
|
||||
};
|
||||
};
|
||||
shellcheck.enable = true;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue