Fork me on GitHub
#clj-kondo
<
2023-04-24
>
p-himik08:04:24

Trying to write a hook for dom-top.core/loopr which is like which is like loop + kinda for + finally. Started with this:

(defn loopr [{:keys [node]}]
      (println "loopr hook")
      (let [[_ acc-vec binding-vec & body] (:children node)
            _ (prn acc-vec binding-vec)
            new-node (api/list-node
                       (list*
                         (api/token-node 'loop)
                         (api/vector-node acc-vec)
                         (api/list-node
                           (list*
                             (api/token-node 'let)
                             (api/vector-node binding-vec)
                             body))))]
           {:node new-node}))
Clj-kondo docs on hooks state in a similar situation: "Moreover, it will report unused bindings and will give warnings customized to this macro." But I don't see it being the case here. Perhaps related, but I see another issue: Can't parse /home/p-himik/dev/git/ensemble/src/test.clj, Key must be integer pointing at the very first character in this file:
(ns test
  (:require [dom-top.core :as dom-top]))

(dom-top/loopr [acc []]
               [x (repeat 10 (range 10))
                y x]
               (recur (conj acc (inc y)))
               (apply + acc))
Not sure how to debug the above and what the mentioned key is supposed to be. Apart from that, (binding [api/*reload* true] ...) doesn't seem to work for me for some reason. If I replace the first println message above with something else and re-execute (pprint/pprint (binding [api/*reload* true] (:findings (clj-kondo/run! {:lint ["/home/p-himik/dev/git/ensemble/src/test.clj"]})))), it prints the old message. Any advice?

borkdude08:04:24

can you maybe try to lint that code from the command line? this should not have any reloading problems

borkdude08:04:47

"Key must be integer" seems to be some kind of type error, where you are accessing something in a vector using a non-integer?

borkdude08:04:15

Are you using the most recent clj-kondo?

p-himik09:04:47

Yeah, "LATEST" just from today. Hmm, the CLI doesn't given that error at all. Aaaand the "key must be integer" error is gone after restarting the REPL, even though I have changed no files.

p-himik09:04:49

Ah, hold on - I did change something, just didn't register it in my memory because my wife called me for breakfast that exact instant. :D Alright, the error is back. So seems like it's in the hook code and maybe I can simply try-catch it.

p-himik09:04:01

Found my mistake - I was wrapping nodes into other nodes. Is there a way to unparse a node? Can't find it in the code or the docs. Just printing it gives me

<list: (loop [acc []] [:tag :list] [:format-string (%s)] [:wrap-length 2] [:seq-fn #object[clj_kondo.impl.rewrite_clj.node.seq$list_node$fn__1159 0x7be299ec clj_kondo.impl.rewrite_clj.node.seq$list_node$fn__1159@7be299ec]] [:children (<token: let> <vector: [x (repeat 10 (range 10)) y x z x]> <list: (recur (conj acc (inc y)))>)] [:clj-kondo.impl/generated true])>
and I have no idea what's wrong because recur is clearly there but the linter says that I'm using loop without recur now. I see api/pprint but judging by the code it will simply pretty-print the above. And also it's not available via the CLI tool for some reason: WARNING: error while trying to read hook for dom-top.core/loopr: Could not resolve symbol: api/pprint where api is [clj-kondo.hooks-api :as api].

borkdude09:04:49

What do you mean with "unparse a node"

p-himik09:04:37

To turn it into a string with Clojure code that I've "rewritten".

borkdude09:04:49

This:

[:tag :list] [:format-string (%s)] 
seems like you're nesting a node wrong, it's likely that you passed a node into a list-node or so while you should pass a vector with that node inside of it

borkdude09:04:58

yes, you can call str on it

p-himik09:04:38

Ah, str was also returning those internal vectors so I assumed that it wasn't the way to get the code. I see now, I was using list* where I should've been using list. Thanks!

borkdude09:04:02

Maybe I should do some verification when constructing those things, it trips me up sometimes too

borkdude09:04:13

Feel free to post an issue about that

p-himik09:04:47

Another issue that I'm not sure how to approach given my limited exposure to all the related things. After plugging clj-kondo into Cursive via the LSP plugin, typing now causes the code to flash with errors. E.g. I'll be typing in the binding vector of a let form and upon any new character the whole let form is highlighted in red for a single frame, along with some other completely unrelated parts of the code. No clue what to blame here - the linter, the LSP plugin, maybe Cursive, maybe some unset settings,...

p-himik09:04:09

This is what I mean.

borkdude09:04:32

@U2FRKM4TW Perhaps you can try #C02UN1B0998 for Cursive? The lsp plugin isn't maintained anymore for a while I believe, but I could be wrong.

borkdude09:04:59

I mean the intellij lsp plugin, the clj-kondo lsp server is still maintained

p-himik10:04:30

Ah, crap. I'm willfully stuck with an older version of IDEA that that extras plugin doesn't support. I guess that brings the "I'll move to Calva any day now" moment closer. :D

borkdude10:04:31

@U2FRKM4TW I think the IDEA version is just a string in that clj-extras thing, perhaps you can compile it yourself...

borkdude10:04:10

moving to Calva will bring you the full clojure-lsp support (based on clj-kondo analysis ) which is quite good now, only the Java interop stuff is subpar compared to IDEA

borkdude10:04:18

(but we're working on that)

borkdude10:04:58

for the flashy thing while typing the binding name: it might be caused by this, I don't see this while typing this in emacs, I only get a warning on the vector that the bindings aren't even

borkdude10:04:13

Well, other things are warned about then too: since the bindings and values are now swapped basically, the syntactic check that a binding name should be a symbol messes things up

p-himik10:04:53

> (but we're working on that) Sweet! That's one of those things that I definitely value in IDEA. Being able to seamlessly navigate between CLJ an Java code is a blessing.

genmeblog14:04:09

SOLVED: remind to myself, do precisely as it states in the docs... I have a problem with importing configs from external library. Probably doing something wrong here. The library's config (it's on the Clojars, and jar includes these files): https://github.com/Clojure2D/clojure2d/tree/master/resources/clj-kondo.exports/clojure2d/clojure2d My local project's deps.edn content:

{:paths ["src"]
 :deps {org.clojure/clojure {:mvn/version "1.11.1"}
        clojure2d/clojure2d {:mvn/version "1.4.5-SNAPSHOT"}}}
Calling the following doesn't copy configs:
$ clj-kondo --lint "$(clojure -Spath)" --copy-configs --skip-lint
No configs copied.
linting took 75ms, errors: 0, warnings: 0
Any idea what's wrong?

2
borkdude14:04:41

check if the files are really in the jar file

borkdude14:04:04

also you need to have a .clj-kondo directory

borkdude14:04:13

in the project where you are copying the configs

genmeblog14:04:11

omg... ok... It's working...

genmeblog14:04:39

I've made testing repo without .clj-kondo

genmeblog14:04:17

But in the other (already existing, with .clj-kondo) repo I skipped --lint arg.