dev: Check that we use ///-style doc comments in Rust

(cherry picked from commit 395a4d7a46e8489ca98667fca3db8aebf998a9b6)
This commit is contained in:
Robert Hensing 2024-05-24 11:45:39 +02:00
parent 37da6411d0
commit 6b438e5398

View file

@ -35,6 +35,26 @@
# New configuration for rustfmt
pre-commit.settings.settings.rust.cargoManifestPath = "./rust/Cargo.toml";
# Check that we're using ///-style doc comments in Rust code.
#
# Unfortunately, rustfmt won't do this for us yet - at least not
# without nightly, and it might do too much.
pre-commit.settings.hooks.rust-doc-comments = {
enable = true;
files = ".*.rs$";
entry = "${pkgs.writeScript "rust-doc-comments" ''
#!${pkgs.runtimeShell}
set -uxo pipefail
grep -n -C3 --color=always -F '/**' "$@"
r=$?
set -e
if [ $r -eq 0 ]; then
echo "Please replace /**-style comments by /// style comments in Rust code."
exit 1
fi
''}";
};
devShells.default = pkgs.mkShell {
name = "nix-bindings-devshell";
strictDeps = true;