File tree 7 files changed +110
-5
lines changed
7 files changed +110
-5
lines changed Original file line number Diff line number Diff line change
1
+ {:lint-as {hiccup.def/defhtml clojure.core/defn}
2
+ :hooks {:analyze-call {hiccup.def/defelem hiccup.hooks/defelem}}}
Original file line number Diff line number Diff line change
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)))}))
Original file line number Diff line number Diff line change
1
+
2
+ {:hooks
3
+ {:analyze-call {org.httpkit.server/with-channel httpkit.with-channel/with-channel}}}
Original file line number Diff line number Diff line change
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})))
Original file line number Diff line number Diff line change
1
+ {:hooks
2
+ {:analyze-call
3
+ {taoensso.encore/defalias taoensso.encore/defalias
4
+ taoensso.encore/defn-cached taoensso.encore/defn-cached}}}
Original file line number Diff line number Diff line change
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))))}))
Original file line number Diff line number Diff line change 28
28
lint {:doc " Lints project using clj-kondo"
29
29
:task (apply shell " clj-kondo --lint src test" *command-line-args*)}
30
30
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
+
31
36
build:static-app {:doc " Builds a static app with default notebooks"
32
37
:task (apply clojure " -X:demo:nextjournal/clerk" *command-line-args*)}
33
38
99
104
:task (do
100
105
(println (str " Testing jar: 'clerk-" (t/version ) " .jar'" ))
101
106
(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" )))}
107
112
108
113
ci:publish {:doc " Publish task which will be run on CI"
109
114
:depends [-current-tag -current-branch]
You can’t perform that action at this time.
0 commit comments