Skip to content

Commit c4e205b

Browse files
committed
Rework lint script
- Now building cache with bb deps as well. This caught some unresolved vars from aviso. They are generated so, I had to add a linter exclusion, but cool! - The building of the clj-kondo cache is now separated from running to report for lint violations. This: 1. Simplfies the lint script 2. Does away with a specialized ci lint config 3. Is amenable to finding and importing exported clj-kondo configs from other projects
1 parent 559c7ec commit c4e205b

File tree

4 files changed

+54
-26
lines changed

4 files changed

+54
-26
lines changed

.clj-kondo/ci-config.edn

Lines changed: 0 additions & 1 deletion
This file was deleted.

.clj-kondo/config.edn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
rewrite-clj.custom-zipper.switchable/defn-switchable clojure.core/defn}
1414
:linters
1515
{:unsorted-required-namespaces {:level :warning}
16+
:unresolved-var {:exclude [io.aviso.ansi]}
1617
:unused-namespace
1718
{:exclude [clojure.test.check]}
1819
:unused-referred-var

doc/02-developer-guide.adoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,11 @@ The CI server runs:
264264
----
265265
bb ./script/lint.clj
266266
----
267-
and you can too.
267+
and you can too. The lint script will build the clj-kondo cache when it is missing.
268+
If you want to force a rebuild of the cache run:
269+
----
270+
bb ./script/lint.clj --rebuild-cache
271+
----
268272

269273
https://github.com/borkdude/clj-kondo/blob/master/doc/editor-integration.md[Integrate clj-kondo into your editor] to catch mistakes as they happen.
270274

script/lint.clj

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,60 @@
11
#!/usr/bin/env bb
22

33
(ns lint
4-
(:require [clojure.java.io :as io]
4+
(:require [babashka.classpath :as bbcp]
5+
[babashka.fs :as fs]
56
[clojure.string :as string]
7+
[docopt.core :as docopt]
8+
[docopt.match :as docopt-match]
69
[helper.env :as env]
710
[helper.shell :as shell]
811
[lread.status-line :as status]))
912

10-
(defn cache-exists? []
11-
(.exists (io/file ".clj-kondo/.cache")))
13+
(defn- cache-exists? []
14+
(fs/exists? ".clj-kondo/.cache"))
1215

13-
(defn -main[]
16+
(defn- delete-cache []
17+
(when (cache-exists?)
18+
(fs/delete-tree ".clj-kondo/.cache")))
19+
20+
(defn- build-cache []
21+
(status/line :head "clj-kondo: building cache")
22+
(let [clj-cp (-> (shell/command ["clojure" "-A:test" "-Spath"] {:out :string}) :out string/trim)
23+
bb-cp (bbcp/get-classpath)]
24+
(shell/command ["clojure" "-M:clj-kondo"
25+
"--dependencies" "--copy-configs"
26+
"--lint" clj-cp bb-cp])))
27+
28+
(defn- lint []
29+
(when (not (cache-exists?))
30+
(build-cache))
31+
(status/line :head "clj-kondo: linting")
32+
(let [{:keys [exit]}
33+
(shell/command-no-exit ["clojure" "-M:clj-kondo"
34+
"--lint" "src" "test" "script" "deps.edn"])]
35+
(if (not (some #{exit} '(0 2 3)))
36+
(status/die exit "clj-kondo existed with unexpected exit code: %d" exit)
37+
(System/exit exit))))
38+
39+
(def docopt-usage "Usage: lint.clj [options]
40+
41+
Options:
42+
--help Show this screen.
43+
--rebuild-cache Force rebuild of lint cache.")
44+
45+
(defn -main [& args]
1446
(env/assert-min-versions)
15-
(if (not (cache-exists?))
16-
(status/line :head "linting and building cache")
17-
(status/line :head "linting"))
18-
19-
(let [lint-args (if (not (cache-exists?))
20-
[(-> (shell/command ["clojure" "-A:test-common:script" "-Spath"] {:out :string})
21-
:out
22-
string/trim)
23-
"deps.edn"]
24-
["src" "test" "script" "deps.edn"])
25-
{:keys [:exit]} (shell/command-no-exit
26-
(concat ["clojure" "-M:clj-kondo"
27-
"--lint"]
28-
lint-args
29-
["--config" ".clj-kondo/ci-config.edn"]))]
30-
(when (not (some #{exit} '(0 2 3)))
31-
(status/die exit
32-
"clj-kondo existed with unexpected exit code: %d" exit))
33-
(System/exit exit)))
47+
(if-let [opts (-> docopt-usage docopt/parse (docopt-match/match-argv args))]
48+
(cond
49+
(get opts "--help")
50+
(println docopt-usage)
51+
52+
(get opts "--rebuild-cache")
53+
(do (delete-cache) (lint))
54+
55+
:else
56+
(lint))
57+
(status/die 1 docopt-usage)))
3458

3559
(env/when-invoked-as-script
36-
(-main))
60+
(apply -main *command-line-args*))

0 commit comments

Comments
 (0)