Skip to content

Commit

Permalink
Initial implemention
Browse files Browse the repository at this point in the history
  • Loading branch information
acamargo committed Apr 22, 2024
1 parent 3840f4e commit 0486e6f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
8 changes: 5 additions & 3 deletions resources/clj-kondo.exports/nubank/state-flow/config.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{:lint-as {state-flow.api/for clojure.core/for}
:hooks {:analyze-call {state-flow.cljtest/defflow nubank.state-flow/defflow
state-flow.api/defflow nubank.state-flow/defflow
state-flow.core/flow nubank.state-flow/flow
state-flow.api/flow nubank.state-flow/flow}}}
state-flow.api/defflow nubank.state-flow/defflow
state-flow.core/flow nubank.state-flow/flow
state-flow.api/flow nubank.state-flow/flow
state-flow.labs.state/with-redefs nubank.state-flow/with-redefs
state-flow.vendor.potemkin/import-vars potemkin.namespaces/import-vars}}}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
(ns nubank.state-flow
(:refer-clojure :exclude [with-redefs])
(:require [clj-kondo.hooks-api :as hooks]))

(defn- normalize-mlet-binds
Expand All @@ -21,10 +22,12 @@
[(hooks/token-node 'let)
(hooks/vector-node new-bindings)])))

#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn flow [{:keys [node]}]
(let [forms (rest (:children node))]
{:node (with-meta (do-let forms) (meta node))}))

#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn defflow [{:keys [node]}]
(let [[test-name & body] (rest (:children node))
new-node (hooks/list-node
Expand All @@ -33,3 +36,27 @@
(do-let body)])]
{:node (with-meta new-node (meta node))
:defined-by 'state-flow.cljtest/defflow}))

#_{:clj-kondo/ignore [:clojure-lsp/unused-public-var]}
(defn with-redefs
"This transformation hook converts
(state-flow.labs.state/with-redefs [bindings & flows])
into
(do (clojure.core/with-redefs bindings)
(state-flow.core/flow \"state-flow.labs.state/with-redefs\" flows))"
[{:keys [node]}]
(let [[bindings & flows] (rest (:children node))
new-node (hooks/list-node
[(hooks/token-node 'do)
(hooks/list-node
[(hooks/token-node 'clojure.core/with-redefs)
bindings])
(hooks/list-node
(concat [(hooks/token-node 'state-flow.core/flow)
(hooks/string-node "state-flow.labs.state/with-redefs")]
flows))])]
{:node (with-meta new-node (meta node))
:defined-by 'state-flow.labs.state/with-redefs}))

0 comments on commit 0486e6f

Please sign in to comment.