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;};
|
settings.rust.check.cargoDeps = pkgs.rustPlatform.importCargoLock {lockFile = ./Cargo.lock;};
|
||||||
hooks = {
|
hooks = {
|
||||||
alejandra.enable = true;
|
alejandra.enable = true;
|
||||||
rustfmt.enable = true;
|
rustfmt = {
|
||||||
|
enable = true;
|
||||||
|
fail_fast = true;
|
||||||
|
packageOverrides.rustfmt = rustup.toolchain;
|
||||||
|
};
|
||||||
cargo-check = {
|
cargo-check = {
|
||||||
enable = true;
|
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 = {
|
clippy = {
|
||||||
enable = true;
|
enable = true;
|
||||||
stages = ["pre-push"];
|
name = "cargo clippy";
|
||||||
settings.denyWarnings = true;
|
stages = ["pre-push"]; # Only pre-push, because it takes a while.
|
||||||
packageOverrides.cargo = rustup.toolchain;
|
settings = {
|
||||||
packageOverrides.clippy = rustup.toolchain;
|
allFeatures = true;
|
||||||
|
denyWarnings = true;
|
||||||
|
};
|
||||||
|
packageOverrides = {
|
||||||
|
cargo = rustup.toolchain;
|
||||||
|
clippy = rustup.toolchain;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
shellcheck.enable = true;
|
shellcheck.enable = true;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue