-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Advice for how to use treefmt
as a pre-commit hook
#164
Comments
Related to #78 |
https://github.com/cachix/pre-commit-hooks.nix Using https://github.com/cachix/pre-commit-hooks.nix#nix-flakes-support as a basis, just do: checks = {
pre-commit-check = pre-commit-hooks.lib."${system}".run {
src = ./.;
hooks = {
treefmt = {
name = "treefmt";
enable = true;
description = "One CLI to format the code tree.";
types = [ "file" ];
pass_filenames = true;
entry = "${pkgs.treefmt}/bin/treefmt";
};
};
};
}; I guess this could be added trivially, to the existing set of modules, almost verbatim: With this I would consider this issue resolved, works well for our use-case. |
I'm using https://github.com/cachix/pre-commit-hooks.nix, but I had to make one change to the above. formatters = [
pkgs.alejandra
pkgs.rustfmt
];
# wrap treefmt to provide the correct PATH with all formatters
treefmt = pkgs.stdenv.mkDerivation {
name = "treefmt";
buildInputs = [pkgs.makeWrapper];
buildCommand = ''
makeWrapper \
${pkgs.treefmt}/bin/treefmt \
$out/bin/treefmt \
--prefix PATH : ${lib.makeBinPath formatters}
'';
}; Using this edit: Even better, after writing this comment I looked in to it and they already have |
Related to #311 |
Is your feature request related to a problem? Please describe.
treefmt
looks like a great choice for a pre-commit hook. I'd like to know the options to do this.Describe the solution you'd like
A wiki entry/example pre-commit hook script.
Describe alternatives you've considered
A bit of Googling how to write pre-commit hooks in general.
The text was updated successfully, but these errors were encountered: