Fork me on GitHub
#clj-kondo
<
2021-10-12
>
borkdude13:10:30

Type inference improvements coming up in the next release: https://twitter.com/borkdude/status/1447920160350916608

borkdude13:10:12

(already available on master)

Noah Bogart14:10:34

that’s cool as hell

pez15:10:30

Where do I find the definitions of the default linters? I’m specifically interested in Inline def https://github.com/clj-kondo/clj-kondo/blob/master/doc/linters.md#inline-def

borkdude15:10:31

You answered your own question ;)

pez15:10:38

Is clj-kondo parsing that markdown file?

pez15:10:44

When clj-kondo looks for inline defs it must use some kind of definition, I am thinking.

pez15:10:10

But I couldn’t find it on a quick scan of the repo, so I am lazy and ask here. 😃

borkdude15:10:50

The default level of that linter is :warning the docs say

borkdude15:10:06

The default config is in clj_kondo/impl/config.clj

🙏 1
borkdude15:10:23

but this should not matter, the docs should reflect the truth

pez15:10:26

It’s still not what I want. 😃 I suck at expressing myself. I’d like to know how clj-kondo goes about determining that something is an inline def. So if I would write a similar linter myself, I could look at the one you’ve done as inspiration.

borkdude15:10:01

This is intertwined in the analysis if I remember correctly. If you encounter def when you already entered another def or defn then you know it's "inline"

pez15:10:45

Makes sense. Thanks!

borkdude15:10:45

Why are you building your own linter, if I may ask for the context? Just curious

pez15:10:45

I am not. 😃 I just used that as a vehicle to clarify my question. I am suggesting at work that we make the default level for this linter to be :error, and there was worry that we wouldn’t be able to use defs in some contexts that we do today. Now we know that we can just ban them. 😃

borkdude15:10:15

you can use #_:clj-kondo/ignore for the rare cases

pez15:10:13

Ah, good that you reminded me. Then I can use that on the only case there is in our current code base, before I understand if I can remove it.

borkdude15:10:38

usually you want intern I think instead of def for "inline" usage

borkdude15:10:00

or for debugging, I still do it a lot, but then remove it afterwards

pez15:10:23

intern? 👀

borkdude15:10:00

(interns *ns* 'the-var some-value)

borkdude15:10:13

if you want to dynamically define vars

pez15:10:04

What’s the difference from def?

borkdude15:10:16

def is static

borkdude15:10:24

you can not have a variable symbol

borkdude15:10:40

also, def creates the var no matter if you're in a condition or not

borkdude15:10:58

for example: (when false (def x 1)) still creates the var x but it remains uninitialized

pez15:10:55

Oh, interesting! Thanks. Lot’s of TILs for me here. 😃

pez16:10:43

The worry I mentioned above was actually exemplified with a def in a when. Did you guess that? 😃

borkdude16:10:34

I did not :)

lread18:10:49

I’m looking at clj-kondo analysis data while working api-diff PR 🧵

lread18:10:49

if I understand correctly, clj-kondo analysis data includes clj-kondo hard-coded cherry picked metadata of interest only

lread18:10:32

for me, this is probably fine, I am interested in :no-doc which is included.

lread18:10:10

but probably an accident that it is included for ns only (not vars).

lread18:10:13

There is probably a very good reason that clj-kondo analysis data does not simply include all metadata on var/ns, yeah?

borkdude19:10:05

There has been work on an issue to ask for more var metadata, but it stalled.

borkdude19:10:01

Would a function work like {:analysis {:var-meta (fn [m] ...)}} work? Syou can just select the extra metadata you want and this will end up in {:var-definitions [{:name ... :meta ...}]?

borkdude20:10:35

@UE21H2HHD I made a comment here: https://github.com/clj-kondo/clj-kondo/issues/1280 A PR for this is welcome or I'll do it myself since the question has come up a couple of times lately.

lread20:10:34

Yeah, thanks, I think that would work fine.

lread21:10:47

Oh didn’t answer if I am up for this PR. Sure? Maybe? Why not? Yeah, I can give it a go. Unless you’ve already borkduded it!

borkdude21:10:35

not borkduding on this one so go ahead :)

👍 1
pinkfrog20:10:06

I am editing a cljc file, and it seem clj-kondo cannot understand cljs correctly. see picture:

borkdude20:10:58

@i write cljs.core/ExceptionInfo instead

thanks3 1
borkdude20:10:11

You can even leave out cljs.core

leoiacovini21:10:04

Not sure if its something already known (tried lookin into Github but I didn’t found nothing), but I am having some hard time in clj-kondo recognizing conditional reader macros into metadata annotations. Eg:

(def ^{#?@(:clj [:deprecated "deprecation message"])}
  my-deprecated-var
  :bla)
Makes the ns unparsable with the error
missing value for key #?@ (:clj [:deprecated "deprecation message"])
Also using an alternative syntax:
(def ^#?(:clj {:deprecated "deprecation message"})
  my-deprecated-var
  :bla)
Makes the error go away but the metadata doesn’t seem to be preserved for clj-kondo analysis (is does not complain about the var being deprecated)

borkdude21:10:02

So the var is only deprecated in :clj?

borkdude21:10:45

What about:

(def
  #?(:clj ^{:deprecated "reason"} my-deprecated-var
     :cljs my-deprecated-var)
  :bla)

borkdude21:10:07

it's a bit more readable too, I personally think

borkdude21:10:50

but clj-kondo should probably support the other way too, so feel free to make an issue about it

leoiacovini22:10:56

It seems to work with this syntax… However I was facing this from another library I had required in my project, so Ideally would be great to have this fixed without needing to change it in the source. I will open an issue anyway, but thanks for the workaround for now 🙂

borkdude22:10:24

ah that's too bad, yeah, I hope it can get fixed soon