git-hooks.nix icon indicating copy to clipboard operation
git-hooks.nix copied to clipboard

Add default pre-commit hooks

Open totoroot opened this issue 1 year ago • 9 comments

This PR adds almost all non-deprecated hooks from the original pre-commit-hooks repository.

Two of these hooks were asked for in https://github.com/cachix/pre-commit-hooks.nix/issues/31 by @PierreR and workarounds have been proposed, like writing custom hooks, or using the rawConfig option.

Thanks to @kalbasit, pre-commit-hooks got packaged for nixpkgs, so why not add all these default pre-commit hooks that are listed here?

I've tested them all, set some sane defaults and occasionally renamed them slightly or changed the description, so it is clearer, what the individual hooks are used for. The rest of the settings were taken from the hooks configuration in the original repository.

All the hooks seem to pass the initial checks and can be used just fine. I haven't added all the arguments for all hooks, but tried to add all that are necessary for sensible usage as a pre-commit hook.

In case someone tries to use one of these hooks and cannot find a needed option that is available in the original hook, please open an issue and feel free to assign me to it. I'll try to add it then.

~~I have yet to add all hooks to the README. Keeping this as a draft until I get around to it, which should be at the beginning of next week. Feel free to review the proposed changes in the meantime.~~

totoroot avatar Feb 22 '24 13:02 totoroot

Closure size of pre-commit-hooks is rather small:

λ du -sh $(nix-build -A python3Packages.pre-commit-hooks)
860K	/nix/store/g07vbn53mvqy5gaqa3dmw4w0lcr2i89a-python3.11-pre-commit-hooks-4.5.0

totoroot avatar Feb 23 '24 07:02 totoroot

I have now listed all added default pre-commit hooks to the corresponding sections of the README.

Since I noticed a couple of formatting issues in the README, I fixed them in 9593b40, so that it is now standard Markdown as checked by mdl and markdownlint. I also sorted all hooks alphabetically in the subsections.

Since the various hooks includes hooks other than formatters, I renamed the section's headline from Other formatters to Various other hooks.

@domenkozar Should we add mdl to the pre-commit hooks in this repository so that the README gets linted on new contributions?

totoroot avatar Feb 27 '24 10:02 totoroot

Oh thanks for all this work! We'll have to base it on top of #397 otherwise we'll get into conflicts.

domenkozar avatar Feb 27 '24 10:02 domenkozar

Oh thanks for all this work! We'll have to base it on top of #397 otherwise we'll get into conflicts.

Sure, I'll try to rebase onto that.

totoroot avatar Feb 27 '24 12:02 totoroot

@domenkozar Alright, my changes are now on top of #397.

totoroot avatar Mar 06 '24 14:03 totoroot

cc @sandydoo

domenkozar avatar Mar 07 '24 03:03 domenkozar

Some braces were missing, but now it should work fine. @sandydoo Please let me know if you need any help finishing up #196.

totoroot avatar Mar 07 '24 12:03 totoroot

Great work, @totoroot!

RE #196, there are two main blockers I'd like to solve before merging:

  1. We'd like to offer an overridable package for every hook. The problem is that a few hooks have more complex requirements: some hooks depend on several packages or have wrappers of some kind. How much do we expose here? Should we expose the wrappers to allow users to override them? Or is this an implementation detail? Should package be a single package type or some attribute set of packages? If it's a single package (or a symlink join), can we reliably access all of the packages used by the enabled hooks to create a dev shell?
  2. The deprecation notices for the renamed options don't currently show up. Maybe there's some trick to get these to propagate through the submodules.

If you have any ideas/thoughts on these, I'd love to hear them!

sandydoo avatar Mar 07 '24 13:03 sandydoo

  1. we discussed about this one quite a bit, most likely it's best to have cfg.package and allow it to be a list of packages that is then used with pkgs.symlinkJoin
  2. should be doable like so: https://github.com/NixOS/nixpkgs/pull/287506/files#diff-346cfce0bc66f4470c59870b415a1582bd5422b09d67309feb20e9e8597d2f7bR899

domenkozar avatar Mar 08 '24 17:03 domenkozar

Hey! We merged it, could you rebase on top of master now?

domenkozar avatar Mar 19 '24 03:03 domenkozar

Yesterday I messed up the large rebase a little, so many thanks to @9999years who fixed up the branch :bouquet:

@domenkozar Ready for review/merge now!

totoroot avatar Mar 28 '24 07:03 totoroot

git-annex seems to not build on macOS, maybe we should disable it...?

9999years avatar Mar 28 '24 18:03 9999years

git-annex seems to not build on macOS, maybe we should disable it...?

@9999years Surely a good idea, but that should be done in a separate PR, as this one did not change the git-annex hook.

totoroot avatar Mar 29 '24 10:03 totoroot

Wait, the CI failures are non-blocking -- CI hasn't passed on the master branch in 2 months: https://github.com/cachix/git-hooks.nix/commit/0b6fdb0941e4dc283ff0e79e2d0aea74d713f2fc

9999years avatar Mar 29 '24 17:03 9999years

Opened #421 to fix the CI failures on macOS.

9999years avatar Mar 29 '24 17:03 9999years

Could you rebase on master?

domenkozar avatar Mar 30 '24 01:03 domenkozar

Could you rebase on master?

I merged master into this branch.

totoroot avatar Mar 30 '24 09:03 totoroot