When software is worked on by more than one person, disagreements on how that software is built will arise. This is normal, but one must take care to not let unproductive disagreements dominate their time.
How code is formatted is a common source unproductive disagreements. As such, leaving that to automated tooling can be a good idea.
cljfmt
to your deps.ednWe are ultimately going to rely on our Justfile
so we are going to make a regular alias, not one with :main-opts
{:paths ["src"]
:deps {org.clojure/clojure {:mvn/version "1.12.0"}
ring/ring {:mvn/version "1.13.0"}
metosin/reitit-ring {:mvn/version "0.5.5"}
org.clojure/tools.logging {:mvn/version "1.3.0"}
org.slf4j/slf4j-simple {:mvn/version "2.0.16"}
hiccup/hiccup {:mvn/version "2.0.0-RC3"}}
:aliases {:nREPL
{:extra-paths ["dev"]
:extra-deps
{nrepl/nrepl {:mvn/version "1.2.0"}}}
:dev {:extra-paths ["dev"]}
:format {:deps {dev.weavejester/cljfmt {:mvn/version "0.13.0"}}}}}
.cljfmt.edn
This file is where you can put configuration for cljfmt
. I tend to think
that sort-ns-references?
should be on for my projects, so lets use that as the example.
{:sort-ns-references? true}
Justfile
for checking and fixing the format of your code
Checking format without fixing it is useful to make automatic checks in CI.
help:
just --list
run:
clojure -M -m example.main
nrepl:
clojure -M:nREPL -m nrepl.cmdline
format_check:
clojure -M:format -m cljfmt.main check src dev
format:
clojure -M:format -m cljfmt.main fix src dev
just format_check
You will likely see some issues unless you are a cyborg with perfect typing skills.
just format
This should fix any errors reported above and just format_check
will start to exit normally.