mlabs-haskell / mlabs-tooling.nix

A flake that provides everything necessary to set up a project within our sopes. This includes the necessary maintenance as well as CI.
MIT License
7 stars 7 forks source link

Pre commit hooks #16

Open aciceri opened 1 year ago

aciceri commented 1 year ago

Several people working on different projects asked for help to have pre-commit hooks in their projects, in my opinion it would make sense centralize this here.

pre-commit-hooks.nix seems to be the de facto standard for this but I agree with @L-as that it would be bloated for our purposes (we already have our linter/formatter derivations and we don't want to fetch a different ghc only to build the formatter executable).

I see two possible solutions:

By the way I would make this optional.

cc @bladyjoker @maciej-bendkowski @brainrake

bladyjoker commented 1 year ago

Hey @aciceri good stuff!

Check out https://github.com/mlabs-haskell/protobufs.nix/blob/main/src/pre-commit-hooks.nix for how to add a new hook, and https://github.com/mlabs-haskell/protobufs.nix/blob/main/pre-commit-check.nix#L16 on how to provide your own 'tools' (primarily fourmolu, but perhaps works with ghc as well).

Note that each repo comes with their own needs

  hooks = {
    nixpkgs-fmt.enable = true;
    nix-linter.enable = true;
    cabal-fmt.enable = true;
    fourmolu.enable = true;
    shellcheck.enable = true;
    hlint.enable = true;
    typos.enable = true;
    markdownlint.enable = true;
  } // protoHooks;

For the most part, mlabs-tooling can assume some common checks (nix, cabal, haskell), but we should have the ability to configure (remove and add hooks) as desired.

Additionally, most of these code quality tools have their own configuration files, would be nice to have those in a reusable but also configurable mode. Example config files: https://github.com/mlabs-haskell/protobufs.nix/blob/main/.markdownlint.yaml and https://github.com/mlabs-haskell/protobufs.nix/blob/main/_typos.toml

Hope that helps.

aciceri commented 1 year ago

@bladyjoker Thank you! We'll definitely check these links when we'll work on this (don't know how soon).

L-as commented 1 year ago

We should just allow overriding the script added to the pre-commit hook.