Fork me on GitHub
#clj-kondo
<
2022-06-01
>
borkdude10:06:40

I'm working on clj-kondo hooks workshop material now for next week's ClojureD. Is there anyone who isn't going there and wants me to help go through the material? Please give me a ping :)

Ken Allen18:06:33

Is there a way to set up linting for plumbing.core/fn-> ? if I lint as clojure.core/-> I still get type and arity errors for the first form. I’d rather not exclude if I can get away with it

borkdude18:06:35

@kallen I think this is a good candidate for hooks. 🧵

borkdude18:06:34

I'm working on a more gentle introduction to hooks here: https://github.com/clj-kondo/hooks-workshop-clojured-2022 This is work in progress and will be used for a workshop next week on ClojureD

Ken Allen18:06:15

TIL that the version of clojure-lsp I installed from homebrew is super old. After fixing that and following the example it seems to be working. I essentially just copied the source from plumbing.core but I gather that I don’t actually need to do that if the real macro is happy being run from SCI?

Ken Allen18:06:05

hmm maybe I spoke too soon. It’s not complaining anymore but emacs is now highlighting the entire (fn-> ….) form like it’s a symbol when my cursor is in it and it’s showing a gensymed symbol in the minibuffer. No idea where in the kondo->lsp->emacs chain that issue is coming from

borkdude18:06:07

@kallen Hmm, can you make a repro?

borkdude19:06:30

@kallen So this works for me:

(defmacro fn-> [& body]
  `(fn [x#] (-> x# ~@body)))

borkdude19:06:38

hooks-workshop.macros/fn-> hooks-workshop.macros/fn->

borkdude19:06:59

And then:

(def f (fn-> inc inc))
  (f 1 2)
gives a lint warning about calling f with an incorrect amount of args (which is expected)

borkdude19:06:18

So how are you calling fn->?

Ken Allen19:06:53

to be clear it does lint correctly now. if I do (fn-> str inc) it complains that it’s getting a string when it expects a number

Ken Allen19:06:26

What I’m seeing is that now clojure-lsp seems to think the entire fn-> form is a symbol so it highlights it and puts the symbol at the bottom, just like if I had put my cursor on def

borkdude20:06:25

Yeah, this is an artifact of :macroexpand . If you want more precise linting, use :analyze-call

borkdude20:06:31

which isn't that hard with a macro like this

borkdude20:06:59

Tomorrow I'll write part 3 of the workshop which should hopefully help ;)

borkdude20:06:10

But the docs about it should be good too

Ken Allen20:06:28

I think I get the picture of what is needed from the docs but you might have the workshop part written by the time I get to poking at this tomorrow.

Ken Allen20:06:27

is there a good way to distribute this sort of config? plumbing is a pretty popular library. Or is the idea that they become part of the library itself?

Joshua Suskalo20:06:43

You can make a PR to put it in the config exports in the library's resources.

Joshua Suskalo20:06:57

I think there's a community project to distribute them too if the library owner refuses to accept a PR to make it part of their library exports.

borkdude20:06:36

I think we have a fair chance of getting this into plumbing, since @U055XFK8V is a maintainer there

borkdude20:06:44

But it's currently not fine-grained, it imports all of those which isn't really optimal

borkdude20:06:10

Splitting up into separate deps could work

borkdude20:06:19

Anyway, it's best to send the configs to the source library

Ken Allen21:06:15

cool, if I get analyze-call working and I get a free moment I’ll PR up at least the stuff that I use on a regular basis. Hopefully that will provide a kernel to grow from.

👍 1
J20:06:13

Hi guys! Is there a way to detect that (inc pokemon) is incorrect (like (inc "1")) because pokemon has a Pokemon schema?

borkdude20:06:05

I think theoretically that should be possible since Pokemon is, at minimum, a map right?

borkdude20:06:33

E.g. this does warn:

(let [x {}]
  (inc x))

J20:06:22

Yes pokemon is a map

borkdude20:06:29

So if you could make a repro using pure clj-kondo, and post an issue about it, we can see why it's not working and how it can be fixed

👍 1