Skip to content

Commit

Permalink
add clj-kondo hook for parallel let plet
Browse files Browse the repository at this point in the history
  • Loading branch information
martinklepsch committed Nov 23, 2023
1 parent 658c429 commit 4eb8291
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion resources/clj-kondo.exports/funcool/promesa/config.edn
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
promesa.core/->> clojure.core/->>
promesa.core/as-> clojure.core/as->
promesa.core/let clojure.core/let
promesa.core/plet clojure.core/let
promesa.core/plet hooks.promesa/plet
promesa.core/loop clojure.core/loop
promesa.core/recur clojure.core/recur
promesa.core/with-redefs clojure.core/with-redefs
Expand Down
16 changes: 16 additions & 0 deletions resources/clj-kondo.exports/funcool/promesa/hooks/promesa.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
(ns hooks.promesa
(:require [clj-kondo.hooks-api :as api]))

(defn plet
;; this effectively rewrites the let to `(let [[bind1 bind2] [(expr-1) (expr-2)] ,,,)
;; making referring to other binding syms produce an error
;; thanks to @NoahBogart on Slack for this
[{:keys [:node]}]
(let [[_plet binds & body] (:children node)
new-bind-syms (api/vector-node (take-nth 2 (:children binds)))
new-bind-exprs (api/vector-node (take-nth 2 (rest (:children binds))))
new-node (api/list-node
(list* (api/token-node 'clojure.core/let)
(api/vector-node [new-bind-syms new-bind-exprs])
body))]
{:node new-node}))

0 comments on commit 4eb8291

Please sign in to comment.