Fork me on GitHub
#clj-kondo
<
2024-03-13
>
borkdude13:03:02

πŸŽ‰ 2
clj-kondo 1
πŸ™Œ 1
Noah Bogart15:03:48

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?

borkdude15:03:41

why not lint f as clj-kondo.lint-as/def-catch-all?

Noah Bogart15:03:07

i want linting on the sub-forms in args

borkdude15:03:16

can you try to do (assoc the-original-node :visited true)?

borkdude15:03:23

this will prevent recursion I believe

borkdude15:03:41

if that works, then we can make an API function for it, since this is kind of an implementation detail πŸ˜…

Noah Bogart15:03:45

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}))

borkdude15:03:05

try: :visited [the-namespace the-fn-symbol]

Noah Bogart15:03:06

it prints a lot and then fails

borkdude15:03:25

(now we're really in impl land...)

πŸ˜… 1
Noah Bogart15:03:35

ayy that works

Noah Bogart15:03:47

(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}))

borkdude16:03:14

I'm not sure why I decided to go with this approach (assoc-ing the vector with symbols) anymore though

Noah Bogart16:03:08

i don't mind relying on implementation that might break lol

borkdude16:03:34

maybe my thought was that you could have multiple hooks for one of the same function but that's not currently supported

borkdude16:03:09

anyway this is your current workaround then, for now ;)

πŸ‘ 1
jplaza20:03:02

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 work

borkdude21:03:43

You can do this:

{:config-in-call {foobar/defphraser {:ignore true}}}

borkdude21:03:05

replace foobar with the right namespace name from https://github.com/alexanderkiel/phrase

πŸ™Œ 1
jplaza22:03:01

Thanks a lot @U04V15CAJ I was looking for this in the docs but had no luck