This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-04-24
Channels
- # ai (41)
- # announcements (4)
- # babashka (14)
- # beginners (24)
- # calva (7)
- # clj-kondo (36)
- # cljsrn (4)
- # clojure (68)
- # clojure-austin (2)
- # clojure-europe (39)
- # clojure-nl (2)
- # clojure-norway (37)
- # clojure-uk (2)
- # clojurescript (7)
- # clr (8)
- # community-development (16)
- # core-async (7)
- # datalevin (67)
- # fulcro (11)
- # helix (1)
- # honeysql (2)
- # london-clojurians (2)
- # off-topic (60)
- # pedestal (3)
- # portal (2)
- # practicalli (1)
- # re-frame (7)
- # reitit (49)
- # releases (3)
- # shadow-cljs (2)
- # xtdb (16)
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?can you maybe try to lint that code from the command line? this should not have any reloading problems
"Key must be integer" seems to be some kind of type error, where you are accessing something in a vector using a non-integer?
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.
Maybe the *reload*
thing isn't working properly then.
It's used here:
https://github.com/clj-kondo/clj-kondo/blob/a284300c3ed0c0c201d3d4933d22323ed44bd2d1/src/clj_kondo/impl/hooks.clj#L115
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.
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]
.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 itAh, 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!
Maybe I should do some verification when constructing those things, it trips me up sometimes too
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,...
@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.
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
@U2FRKM4TW I think the IDEA version is just a string in that clj-extras thing, perhaps you can compile it yourself...
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
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
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
> (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.
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?