clj-kondo

valerauko 2025-03-11T07:24:05.053699Z

Is it possible to add an analyze hook for defn?

valerauko 2025-03-11T07:25:20.255619Z

Something like

(defn my-hook
  [{:keys [node] :as input}]
  (if (something node)
    (do my stuff)
    input)) ;; fall back to original behavior
Is there some existing hook I should call or

valerauko 2025-03-11T07:28:19.351179Z

What I'm trying to do: hook into defn, check if any of the arglists has .child and replace it with _ child to resolve warnings in clojuredart (I know it's super hacky but it could at least resolve the most major case)

borkdude 2025-03-11T08:37:02.163489Z

have you tried it?

valerauko 2025-03-11T10:52:20.616979Z

Yeah if I just replace the args like that, it seems that defn forms get ignored by clj-kondo altogether. That's why I wondered if I could call into some existing hook to "extend" the default behavior

valerauko 2025-03-11T10:52:51.087779Z

For now I worked around this by aliasing defn as defwidget, adding a hook for defwidget and replacing every defn that had a .child with defwidget

borkdude 2025-03-11T10:52:55.916269Z

> it seems that defn forms get ignored by clj-kondo altogether. what are you returning?

valerauko 2025-03-11T10:53:20.663779Z

The updated {:node node} thing

borkdude 2025-03-11T10:53:54.097639Z

could it be that you are messing something up?

borkdude 2025-03-11T10:53:59.925069Z

no offense of course

valerauko 2025-03-11T10:54:48.965679Z

None taken, that sanity check was my first step too. But alas the hook as below seems to have had that effect

(defn my-hook
  [{:keys [node] :as input}]
  input)

borkdude 2025-03-11T10:55:22.215779Z

you can run clj-kondo with --debug to have extra verification when constructing nodes

borkdude 2025-03-11T10:55:36.512759Z

also printing the new node might help to see if it's constructed correctly

valerauko 2025-03-11T10:57:21.661929Z

Just to make sure I understand correctly If I add a hook for clojure.core/defn, and my hook returns a node that still starts with defn, it should get passed to the "default" linters for defn?

borkdude 2025-03-11T10:58:12.498159Z

I think so

๐Ÿ‘ 1
ericdallo 2025-03-11T17:07:38.234109Z

I'm taking a look at this https://github.com/clojure-lsp/clojure-lsp/issues/1957 and realized that it doesn't work because of how clj-kondo return findings of syntax type ๐Ÿงต

ericdallo 2025-03-11T17:08:11.628119Z

for the following code:

(ns clojure-lsp.feature.foo)


foobar/
{:end-row 4, :type :syntax, :level :error, :col 1, :uri "file:///home/greg/dev/clojure-lsp/lib/src/clojure_lsp/feature/foo.clj", :end-col 1, :langs (), :message "Invalid symbol: foobar/.", :row 4}
would be possible to end-col be 6 o7 instead of 1?

ericdallo 2025-03-11T17:09:41.098509Z

other types like unresolved-namespace or unknown-symbol work with the end-col matching properly

borkdude 2025-03-11T18:20:41.088789Z

@lee is this perhaps an issue that is related to the tools.reader bump in rewrite-clj?

borkdude 2025-03-11T18:21:12.989859Z

@ericdallo feel free to post an issue

ericdallo 2025-03-11T18:44:32.632639Z

I believe this behavior is pretty old, will create a issue

ericdallo 2025-03-11T18:47:26.383039Z

https://github.com/clj-kondo/clj-kondo/issues/2502

borkdude 2025-03-11T18:49:15.190909Z

thanks

lread 2025-03-11T18:59:27.099089Z

> @lee is this perhaps an issue that is related to the tools.reader bump in rewrite-clj? I don't think so... The tools.reader bug was an off by one end-col for numbers/symbols/keywords at eof.