fluree / server

Fluree Server - Operates Fluree in consensus, fault-tolerant, redundant
12 stars 1 forks source link

Add optional git pre-commit hooks for cljfmt & clj-kondo #32

Closed cap10morgan closed 8 months ago

cap10morgan commented 8 months ago

This uses babashka tasks to run some pre-commit checks via git hooks, but only after you opt in by running bb run git-hooks install. Currently it runs cljfmt and clj-kondo and rejects the commit if either complain. In my testing this runs in tens of milliseconds so hopefully worth the added value to each commit.

Currently it only checks files that are staged, and crucially, it checks the staged version of those files in a separate tmp dir (every example of git hooks I saw online checked the working directory version of the staged files; which are often not the same!). If we find a need to have the other un-staged files in there too, I can add that. I wasn't sure if it made a difference or not.

It is currently depending on a fork of cljfmt because it didn't have a library fn to pass in paths to recursively check. I'm going to PR that upstream and see if I can get it or something similar into an official release.

This is all towards the goal of spending less time fixing bugs that sneak onto main and wasting time cleaning up conflicts that are merely due to inconsistent code formatting. We had been doing far too much of the latter, especially.

cap10morgan commented 8 months ago

Current dependencies on/for this PR:

This stack of pull requests is managed by Graphite.