Skip to content

Commit c47a06e

Browse files
committed
Add bb lint:copy-configs and add resulting configs
1 parent 03d534f commit c47a06e

File tree

7 files changed

+110
-5
lines changed

7 files changed

+110
-5
lines changed

.clj-kondo/hiccup/hiccup/config.edn

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{:lint-as {hiccup.def/defhtml clojure.core/defn}
2+
:hooks {:analyze-call {hiccup.def/defelem hiccup.hooks/defelem}}}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
(ns hiccup.hooks
2+
(:require [clj-kondo.hooks-api :as api]
3+
[clojure.set :as set]))
4+
5+
;; See https://github.com/clj-kondo/clj-kondo/blob/master/doc/hooks.md
6+
7+
(defn- parse-defn [elems]
8+
(let [[fhead fbody] (split-with #(not (or (api/vector-node? %)
9+
(api/list-node? %)))
10+
elems)
11+
arities (if (api/vector-node? (first fbody))
12+
(list (api/list-node fbody))
13+
fbody)]
14+
[fhead arities]))
15+
16+
(defn- count-args [arity]
17+
(let [args (first (api/sexpr arity))]
18+
(if (= '& (fnext (reverse args)))
19+
true ; unbounded args
20+
(count args))))
21+
22+
(defn- dummy-arity [arg-count]
23+
(api/list-node
24+
(list
25+
(api/vector-node
26+
(vec (repeat arg-count (api/token-node '_)))))))
27+
28+
(defn defelem [{:keys [node]}]
29+
(let [[_ & rest] (:children node)
30+
[fhead arities] (parse-defn rest)
31+
arg-counts (set (filter number? (map count-args arities)))
32+
dummy-arg-counts (set/difference (set (map inc arg-counts)) arg-counts)
33+
dummy-arities (for [n dummy-arg-counts] (dummy-arity n))]
34+
{:node
35+
(api/list-node
36+
(list*
37+
(api/token-node 'clojure.core/defn)
38+
(concat fhead arities dummy-arities)))}))
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
{:hooks
3+
{:analyze-call {org.httpkit.server/with-channel httpkit.with-channel/with-channel}}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(ns httpkit.with-channel
2+
(:require [clj-kondo.hooks-api :as api]))
3+
4+
(defn with-channel [{node :node}]
5+
(let [[request channel & body] (rest (:children node))]
6+
(when-not (and request channel) (throw (ex-info "No request or channel provided" {})))
7+
(when-not (api/token-node? channel) (throw (ex-info "Missing channel argument" {})))
8+
(let [new-node
9+
(api/list-node
10+
(list*
11+
(api/token-node 'let)
12+
(api/vector-node [channel (api/vector-node [])])
13+
request
14+
body))]
15+
16+
{:node new-node})))

.clj-kondo/taoensso/encore/config.edn

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{:hooks
2+
{:analyze-call
3+
{taoensso.encore/defalias taoensso.encore/defalias
4+
taoensso.encore/defn-cached taoensso.encore/defn-cached}}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
(ns taoensso.encore
2+
"I don't personally use clj-kondo, so these hooks are
3+
kindly authored and maintained by contributors.
4+
PRs very welcome! - Peter Taoussanis"
5+
(:require
6+
[clj-kondo.hooks-api :as hooks]))
7+
8+
(defn defalias
9+
[{:keys [node]}]
10+
(let [[sym-raw src-raw] (rest (:children node))
11+
src (if src-raw src-raw sym-raw)
12+
sym
13+
(if src-raw
14+
sym-raw
15+
(symbol (name (hooks/sexpr src))))]
16+
17+
{:node
18+
(with-meta
19+
(hooks/list-node
20+
[(hooks/token-node 'def)
21+
(hooks/token-node (hooks/sexpr sym))
22+
(hooks/token-node (hooks/sexpr src))])
23+
(meta src))}))
24+
25+
(defn defn-cached
26+
[{:keys [node] :as x}]
27+
(let [[sym _opts binding-vec & body] (rest (:children node))]
28+
{:node
29+
(hooks/list-node
30+
(list
31+
(hooks/token-node 'def)
32+
sym
33+
(hooks/list-node
34+
(list*
35+
(hooks/token-node 'fn)
36+
binding-vec
37+
body))))}))

bb.edn

+10-5
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
lint {:doc "Lints project using clj-kondo"
2929
:task (apply shell "clj-kondo --lint src test" *command-line-args*)}
3030

31+
lint:copy-configs {:doc "Copies clj-kondo configs from deps"
32+
:task (println "clj-kondo --lint"
33+
(-> (shell {:out :string} "clojure -Spath") :out str/trim)
34+
"--dependencies --copy-configs --skip-lint")}
35+
3136
build:static-app {:doc "Builds a static app with default notebooks"
3237
:task (apply clojure "-X:demo:nextjournal/clerk" *command-line-args*)}
3338

@@ -99,11 +104,11 @@
99104
:task (do
100105
(println (str "Testing jar: 'clerk-" (t/version) ".jar'"))
101106
(clojure (str "-Sforce -Srepro -Sdeps '"
102-
(pr-str {:aliases {:test-jar {:jvm-opts ["-Dclojure.main.report=stdout"]
103-
:deps {'io.github.nextjournal/clerk {:local/root (str "./target/clerk-" (t/version) ".jar")}}
104-
:exec-fn 'nextjournal.clerk/build!
105-
:exec-args {:paths ["notebooks/hello.clj"]}}}})
106-
"' -T:test-jar")))}
107+
(pr-str {:aliases {:test-jar {:jvm-opts ["-Dclojure.main.report=stdout"]
108+
:deps {'io.github.nextjournal/clerk {:local/root (str "./target/clerk-" (t/version) ".jar")}}
109+
:exec-fn 'nextjournal.clerk/build!
110+
:exec-args {:paths ["notebooks/hello.clj"]}}}})
111+
"' -T:test-jar")))}
107112

108113
ci:publish {:doc "Publish task which will be run on CI"
109114
:depends [-current-tag -current-branch]

0 commit comments

Comments
 (0)