Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
flake/hooks: Reconfigure Git Hooks
Merged lorenz opened 8 months ago
  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.
1 file changed +34 -6 7d2f0e38 d7aa2d9d
modified 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;
            };