Fork me on GitHub
#clj-kondo
<
2021-07-15
>
wdullaer10:07:11

we have a habit of using macros to generate def's in our libraries

wdullaer10:07:31

recently clj-kondo started reporting all of these as unresolved-vars

wdullaer10:07:23

according to this https://github.com/clj-kondo/config/tree/master/hugsql clj-kondo should accept them if you import them from another namespace, but that seems to no longer be true

borkdude10:07:46

you can solve this either with :lint-as {your.cool/macro clojure.core/def} or just disabling that linter. the point of that linter is when you use vars from another namespace that don't exist, you will get a warning.

borkdude10:07:06

that's only true if there are no other vars in that namespace

borkdude10:07:17

you can also :exclude some namespaces in the linter config

wdullaer10:07:40

I'm not entirely sure about the empty namespace: it's complaining about unresolved-vars from a namespace that contains just an s/fdef and the macro that generates all these vars

wdullaer10:07:09

I know I can tell clj-kondo to ignore them, but it's a very common pattern in our codebase, and so keeping the ignore list up to date will be a lot of work

borkdude10:07:42

can you show me an example of such a macro?

wdullaer10:07:39

I've sent a gist in a dm

wdullaer14:07:28

if someone else reads these messages: I've sorted out the problem using a hook that replaces the macro calls with declare/def statements

wdullaer14:07:11

since these calls are in libraries in my case I also had to reindex the cache with clj-kondo --lint "$(lein classpath)"

borkdude14:07:44

yep, that's the way to do it, cool that you made it work

seancorfield20:07:58

Just wanted to mention that this is flagged as "missing :mvn/version, :git/url, or :local/root" although it is legal now in the latest t.d.a:

io.github.cognitect-labs/test-runner {:git/tag "v0.3.1" :git/sha "705ad25"}

borkdude20:07:19

ah is it. then it shall be updated in kondo.

borkdude20:07:21

what is the rule here, if there is a git/sha, what rule should the library symbol have in order for it to be resolved to github/gitlab etc?

Joshua Suskalo20:07:23

it has to conform to ^(com|io)\.(github|gitlab)\..*$ at the moment I think

seancorfield21:07:45

☝️:skin-tone-2: Yup, sounds right. And if it's that format, :git/url can be omitted and the you should have :git/tag AND :git/sha.

Joshua Suskalo21:07:10

need to check the actual tools deps code though, the guide on http://clojure.org only mentions github, not gitlab

borkdude21:07:48

if you only have git/tag will the tool then insert the SHA or...? tags can be a bit volatile

seancorfield21:07:02

(I think there's also some wiggle room in t.d.a right now because I put {:tag ".." :sha ".."} in one deps.edn file and it was perfectly happy with it, to my surprise)

Joshua Suskalo21:07:15

If you have a tag you can have a prefix sha, but if you have no tag you need a full sha

seancorfield21:07:20

Having only :git/tag is not allowed I think.

Joshua Suskalo21:07:28

but you always need a :git/sha key.

borkdude21:07:34

git/tag is more or less for humans, let's say?

Joshua Suskalo21:07:45

Yeah, the only exception to needing the :git/sha with the tag is when installing a tool with -Ttools

seancorfield21:07:46

(or just :sha in the old format)

borkdude21:07:01

is :sha still accepted?

borkdude21:07:26

I will copy paste this into an issue

borkdude21:07:51

for now you can use #_:clj-kondo/ignore to ignore false positives

Joshua Suskalo21:07:06

Like I said somewhere else, I think I want to write a tool for use with -T which allows you to specify only a tag and then it'd use rewrite-clj to add the dep to your deps.edn file with a prefix sha.

❤️ 2
borkdude21:07:38

yeah, that's pretty easy. can just be a small bb script even

Joshua Suskalo21:07:30

Yeah, a bb script would be a good way to package it to run elsewhere, but that is kinda what -T is for on this. Would probably just make it compatible with bb so that it could be run that way if a user wants.

borkdude21:07:19

oh you mean that script could be installed using -T, yeah, that's meta ;)

borkdude21:07:41

Thanks for letting me know.

borkdude21:07:06

If anyone wants to work on this, feel free. I have to write a talk this weekend so I probably won't get to it by then :)

Joshua Suskalo21:07:37

I'd volunteer if my weekend weren't already full

borkdude21:07:48

no worries, it'll be done eventually

seancorfield21:07:55

Logic around what can be in git coords: https://github.com/clojure/tools.deps.alpha/blob/master/src/main/clojure/clojure/tools/deps/alpha/extensions/git.clj#L56-L76 -- :tag and :sha are supported but :git/tag and :git/sha are "preferred" it seems (and you can't have both the qualified and unqualified versions).

seancorfield21:07:00

(and I doubt this is urgent for anyone b/c very few folks are going to be a) running the very latest t.d.a and b) using the new, shorter git coords 🙂 )

👍 2
borkdude21:07:18

makes sense