feat: add pre-commit hook to check TODO|FIXME|FIX comment
This commit is contained in:
parent
cf005ff872
commit
2378a66114
4 changed files with 43 additions and 7 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
use flake
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,3 +1,4 @@
|
||||||
**/result
|
**/result
|
||||||
|
.direnv
|
||||||
|
|
||||||
.pre-commit-config.yaml
|
.pre-commit-config.yaml
|
||||||
|
|
|
||||||
29
flake.nix
29
flake.nix
|
|
@ -254,14 +254,29 @@
|
||||||
pkgs.writeShellScriptBin "pre-commit-run" script
|
pkgs.writeShellScriptBin "pre-commit-run" script
|
||||||
);
|
);
|
||||||
|
|
||||||
checks = forEachSystem (system: {
|
checks = forEachSystem (
|
||||||
pre-commit-check = inputs.git-hooks.lib.${system}.run {
|
system:
|
||||||
src = ./.;
|
let
|
||||||
hooks = {
|
pkgs = import nixpkgs { inherit system; };
|
||||||
nixfmt.enable = true;
|
in
|
||||||
|
{
|
||||||
|
pre-commit-check = inputs.git-hooks.lib.${system}.run {
|
||||||
|
src = ./.;
|
||||||
|
hooks = {
|
||||||
|
nixfmt.enable = true;
|
||||||
|
|
||||||
|
check-comment = {
|
||||||
|
enable = true;
|
||||||
|
name = "check comment";
|
||||||
|
entry = "${pkgs.callPackage ./githooks/check-comment.nix { }}";
|
||||||
|
files = "\\.nix$";
|
||||||
|
pass_filenames = false;
|
||||||
|
stages = [ "pre-commit" ];
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
devShells = forEachSystem (system: {
|
devShells = forEachSystem (system: {
|
||||||
default =
|
default =
|
||||||
|
|
|
||||||
19
githooks/check-comment.nix
Normal file
19
githooks/check-comment.nix
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
{ pkgs, lib }:
|
||||||
|
pkgs.writeShellScript "check-comment" ''
|
||||||
|
FILES=$("${lib.getExe pkgs.git}" diff --cached --name-only --diff-filter=ACM | grep '\.nix$' | grep -v '^githooks/check-comment.nix$')
|
||||||
|
|
||||||
|
TODO_FOUND=0
|
||||||
|
|
||||||
|
for file in $FILES; do
|
||||||
|
if grep -nHE '#\s*(TODO|FIXME|FIX):' "$file"; then
|
||||||
|
TODO_FOUND=1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ $TODO_FOUND -eq 1 ]; then
|
||||||
|
echo "Remove all the '#TODO|FIXME|FIX' before committing"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
''
|
||||||
Loading…
Add table
Add a link
Reference in a new issue