clj-kondo 2024-12-30

Hello, am I doing something wrong with this hook? I have this macro:

(ns voice-fn.frames)

(defmacro defframe
  "Define a frame creator function and its predicate.
   Usage: (defframe audio-input :audio/raw-input \"Doc string\")"
  [name type docstring]
  `(do
     (defn ~name
       ~docstring
       [data#]
       (create-frame ~type data#))

     (defn ~(symbol (str name "?"))
       [frame#]
       (and (frame? frame#) (= ~type (:frame/type frame#))))))

(defframe llm-output-text-sentence-frame :llm/output-text-sentence
  "Frame generated by a sentence assembler that takes in chunks from a LLM processor")
.clj-kondo/config.edn:
{:lint-as {uncomplicate.commons.core/with-release clojure.core/let}
 :hooks {:analyze-call {voice-fn.frames/defframe hooks.defframe/defframe}}}
.clj-kondo/hooks/defframe.clj
(ns hooks.defframe
  (:require
   [clj-kondo.hooks-api :as api]))

(defn defframe [{:keys [node]}]
  (let [[name _type docstring] (rest (:children node))
        frame-name (api/token-node (api/symbol-from-node name))
        pred-name (api/token-node (symbol (str (api/symbol-from-node name) "?")))]
    {:node (api/list-node
             [(api/token-node 'do)
              (api/list-node
                [(api/token-node 'defn) frame-name docstring])
              (api/list-node
                [(api/token-node 'defn) pred-name])])}))
I am using clj-kondo through clojure LSP, so it might be that issue but it feels I just might be doing something wrong

You can be more specific what you mean with "wrong"? What is e.g. the expected behavior and the behavior you are now seeing?

Sorry, yeah, the expected behaviour is clojure-lsp will pick this config but I still get

try linting from the command line first

👍 1

Some relevant other details: • I restarted lsp-mode to make sure the new config is taken into account • My file structure might be relevant

voice-fn/
  .clj-kondo/
  core/
      .clj-kondo //specific to core
      src/
  examples
To make sure that this would work I included this config in both clj-kondo configs to be sure

just with clj-kondo, no lsp

you can't have multiple .clj-kondo directories in one project

I see. So best I move all config to topmost directory

yes or make multiple projects

Is a project defined by the presence of a deps.edn file or of a git repository? I have 2 deps.edn projects (core & examples) in the same git repo

The issue is picked up by kondo itself too, with latest release version

well, you see the WARNING? that is the issue you should address

Thank you, I saw it now after posting 😄

😀 1

I'm wondering if this is something clj-kondo could lint, it is not the first time I see a bug introduced in a project by someone putting an s-expression in the :or default value of a destructuring: https://github.com/cognitect-labs/aws-api/issues/262

user> (defn f1 [] (println "WOW YOU DON'T WANT THIS TO RUN"))
#'user/f1
user> (let [{:keys [x] :or {x (f1)}} {:x 1}] x)
WOW YOU DON'T WANT THIS TO RUN
1

I think that's a reasonable thing to want. Issue welcome!