Skip to content

Commit 34587a1

Browse files
committed
Add eastwood linting to bb lint task
Bb lint task is called as part of ci-unit-tests tasks so explicit call to eastwood no longer required in github action unit-test workflow. Update deveveloper guide to reflect changes in linting.
1 parent 6abfe17 commit 34587a1

File tree

6 files changed

+102
-62
lines changed

6 files changed

+102
-62
lines changed

.github/workflows/unit-test.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,3 @@ jobs:
147147
#
148148
- name: Run CI tests
149149
run: bb ci-unit-tests
150-
151-
# Runs after ci-unit-tests (which runs clj-kondo), for fail-fast behavior (as Eastwood is slower)
152-
- name: Lint with Eastwood
153-
run: clojure -A:test-common:eastwood
154-

bb.edn

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
:leave (let [{:keys [name]} (current-task)] (status/line :detail "\nTASK %s done." name))
1616
;; commands
1717
apply-import-vars {:task apply-import-vars/-main :doc "(check|gen-code) - export APIs statically from templates"}
18-
lint {:task lint/-main :doc "[--rebuild-cache]"}
18+
lint {:task lint/-main :doc "[--rebuild-cache] lint source code with clj-kondo and eastwood"}
19+
-lint-kondo {:task lint-kondo/-main :doc "[--rebuild-cache]"}
20+
-lint-eastwood {:task lint-eastwood/-main}
1921
test-clj {:task test-clj/-main :doc "[--clojure-version (1.9|1.10)]"}
2022
test-cljs {:task test-cljs/-main :doc "use --help for args"}
2123
test-shadow-cljs {:task test-shadow-cljs/-main}

doc/02-developer-guide.adoc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ Note that checks are only done against installed `./node_modules`, so you may wa
290290

291291
[#linting]
292292
== Linting
293-
We use https://github.com/borkdude/clj-kondo[clj-kondo] for linting rewrite-clj source code.
293+
We use https://github.com/borkdude/clj-kondo[clj-kondo] and https://github.com/jonase/eastwood[eastwood] to lint rewrite-clj source code.
294294

295295
We fail the build on any lint violations.
296296
The CI server runs:
@@ -305,6 +305,11 @@ bb lint --rebuild-cache
305305

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

308+
You can optionally:
309+
310+
* `bb -lint-kondo` to only run clj-kondo linter
311+
* `bb -lint-eastwood` to only run eastwood linter
312+
308313
== API diffs
309314
Rewrite-clj v1's primary goals include remaining compatible with rewrite-clj v0 and rewrite-cljs and avoiding breaking changes.
310315

script/lint.clj

100755100644
Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,12 @@
1-
#!/usr/bin/env bb
2-
31
(ns lint
4-
(:require [babashka.classpath :as bbcp]
5-
[babashka.fs :as fs]
6-
[clojure.string :as string]
7-
[helper.main :as main]
8-
[helper.shell :as shell]
9-
[lread.status-line :as status]))
10-
11-
(def clj-kondo-cache ".clj-kondo/.cache")
12-
13-
(defn- cache-exists? []
14-
(fs/exists? clj-kondo-cache))
15-
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:lint-cache" "-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-
(if (not (cache-exists?))
30-
(build-cache)
31-
(let [updated-dep-files (fs/modified-since clj-kondo-cache ["deps.edn" "bb.edn"])]
32-
(when (seq updated-dep-files)
33-
(status/line :detail "Found deps files newer than lint cache: %s" (mapv str updated-dep-files))
34-
(delete-cache)
35-
(build-cache))))
36-
(status/line :head "clj-kondo: linting")
37-
(let [{:keys [exit]}
38-
(shell/command-no-exit ["clojure" "-M:clj-kondo"
39-
"--lint" "src" "test" "script" "deps.edn"])]
40-
(cond
41-
(= 2 exit) (status/die exit "clj-kondo found one or more lint errors")
42-
(= 3 exit) (status/die exit "clj-kondo found one or more lint warnings")
43-
(> exit 0) (status/die exit "clj-kondo returned unexpected exit code"))))
44-
45-
(def args-usage "Valid args: [options]
46-
47-
Options:
48-
--rebuild-cache Force rebuild of lint cache.
49-
--help Show this help.")
2+
(:require [helper.main :as main]
3+
[lint-eastwood :as eastwood]
4+
[lint-kondo :as kondo]))
505

516
(defn -main [& args]
52-
(when-let [opts (main/doc-arg-opt args-usage args)]
53-
(cond
54-
(get opts "--rebuild-cache")
55-
(do (delete-cache) (lint))
56-
57-
:else
58-
(lint))))
7+
(when (main/doc-arg-opt kondo/args-usage args)
8+
(apply kondo/-main args)
9+
(eastwood/-main)))
5910

6011
(main/when-invoked-as-script
6112
(apply -main *command-line-args*))

script/lint_eastwood.clj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bb
2+
3+
(ns lint-eastwood
4+
(:require [helper.main :as main]
5+
[helper.shell :as shell]
6+
[lread.status-line :as status]))
7+
8+
(defn- lint []
9+
(status/line :head "eastwood: linting")
10+
(shell/command ["clojure" "-M:test-common:eastwood"]))
11+
12+
(defn -main [& args]
13+
(when (main/doc-arg-opt args)
14+
(lint))
15+
nil)
16+
17+
(main/when-invoked-as-script
18+
(apply -main *command-line-args*))

script/lint_kondo.clj

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env bb
2+
3+
(ns lint-kondo
4+
(:require [babashka.classpath :as bbcp]
5+
[babashka.fs :as fs]
6+
[clojure.string :as string]
7+
[helper.main :as main]
8+
[helper.shell :as shell]
9+
[lread.status-line :as status]))
10+
11+
(def clj-kondo-cache ".clj-kondo/.cache")
12+
13+
(defn- cache-exists? []
14+
(fs/exists? clj-kondo-cache))
15+
16+
(defn- delete-cache []
17+
(when (cache-exists?)
18+
(fs/delete-tree clj-kondo-cache)))
19+
20+
(defn- build-cache []
21+
(status/line :detail "Building cache")
22+
(when (cache-exists?)
23+
(delete-cache))
24+
(let [clj-cp (-> (shell/command ["clojure" "-A:test:lint-cache" "-Spath"] {:out :string}) :out string/trim)
25+
bb-cp (bbcp/get-classpath)]
26+
(shell/command ["clojure" "-M:clj-kondo"
27+
"--dependencies" "--copy-configs"
28+
"--lint" clj-cp bb-cp])))
29+
30+
(defn- check-cache [{:keys [rebuild-cache]}]
31+
(status/line :head "clj-kondo: cache check")
32+
(if-let [rebuild-reason (cond
33+
rebuild-cache
34+
"Rebuild requested"
35+
36+
(not (cache-exists?))
37+
"Cache not found"
38+
39+
:else
40+
(let [updated-dep-files (fs/modified-since clj-kondo-cache ["deps.edn" "bb.edn"])]
41+
(when (seq updated-dep-files)
42+
(format "Found deps files newer than lint cache: %s" (mapv str updated-dep-files)))))]
43+
(do (status/line :detail rebuild-reason)
44+
(build-cache))
45+
(status/line :detail "Using existing cache")))
46+
47+
(defn- lint [opts]
48+
(check-cache opts)
49+
(status/line :head "clj-kondo: linting")
50+
(let [{:keys [exit]}
51+
(shell/command-no-exit ["clojure" "-M:clj-kondo"
52+
"--lint" "src" "test" "script" "deps.edn"])]
53+
(cond
54+
(= 2 exit) (status/die exit "clj-kondo found one or more lint errors")
55+
(= 3 exit) (status/die exit "clj-kondo found one or more lint warnings")
56+
(> exit 0) (status/die exit "clj-kondo returned unexpected exit code"))))
57+
58+
(def args-usage "Valid args: [options]
59+
60+
Options:
61+
--rebuild-cache Force rebuild of clj-kondo lint cache.
62+
--help Show this help.")
63+
64+
(defn -main [& args]
65+
(when-let [opts (main/doc-arg-opt args-usage args)]
66+
(lint {:rebuild-cache (get opts "--rebuild-cache")})))
67+
68+
(main/when-invoked-as-script
69+
(apply -main *command-line-args*))

0 commit comments

Comments
 (0)