forked from hiredman/clj-http-lite
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathlint.clj
62 lines (52 loc) · 2.2 KB
/
lint.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
(ns lint
(:require [babashka.classpath :as bbcp]
[babashka.cli :as cli]
[babashka.fs :as fs]
[babashka.tasks :as t]
[clojure.string :as string]
[lread.status-line :as status]))
(def clj-kondo-cache ".clj-kondo/.cache")
(defn- cache-exists? []
(fs/exists? clj-kondo-cache))
(defn- delete-cache []
(when (cache-exists?)
(fs/delete-tree clj-kondo-cache)))
(defn- build-cache []
(when (cache-exists?)
(delete-cache))
(let [clj-cp (-> (t/clojure {:out :string}
"-Spath -M:test")
with-out-str
string/trim)
bb-cp (bbcp/get-classpath)]
(status/line :detail "- copying lib configs and creating cache")
(t/clojure "-M:clj-kondo --skip-lint --copy-configs --dependencies --lint" clj-cp bb-cp)))
(defn- check-cache [{:keys [rebuild]}]
(status/line :head "clj-kondo: cache check")
(if-let [rebuild-reason (cond
rebuild
"Rebuild requested"
(not (cache-exists?))
"Cache not found"
:else
(let [updated-dep-files (fs/modified-since clj-kondo-cache ["deps.edn" "bb.edn"])]
(when (seq updated-dep-files)
(format "Found deps files newer than lint cache: %s" (mapv str updated-dep-files)))))]
(do (status/line :detail rebuild-reason)
(build-cache))
(status/line :detail "Using existing cache")))
(defn- lint [opts]
(check-cache opts)
(status/line :head "clj-kondo: linting")
(let [{:keys [exit]}
(t/clojure {:continue true}
"-M:clj-kondo --parallel --lint src test build script deps.edn bb.edn")]
(cond
(= 2 exit) (status/die exit "clj-kondo found one or more lint errors")
(= 3 exit) (status/die exit "clj-kondo found one or more lint warnings")
(> exit 0) (status/die exit "clj-kondo returned unexpected exit code"))))
(defn -main [& args]
(when-let [opts (cli/parse-opts args)]
(lint opts)))
(when (= *file* (System/getProperty "babashka.file"))
(apply -main *command-line-args*))