clj-kondo 2024-09-24

How do I convert a clj-kondo.hooks-api/keyword-node? to a symbol node? In other words, what is the API's version of "(symbol (name kw))"?

(api/token-node (symbol (:string-value kw-node)))
Seems to work, but is it an ok thing to do?

(clj-kondo.hooks-api/parse-string ":foo")
#clj_kondo.impl.rewrite_clj.node.keyword.KeywordNode{:k :foo,
                                                     :namespaced? nil}
for me, keyword nodes have a :k value, not a :string-value

Yeah, I noticed

Must have tested with a string also and mixed them up

(i do see that attribute on token-nodes however)

So I ended up with (api/token-node (symbol (name (:k kw-node))))

that could drop the namespace of keywords you analyze. is that acceptable?

Yeah, it's fine for now. I am looking to transform code for clj-kondo so it recognizes something as ~a function

I’m looking at what we do in some of our custom analysis

.clj-kondo/src/hooks/metabase/api/common.clj
21:                    (api/token-node 'do)
22:                    (-> (api/token-node (symbol "compojure.core" (str (api/sexpr method))))
26:                      (api/token-node 'clojure.core/defn)
27:                      (-> (api/token-node (route-fn-name (api/sexpr method) (api/sexpr route)))
https://github.com/metabase/metabase/blob/master/.clj-kondo/src/hooks/metabase/api/common.clj#L27 We seem to prefer using api/sexp instead of using internal attributes

was aging for api/token-node

Ah, that's probably a little more resilient. Thanks

šŸ‘ 1