This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-13
Channels
- # announcements (14)
- # babashka (13)
- # beginners (25)
- # biff (7)
- # calva (36)
- # clj-kondo (22)
- # clojure (31)
- # clojure-austin (1)
- # clojure-europe (12)
- # clojure-losangeles (4)
- # clojure-nl (1)
- # clojure-norway (61)
- # clojure-uk (4)
- # clojurescript (3)
- # datomic (24)
- # events (1)
- # humbleui (9)
- # leiningen (9)
- # lsp (30)
- # malli (3)
- # missionary (15)
- # off-topic (5)
- # re-frame (4)
- # reitit (7)
- # releases (2)
- # remote-jobs (4)
- # rewrite-clj (11)
- # ring-swagger (2)
- # sci (6)
- # xtdb (2)
- # yamlscript (3)
I want to write a hook that takes a function call (f sym args)
and rewrites it to be (do (declare sym) (f sym args))
. it seems that the naive approach causes clj-kondo to recurse. how do i get it to ignore the sub-call to f
here?
i want linting on the sub-forms in args
if that works, then we can make an API function for it, since this is kind of an implementation detail π
that didn't work, as far as i can tell.
(defn =>
[{:keys [node]}]
(let [[=>-sym fn-sym schema] (:children node)
new-node (api/list-node
[(api/coerce 'do) (api/coerce (list 'declare fn-sym))
(assoc node :visited true)])]
(prn new-node)
{:node new-node}))
it prints a lot and then fails
ayy that works
(defn =>
[{:keys [node]}]
(let [[=>-sym fn-sym schema] (:children node)
new-node (api/list-node
[(api/coerce 'do) (api/coerce (list 'declare fn-sym))
(assoc node :visited ['malli.core '=>])])]
(prn new-node)
{:node new-node}))
I'm not sure why I decided to go with this approach (assoc-ing the vector with symbols) anymore though
i don't mind relying on implementation that might break lol
maybe my thought was that you could have multiple hooks for one of the same function but that's not currently supported
Hello everyone! Any suggestion to correctly lint this macro or disable completely linting for it in my code:
(defmacro defphraser
"Defines a phraser. Takes a predicate with possible capture symbols which have
to be also defined in the argument vector."
{:arglists '([pred specifiers? [context-binding-form problem-binding-form
& capture-binding-forms] & body])}
[pred & more]
(let [specifiers (when (map? (first more)) (first more))
[[context-binding-form problem-binding-form & capture-binding-forms]
& body]
(if specifiers (rest more) more)]
(if (= :default pred)
`(defmethod phrase* []
[~context-binding-form ~problem-binding-form]
~@body)
(let [{:keys [pred mappings]} (replace-syms (res &env pred capture-binding-forms)
capture-binding-forms)
{:keys [via]} specifiers
dispatch-val (cond-> [pred] (seq via) (conj via))
problem (gensym "problem")
binding-forms
(cond-> [problem-binding-form `(dissoc ~problem ::normalized-pred
::mappings ::via)]
(not-empty mappings)
(conj {mappings ::mappings} problem))]
`(defmethod phrase* '~dispatch-val [~context-binding-form ~problem]
(let ~binding-forms
~@body))))))
The macro is from this library. Lint as defn unluckily doesnβt workreplace foobar with the right namespace name from https://github.com/alexanderkiel/phrase
Thanks a lot @U04V15CAJ I was looking for this in the docs but had no luck