Skip to content

Commit abf66de

Browse files
authored
dev: bump clj-kondo (#689)
Also: - bring in clj-kondo provided config for slingshot as a test dep - have clj-kondo move imports to current ./clj-kondo/imports location
1 parent 2ebeb18 commit abf66de

File tree

16 files changed

+180
-120
lines changed

16 files changed

+180
-120
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{:linters
2+
{:etaoin/with-x-action {:level :error}
3+
:etaoin/binding-sym {:level :error}
4+
:etaoin/opts-map-type {:level :error}
5+
:etaoin/opts-map-pos {:level :error}
6+
:etaoin/empty-opts {:level :warning}}
7+
:hooks
8+
{:analyze-call
9+
{etaoin.api/with-chrome etaoin.api/with-browser
10+
etaoin.api/with-chrome-headless etaoin.api/with-browser
11+
etaoin.api/with-firefox etaoin.api/with-browser
12+
etaoin.api/with-firefox-headless etaoin.api/with-browser
13+
etaoin.api/with-edge etaoin.api/with-browser
14+
etaoin.api/with-edge-headless etaoin.api/with-browser
15+
etaoin.api/with-safari etaoin.api/with-browser
16+
17+
etaoin.api/with-driver etaoin.api/with-driver
18+
etaoin.api/with-key-down etaoin.api/with-key-down
19+
etaoin.api/with-pointer-btn-down etaoin.api/with-pointer-btn-down
20+
21+
;; api2 moves to a more conventional let-ish vector syntax
22+
etaoin.api2/with-chrome etaoin.api2/with-browser
23+
etaoin.api2/with-chrome-headless etaoin.api2/with-browser
24+
etaoin.api2/with-edge etaoin.api2/with-browser
25+
etaoin.api2/with-edge-headless etaoin.api2/with-browser
26+
etaoin.api2/with-firefox etaoin.api2/with-browser
27+
etaoin.api2/with-firefox-headless etaoin.api2/with-browser
28+
etaoin.api2/with-safari etaoin.api2/with-browser}}
29+
:lint-as
30+
{etaoin.api/with-pointer-left-btn-down clojure.core/->}}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
(ns etaoin.api
2+
(:require [clj-kondo.hooks-api :as api]
3+
[etaoin.hooks-util :as h]))
4+
5+
(defn- nil-node? [n]
6+
(and (api/token-node? n) (nil? (api/sexpr n))))
7+
8+
(defn- with-bound-arg [node arg-offset]
9+
(let [macro-args (rest (:children node))
10+
leading-args (take arg-offset macro-args)
11+
interesting-args (drop arg-offset macro-args)
12+
[opts binding-sym & body] (if (h/symbol-node? (second interesting-args))
13+
interesting-args
14+
(cons nil interesting-args))]
15+
;; if the user has specified nil or {} for options we can suggest that is not necessary
16+
(when (and opts
17+
(or (and (api/map-node? opts) (not (seq (:children opts))))
18+
(nil-node? opts)))
19+
(api/reg-finding! (assoc (meta opts)
20+
:message "Empty or nil driver options can be omitted"
21+
:type :etaoin/empty-opts)))
22+
23+
(cond
24+
(not (h/symbol-node? binding-sym))
25+
;; it makes more sense here to report on the incoming node position instead of what we expect to be the binding-sym
26+
(api/reg-finding! (assoc (meta node)
27+
:message "Expected binding symbol for driver"
28+
:type :etaoin/binding-sym))
29+
30+
;; we don't want to explicitly expect a map because the map might come from
31+
;; an evalution, but we can do some checks
32+
(and opts ;; we'll assume a list-node is a function call (eval)
33+
(not (nil-node? opts)) ;; nil is actually old-v1 syntax acceptable
34+
(not (api/list-node? opts)) ;; some fn call
35+
(not (h/symbol-node? opts)) ;; from a binding maybe
36+
;; there are other eval node types... @(something) for example... maybe we'll add them in if folks ask
37+
(not (api/map-node? opts)))
38+
;; we can report directly on the opts node, because at this point we know we expect
39+
;; this arg position to be an opts map
40+
(api/reg-finding! (assoc (meta opts)
41+
:message "When specified, opts should be a map"
42+
:type :etaoin/opts-map-type))
43+
44+
;; one last nicety, if the first form in body is a map, the user has accidentally swapped
45+
;; binding and opt args
46+
(api/map-node? (first body))
47+
(api/reg-finding! (assoc (meta (first body))
48+
:message "When specified, opts must appear before binding symbol"
49+
:type :etaoin/opts-map-pos))
50+
51+
:else
52+
{:node (api/list-node
53+
(list*
54+
(api/token-node 'let)
55+
;; simulate the effect, macro is creating a new thing (driver for example)
56+
;; via binding it. I don't think the bound value matters for the linting process
57+
(api/vector-node [binding-sym (api/map-node [])])
58+
;; reference the other args so that they are not linted as unused
59+
(api/vector-node leading-args)
60+
opts ;; might be a binding, so ref it too
61+
body))})))
62+
63+
(defn- with-x-down
64+
"This is somewhat of a maybe an odd duck.
65+
I think it is assumed to be used within a threading macro.
66+
And itself employs a threadfirst macro.
67+
So each body form need to have an action (dummy or not) threaded into it."
68+
[node]
69+
(let [macro-args (rest (:children node))
70+
[input x & body] macro-args
71+
dummy-action (api/map-node [])]
72+
{:node (api/list-node
73+
(apply list*
74+
(api/token-node 'do)
75+
;; reference x and input just in case they contain something lint-relevant
76+
x input
77+
;; dump the body, threading a dummy action in as first arg
78+
(map (fn [body-form]
79+
(cond
80+
;; not certain this is absolutely what we want, but maybe close enough
81+
(h/symbol-node? body-form) (api/list-node (list* body-form dummy-action))
82+
(api/list-node? body-form) (let [children (:children body-form)]
83+
(assoc body-form :children (apply list*
84+
(first children)
85+
dummy-action
86+
(rest children))))
87+
:else
88+
(api/reg-finding! (assoc (meta body-form)
89+
:message "expected to be threaded through an action"
90+
:type :etaoin/with-x-action))))
91+
body)))}))
92+
93+
(defn with-browser
94+
"Covers etaoin.api/with-chrome and all its variants
95+
[opt? bind & body]"
96+
[{:keys [node]}]
97+
(with-bound-arg node 0))
98+
99+
(defn with-driver
100+
"Very similar to with-browser but bound arg is 1 deeper
101+
[type opt? bind & body]"
102+
[{:keys [node]}]
103+
(with-bound-arg node 1))
104+
105+
(defn with-key-down
106+
"[input key & body]"
107+
[{:keys [node]}]
108+
(with-x-down node))
109+
110+
(defn with-pointer-btn-down
111+
"[input button & body]"
112+
[{:keys [node]}]
113+
(with-x-down node))
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
(ns etaoin.api2
2+
(:require [clj-kondo.hooks-api :as api]
3+
[etaoin.hooks-util :as h]))
4+
5+
(defn with-browser
6+
"Newer variants for api2
7+
[[bind & [options]] & body]"
8+
[{:keys [node]}]
9+
(let [macro-args (rest (:children node))
10+
binding-like-vector (first macro-args)]
11+
(if-not (api/vector-node? binding-like-vector)
12+
;; could use clj-kondo findings, but I think this is good for now
13+
(throw (ex-info "Expected vector for first arg" {}))
14+
(let [binding-sym (-> binding-like-vector :children first)]
15+
(if-not (h/symbol-node? binding-sym)
16+
(throw (ex-info "Expected binding symbol for first arg in vector" {}))
17+
(let [other-args (rest binding-like-vector)
18+
body (rest macro-args)]
19+
{:node (api/list-node
20+
(list*
21+
(api/token-node 'let)
22+
;; simulate the effect, macro is creating a new thing (driver for example)
23+
;; via binding it. I don't think the bound value matters for the linting process
24+
(api/vector-node [binding-sym (api/map-node [])])
25+
;; reference the other args so that they are not linted as unused
26+
(api/vector-node other-args)
27+
body))}))))))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
(ns etaoin.hooks-util
2+
(:require [clj-kondo.hooks-api :as api]))
3+
4+
(defn symbol-node? [node]
5+
(and (api/token-node? node)
6+
(symbol? (api/sexpr node))))

.clj-kondo/potemkin/potemkin/config.edn

Lines changed: 0 additions & 62 deletions
This file was deleted.

.clj-kondo/potemkin/potemkin/potemkin/namespaces.clj

Lines changed: 0 additions & 56 deletions
This file was deleted.

deps.edn

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
org.babashka/cli {:mvn/version "0.8.62"}
2525
ch.qos.logback/logback-classic {:mvn/version "1.3.15"}
2626
;; for http-client which uses apache http client 4.x which uses commons logging
27-
org.slf4j/jcl-over-slf4j {:mvn/version "2.0.16"}}
27+
org.slf4j/jcl-over-slf4j {:mvn/version "2.0.16"}
28+
;; slingshot does not have a kondo config, grab kondo team provided config from here
29+
io.github.clj-kondo/config-slingshot-slingshot {:mvn/version "1.0.0"}}
2830
:exec-fn test-shared/test
2931
:org.babashka/cli {:coerce {:nses [:symbol]
3032
:patterns [:string]
@@ -61,7 +63,7 @@
6163
:jvm-opts ["-Dclojure.storm.instrumentOnlyPrefixes=etaoin"]}
6264

6365
;; for consistent linting we use a specific version of clj-kondo through the jvm
64-
:clj-kondo {:extra-deps {clj-kondo/clj-kondo {:mvn/version "2024.11.14"}}
66+
:clj-kondo {:extra-deps {clj-kondo/clj-kondo {:mvn/version "2025.01.16"}}
6567
:main-opts ["-m" "clj-kondo.main"]}
6668

6769
:eastwood {:extra-deps {jonase/eastwood {:mvn/version "1.4.3"}}

0 commit comments

Comments
 (0)