This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-09-18
Channels
- # announcements (1)
- # asami (2)
- # babashka (21)
- # beginners (23)
- # cider (5)
- # clj-kondo (10)
- # clojure (31)
- # clojure-europe (3)
- # clojure-nl (1)
- # clojurescript (47)
- # deps-new (1)
- # figwheel-main (7)
- # fulcro (7)
- # gratitude (1)
- # jobs-discuss (2)
- # lein-figwheel (1)
- # lsp (5)
- # off-topic (11)
- # pathom (5)
- # re-frame (1)
- # react (5)
- # reagent (4)
- # releases (1)
- # shadow-cljs (63)
- # tools-deps (16)
- # xtdb (26)
@aramz If the struggle is too real, then you can also just re-use that macro with the :macroexpand
hook :)
It usually helps me to put a println with the new-node
to debug the resulting node
E.g. when I lint:
(ns bar
(:require [foo :as foo]))
(foo/for-indexed
[itm idx [1 2 3]]
)
then I see <list: (let [itm idx])>
as the expansion and I get an unresolved idx
because that's the right value which is referring to something unknown.@aramz So this implementation works:
(defn for-indexed [{:keys [:node]}]
(let [[bindings & body] (-> node :children rest)
[item index coll] (:children bindings)
new-node (api/list-node
(list
(api/token-node 'for)
(api/vector-node [item coll])
(api/list-node
(list*
(api/token-node 'let)
(api/vector-node [index (api/token-node 0)])
body))))]
{:node new-node}))
I'm just generating <list: (for [itm [1 2 3]] (let [idx 0] itm))>
there, to keep it simple, so I'm making a let with idx bound to 0, so if you don't use this binding then clj-kondo will report the binding as unused.Thank you for this @U04V15CAJ - I have been trying to wrap my head around this. I’ve been tweaking your solution to try to better understand how it works. I’m confused as to why the variadic form & body works and without it returns all the same finding of no item, index coll. Also, I’m using calva and I need to restart vscode to get any changes in clj-kondo. Instead now, I’ve been linting via command line and using jet (excellent tool btw) to see what’s happening. Wondering if you have tips on a better workflow for building hooks. Lastly, I am trying to use the macroexpand hook. where would I see the output of this? When I run
clj-kondo --lint src/rdd/components/recipe/recipe_editor/testing.cljs --config '{:output {:analysis true :format :edn} :linters {:for-indexed/missing-index {:level :error}} :hooks {:macroexpand {rdd.utils.for-indexed/for-indexed script/for-indexed}}}' | jet --pretty
I’m not seeing anything like you mentioned when you lint <list: (let [itm idx])>
Thanks again for all the amazing work