Fork me on GitHub
#clj-kondo
<
2021-09-17
>
royalaid20:09:28

Hey @borkdude love kondo! I’m trying to extend to catch all of my calls to js/console.log . I figured this would be like any other hook but it doesn’t seem to be picking up the usages in my project

borkdude20:09:44

@royalaid the hooks are currently only for clojure code, not for interop. if you could like to find calls like this, you could either use grep or https://github.com/borkdude/grasp or similar.

royalaid20:09:43

So it won’t pick up forms like the ones in the js ns?

borkdude20:09:17

I don't think so (but worth a try :P)

royalaid20:09:59

Yeah it wasn’t getting them so wanted to make sure I wasn’t missing some, seems like your assumptions are correct 😢

az22:09:54

Hi everyone. I’ve been struggling for hours to try to build a hook, but I’m really stuck on this one. Any tips to getting something like this working with kondo?

(defmacro for-indexed [[item index coll] & body]
  `(for [i# (range (count ~coll))]
     (let [~item (nth ~coll i#)
           ~index i#]
       ~@body)))
This is how far I’ve been able to get but I still get linting errors. Unused binding coll, item and index
(ns hooks.for-indexed
  (:require [clj-kondo.hooks-api :as api]
            [clojure.edn :as edn]))

(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 'let)
                   (api/vector-node [item index])
                   body))]
    {:node new-node}))
Any ideas?