Skip to content

Commit

Permalink
docs: readme: update contributors (#22)
Browse files Browse the repository at this point in the history
Switch to using etaoin for generating contributor badges (mostly
borrowed from work I did on cljdoc).
  • Loading branch information
lread authored May 1, 2024
1 parent 88e139a commit b8920e8
Show file tree
Hide file tree
Showing 16 changed files with 302 additions and 140 deletions.
32 changes: 32 additions & 0 deletions .clj-kondo/etaoin/etaoin/config.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{:linters
{:etaoin/with-x-action {:level :error}
:etaoin/binding-sym {:level :error}
:etaoin/opts-map-type {:level :error}
:etaoin/opts-map-pos {:level :error}
:etaoin/empty-opts {:level :warning}}
:hooks
{:analyze-call
{etaoin.api/with-chrome etaoin.api/with-browser
etaoin.api/with-chrome-headless etaoin.api/with-browser
etaoin.api/with-firefox etaoin.api/with-browser
etaoin.api/with-firefox-headless etaoin.api/with-browser
etaoin.api/with-edge etaoin.api/with-browser
etaoin.api/with-edge-headless etaoin.api/with-browser
etaoin.api/with-phantom etaoin.api/with-browser
etaoin.api/with-safari etaoin.api/with-browser

etaoin.api/with-driver etaoin.api/with-driver
etaoin.api/with-key-down etaoin.api/with-key-down
etaoin.api/with-pointer-btn-down etaoin.api/with-pointer-btn-down

;; api2 moves to a more conventional let-ish vector syntax
etaoin.api2/with-chrome etaoin.api2/with-browser
etaoin.api2/with-chrome-headless etaoin.api2/with-browser
etaoin.api2/with-edge etaoin.api2/with-browser
etaoin.api2/with-edge-headless etaoin.api2/with-browser
etaoin.api2/with-firefox etaoin.api2/with-browser
etaoin.api2/with-firefox-headless etaoin.api2/with-browser
etaoin.api2/with-phantom etaoin.api2/with-browser
etaoin.api2/with-safari etaoin.api2/with-browser}}
:lint-as
{etaoin.api/with-pointer-left-btn-down clojure.core/->}}
113 changes: 113 additions & 0 deletions .clj-kondo/etaoin/etaoin/etaoin/api.clj_kondo
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
(ns etaoin.api
(:require [clj-kondo.hooks-api :as api]
[etaoin.hooks-util :as h]))

(defn- nil-node? [n]
(and (api/token-node? n) (nil? (api/sexpr n))))

(defn- with-bound-arg [node arg-offset]
(let [macro-args (rest (:children node))
leading-args (take arg-offset macro-args)
interesting-args (drop arg-offset macro-args)
[opts binding-sym & body] (if (h/symbol-node? (second interesting-args))
interesting-args
(cons nil interesting-args))]
;; if the user has specified nil or {} for options we can suggest that is not necessary
(when (and opts
(or (and (api/map-node? opts) (not (seq (:children opts))))
(nil-node? opts)))
(api/reg-finding! (assoc (meta opts)
:message "Empty or nil driver options can be omitted"
:type :etaoin/empty-opts)))

(cond
(not (h/symbol-node? binding-sym))
;; it makes more sense here to report on the incoming node position instead of what we expect to be the binding-sym
(api/reg-finding! (assoc (meta node)
:message "Expected binding symbol for driver"
:type :etaoin/binding-sym))

;; we don't want to explicitly expect a map because the map might come from
;; an evalution, but we can do some checks
(and opts ;; we'll assume a list-node is a function call (eval)
(not (nil-node? opts)) ;; nil is actually old-v1 syntax acceptable
(not (api/list-node? opts)) ;; some fn call
(not (h/symbol-node? opts)) ;; from a binding maybe
;; there are other eval node types... @(something) for example... maybe we'll add them in if folks ask
(not (api/map-node? opts)))
;; we can report directly on the opts node, because at this point we know we expect
;; this arg position to be an opts map
(api/reg-finding! (assoc (meta opts)
:message "When specified, opts should be a map"
:type :etaoin/opts-map-type))

;; one last nicety, if the first form in body is a map, the user has accidentally swapped
;; binding and opt args
(api/map-node? (first body))
(api/reg-finding! (assoc (meta (first body))
:message "When specified, opts must appear before binding symbol"
:type :etaoin/opts-map-pos))

:else
{:node (api/list-node
(list*
(api/token-node 'let)
;; simulate the effect, macro is creating a new thing (driver for example)
;; via binding it. I don't think the bound value matters for the linting process
(api/vector-node [binding-sym (api/map-node [])])
;; reference the other args so that they are not linted as unused
(api/vector-node leading-args)
opts ;; might be a binding, so ref it too
body))})))

(defn- with-x-down
"This is somewhat of a maybe an odd duck.
I think it is assumed to be used within a threading macro.
And itself employs a threadfirst macro.
So each body form need to have an action (dummy or not) threaded into it."
[node]
(let [macro-args (rest (:children node))
[input x & body] macro-args
dummy-action (api/map-node [])]
{:node (api/list-node
(apply list*
(api/token-node 'do)
;; reference x and input just in case they contain something lint-relevant
x input
;; dump the body, threading a dummy action in as first arg
(map (fn [body-form]
(cond
;; not certain this is absolutely what we want, but maybe close enough
(h/symbol-node? body-form) (api/list-node (list* body-form dummy-action))
(api/list-node? body-form) (let [children (:children body-form)]
(assoc body-form :children (apply list*
(first children)
dummy-action
(rest children))))
:else
(api/reg-finding! (assoc (meta body-form)
:message "expected to be threaded through an action"
:type :etaoin/with-x-action))))
body)))}))

(defn with-browser
"Covers etaoin.api/with-chrome and all its variants
[opt? bind & body]"
[{:keys [node]}]
(with-bound-arg node 0))

(defn with-driver
"Very similar to with-browser but bound arg is 1 deeper
[type opt? bind & body]"
[{:keys [node]}]
(with-bound-arg node 1))

(defn with-key-down
"[input key & body]"
[{:keys [node]}]
(with-x-down node))

(defn with-pointer-btn-down
"[input button & body]"
[{:keys [node]}]
(with-x-down node))
27 changes: 27 additions & 0 deletions .clj-kondo/etaoin/etaoin/etaoin/api2.clj_kondo
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(ns etaoin.api2
(:require [clj-kondo.hooks-api :as api]
[etaoin.hooks-util :as h]))

(defn with-browser
"Newer variants for api2
[[bind & [options]] & body]"
[{:keys [node]}]
(let [macro-args (rest (:children node))
binding-like-vector (first macro-args)]
(if-not (api/vector-node? binding-like-vector)
;; could use clj-kondo findings, but I think this is good for now
(throw (ex-info "Expected vector for first arg" {}))
(let [binding-sym (-> binding-like-vector :children first)]
(if-not (h/symbol-node? binding-sym)
(throw (ex-info "Expected binding symbol for first arg in vector" {}))
(let [other-args (rest binding-like-vector)
body (rest macro-args)]
{:node (api/list-node
(list*
(api/token-node 'let)
;; simulate the effect, macro is creating a new thing (driver for example)
;; via binding it. I don't think the bound value matters for the linting process
(api/vector-node [binding-sym (api/map-node [])])
;; reference the other args so that they are not linted as unused
(api/vector-node other-args)
body))}))))))
6 changes: 6 additions & 0 deletions .clj-kondo/etaoin/etaoin/etaoin/hooks_util.clj_kondo
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
(ns etaoin.hooks-util
(:require [clj-kondo.hooks-api :as api]))

(defn symbol-node? [node]
(and (api/token-node? node)
(symbol? (api/sexpr node))))
22 changes: 11 additions & 11 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,26 @@ Test-doc-block versioning scheme is: `major`.`minor`.`patch`-`test-qualifier`
// Contributors updated by script, do not edit
// AUTO-GENERATED:CONTRIBUTORS-START
:imagesdir: ./doc/generated/contributors
[.float-group]
[]
--
image:seancorfield.png[seancorfield,role="left",width=310,link="https://github.com/seancorfield"]
image:MIJOTHY.png[MIJOTHY,role="left",width=310,link="https://github.com/MIJOTHY"]
image:borkdude.png[borkdude,role="left",width=310,link="https://github.com/borkdude"]
image:holyjak.png[holyjak,role="left",width=310,link="https://github.com/holyjak"]
image:PEZ.png[PEZ,role="left",width=310,link="https://github.com/PEZ"]
image:SevereOverfl0w.png[SevereOverfl0w,role="left",width=310,link="https://github.com/SevereOverfl0w"]
image:sogaiu.png[sogaiu,role="left",width=310,link="https://github.com/sogaiu"]
image:uochan.png[uochan,role="left",width=310,link="https://github.com/uochan"]
image:seancorfield.png[seancorfield,width=273,link="https://github.com/seancorfield"]
image:MIJOTHY.png[MIJOTHY,width=273,link="https://github.com/MIJOTHY"]
image:borkdude.png[borkdude,width=273,link="https://github.com/borkdude"]
image:holyjak.png[holyjak,width=273,link="https://github.com/holyjak"]
image:PEZ.png[PEZ,width=273,link="https://github.com/PEZ"]
image:SevereOverfl0w.png[SevereOverfl0w,width=273,link="https://github.com/SevereOverfl0w"]
image:sogaiu.png[sogaiu,width=273,link="https://github.com/sogaiu"]
image:uochan.png[uochan,width=273,link="https://github.com/uochan"]
--
// AUTO-GENERATED:CONTRIBUTORS-END

=== Current Maintainers
// Maintainers updated by script, do not edit
// AUTO-GENERATED:MAINTAINERS-START
:imagesdir: ./doc/generated/contributors
[.float-group]
[]
--
image:lread.png[lread,role="left",width=310,link="https://github.com/lread"]
image:lread.png[lread,width=273,link="https://github.com/lread"]
--
// AUTO-GENERATED:MAINTAINERS-END

Expand Down
3 changes: 2 additions & 1 deletion bb.edn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
:deps {lread/status-line {:git/url "https://github.com/lread/status-line.git"
:sha "cf44c15f30ea3867227fa61ceb823e5e942c707f"}
dev.nubank/docopt {:mvn/version "0.6.1-fix7"}
version-clj/version-clj {:mvn/version "2.0.2"}}
version-clj/version-clj {:mvn/version "2.0.2"}
etaoin/etaoin {:mvn/version "1.0.40"}}

:tasks {;; setup
:requires ([babashka.fs :as fs]
Expand Down
Binary file modified doc/generated/contributors/MIJOTHY.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/generated/contributors/PEZ.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/generated/contributors/SevereOverfl0w.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/generated/contributors/borkdude.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/generated/contributors/holyjak.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/generated/contributors/lread.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/generated/contributors/seancorfield.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/generated/contributors/sogaiu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/generated/contributors/uochan.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b8920e8

Please sign in to comment.