hooks: Filter for "radicle.{xyz,zulipchat.com}"
This hook should make people think before committing domain names
like "radicle.xyz" and "radicle.zulipchat.com" to our Rust code.
Note that these checks can be easily skipped as follows:
SKIP=grep-radicle.xyz,grep-radicle.zulipchat.com git commit …
See also <https://pre-commit.com/#temporarily-disabling-hooks>
This commit is contained in:
parent
b301fa6a00
commit
9b7529baa7
37
flake.nix
37
flake.nix
|
|
@ -168,10 +168,36 @@
|
||||||
prefix = "msrv-";
|
prefix = "msrv-";
|
||||||
})
|
})
|
||||||
// {
|
// {
|
||||||
pre-commit-check = inputs.git-hooks.lib.${system}.run {
|
pre-commit-check = let
|
||||||
|
grep = rec {
|
||||||
|
words = ["radicle.xyz" "radicle.zulipchat.com"];
|
||||||
|
after = map id words;
|
||||||
|
prefix = "grep-";
|
||||||
|
id = word: prefix + word;
|
||||||
|
hooks = builtins.listToAttrs (map (word: {
|
||||||
|
# "," is problematic, as this is used to split
|
||||||
|
# lists of hook names, when skipping, see:
|
||||||
|
# https://pre-commit.com/#temporarily-disabling-hooks
|
||||||
|
name = assert !lib.hasInfix "," word; id word;
|
||||||
|
value = hook word;
|
||||||
|
})
|
||||||
|
words);
|
||||||
|
hook = word: {
|
||||||
|
enable = true;
|
||||||
|
entry = builtins.toString (pkgs.writeShellScript
|
||||||
|
"grep-${word}"
|
||||||
|
"! ${lib.getExe pkgs.ripgrep} --context=3 --fixed-strings '${word}' $@");
|
||||||
|
name = "Avoid '${word}' in Rust code";
|
||||||
|
files = "\\.rs$";
|
||||||
|
pass_filenames = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
in
|
||||||
|
inputs.git-hooks.lib.${system}.run {
|
||||||
src = ./.;
|
src = ./.;
|
||||||
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 = {
|
rustfmt = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
@ -181,7 +207,7 @@
|
||||||
cargo-check = {
|
cargo-check = {
|
||||||
enable = true;
|
enable = true;
|
||||||
name = "cargo check";
|
name = "cargo check";
|
||||||
after = ["rustfmt"];
|
after = ["rustfmt"] ++ grep.after;
|
||||||
fail_fast = true;
|
fail_fast = true;
|
||||||
};
|
};
|
||||||
cargo-doc = let
|
cargo-doc = let
|
||||||
|
|
@ -194,7 +220,7 @@
|
||||||
in {
|
in {
|
||||||
enable = true;
|
enable = true;
|
||||||
name = "cargo doc";
|
name = "cargo doc";
|
||||||
after = ["rustfmt"];
|
after = ["rustfmt"] ++ grep.after;
|
||||||
fail_fast = true;
|
fail_fast = true;
|
||||||
entry = "${command} doc --workspace --all-features --no-deps";
|
entry = "${command} doc --workspace --all-features --no-deps";
|
||||||
files = "\\.rs$";
|
files = "\\.rs$";
|
||||||
|
|
@ -214,7 +240,8 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
shellcheck.enable = true;
|
shellcheck.enable = true;
|
||||||
};
|
}
|
||||||
|
// grep.hooks;
|
||||||
};
|
};
|
||||||
|
|
||||||
# Build the crate as part of `nix flake check` for convenience
|
# Build the crate as part of `nix flake check` for convenience
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue