Help settingup pre-commit-checks and format

Hey, so i started setting up pre-commit-checks recently using git-hooks a particular hook i implemented is mdformat and i wish i could try formatting before checking, and thats where im a bit confused.

I found about a formatter config that git-hooks sets to run the checks and i wonder if i should modify to format the md files as well.

How should i implement this starting from the template here: GitHub - cachix/git-hooks.nix: Seamless integration of https://pre-commit.com git hooks with Nix.

Unless I’m misunderstanding, it’s right on the linked page:

Run all hooks sandboxed:

nix flake check

Keep in mind that nix flake check runs in a sandbox. It doesn’t have access to the internet and cannot modify files. This makes it a poor choice for formatting hooks that attempt to fix files automatically, or hooks that cannot easily be packaged to avoid impure access to the internet.

A better alternative in such cases is to run pre-commit through nix develop:

nix develop -c pre-commit run -a

Or configure a formatter like in the example above and use nix fmt:

nix fmt
1 Like

I also had just figured out that. on checking the flake they provided they just run the same checks, so i assumed that no formatting was actually done, turns out they do change the args and end up formatting the files.

I wish the description page was more clear.
oh and thanks!

1 Like