Skip to content

Commit 8a321aa

Browse files
committed
dev: rebuild lint cache on deps changes
Inspired by babashka's new-ish fs/modified-since, I now have the lint script automatically rebuild its cache when deps.edn or bb.edn are newer than the cache.
1 parent 909e502 commit 8a321aa

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

script/lint.clj

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,14 @@
1010
[helper.shell :as shell]
1111
[lread.status-line :as status]))
1212

13+
(def clj-kondo-cache ".clj-kondo/.cache")
14+
1315
(defn- cache-exists? []
14-
(fs/exists? ".clj-kondo/.cache"))
16+
(fs/exists? clj-kondo-cache))
1517

1618
(defn- delete-cache []
1719
(when (cache-exists?)
18-
(fs/delete-tree ".clj-kondo/.cache")))
20+
(fs/delete-tree clj-kondo-cache)))
1921

2022
(defn- build-cache []
2123
(status/line :head "clj-kondo: building cache")
@@ -26,8 +28,13 @@
2628
"--lint" clj-cp bb-cp])))
2729

2830
(defn- lint []
29-
(when (not (cache-exists?))
30-
(build-cache))
31+
(if (not (cache-exists?))
32+
(build-cache)
33+
(let [updated-dep-files (fs/modified-since clj-kondo-cache ["deps.edn" "bb.edn"])]
34+
(when (seq updated-dep-files)
35+
(status/line :detail "Found deps files newer than lint cache: %s" (mapv str updated-dep-files))
36+
(delete-cache)
37+
(build-cache))))
3138
(status/line :head "clj-kondo: linting")
3239
(let [{:keys [exit]}
3340
(shell/command-no-exit ["clojure" "-M:clj-kondo"

0 commit comments

Comments
 (0)