Fork me on GitHub
#clj-kondo
<
2023-02-24
>
grzm16:02:09

Do people generally exclude imported clj-kondo configs from version control (say, using .gitignore)? We’ve got one (for a transitive dependency that we’re not using) that happens to always trip our cljfmt runs.

borkdude16:02:34

If you're not using that library you could just gitignore it. I do check in configs for libs that I am using, so everyone has the same clj-kondo config, but whatever works best for you. does cljfmt support an ignore setting?

☝️ 2
grzm16:02:11

I think probably, but I’m currently working out how lsp and cljfmt work together, so I think I’ll just exclude it in deps.edn. That should prevent the clj-kondo config from being imported, correct?

borkdude16:02:03

yes, I think so

borkdude16:02:09

as long as it doesn't get into your classpath

grzm16:02:33

Yup. At least clj -Stree doesn’t show it 🙂

grzm16:02:28

I agree the cljfmt ignore would be more surgical. And maybe I’ll just submit a patch upstream and see if they take it. Thanks!

borkdude16:02:29

good luck! :)

Derek19:02:41

I’m looking at some legacy code and found the following form (in thread) which kondo does not like. Is it valid Clojure?

Derek19:02:03

(defprotocol Body
  (to-body [x]))

(extend-protocol Body
  (class (byte-array 0))
  (to-body [this] (RequestBody/fromBytes this)))

Derek19:02:29

kondo complains that Function arguments should be wrapped in vector.

borkdude19:02:09

Which library is this. It is not valid code. See a recent discussion in #CF595DNF7

borkdude19:02:19

This code only works by accident

Derek19:02:06

Thanks, it’s internal code unfortunately

borkdude19:02:21

why is that unfortunately? then you can change it right?

Derek19:02:47

Oh yes! I meant that I could not show you in situ

borkdude19:02:03

Something like this should work:

(defprotocol Body
  (to-body [x]))

(extend (class (byte-array 0))
  Body {:to-body (fn [this] (RequestBody/fromBytes this))})

Derek19:02:17

Thank you, I’ll give that a try!

hiredman20:02:18

In the above thread @U060FKQPN explains why there are issues with code like, but it is not clear if those issues are a bug in the extend-protocol definition, or if that is invalid code

borkdude21:02:43

Given that it only works accidentally for one case, but not when you provide some combination of other stuff (in which clj emits an invalid type hint like ^(class (byte-array 0))) in the expansion) I'd not use it at all at this point, but it would be good if the core team (@U064X3EF3 ?) could shed some light on this if it's supported or a bug.

hiredman21:02:15

https://clojure.atlassian.net/browse/CLJ-1381 appears to be this issue, but not a lot of commentary

👍 2
borkdude21:02:27

I personally wouldn't mind if the solution was (extend-protocol Foobar bytes ...)

borkdude21:02:44

but given that there is extend perhaps we don't need it

borkdude18:02:39

In Clojure 1.12 you can write byte*

Alex Miller (Clojure team)20:02:46

don't get too attached to the foo* :)

Alex Miller (Clojure team)20:02:11

you can also use the string form in this code I believe

Alex Miller (Clojure team)20:02:43

guess not, I thought there was some other workaround but maybe the code up top is what I'm thinking of

Alex Miller (Clojure team)20:02:58

but wherever we end up on the class array stuff, that would help regardless