Fork me on GitHub
#clj-kondo
<
2021-07-28
>
borkdude09:07:25

@ps @jimka.issy @dave et al, I have merged the macroexpand feature to master and wrote some docs in the issue here: https://github.com/clj-kondo/clj-kondo/issues/1327#issue-952124466

😁 5
dave13:07:26

I just tried it with the latest clojure-lsp, and it works like a charm. Fantastic work! 💯

👍 2
borkdude10:07:07

ah well, I guess I will just release this and then gather some feedback until the next release

martinklepsch10:07:22

clj-kondo produces a duplicate require warning for a babashka script, is that intended?

borkdude10:07:35

@martinklepsch can you post that code here?

borkdude10:07:44

I can try locally, if you post the code

borkdude10:07:15

I'm about to release clj-kondo, so be fast @martinklepsch

martinklepsch10:07:27

Actually I now ran clj-kondo from the CLI and it didn’t complain so I think it’s probably an issue with the action (old version I guess?)

borkdude11:07:27

Just released a new version of clj-kondo with the new macroexpansion feature; https://clojurians.slack.com/archives/C06MAR553/p1627470400150500

Noah Bogart13:07:17

set up: i have a macro game.macros/req, and i’m using potemkin to import-export it into game.core. It’s anaphoric, so defines a bunch of vars in a let that are available to the code it wraps: (req (+ (:credits corp) 5)) works because corp is defined by req. in my .clj-kondo/config.edn, i have {:linters {:unresolved-symbol {:exclude [(game.macros/req [corp ...])] so as to ignore those symbols. if I use (:require [game.macros :refer [req]]), the linters work correctly. however, if I put in my config.edn {:lint-as {game.core/req game.macros/req}} , and change the require to be (:require [game.core :refer [req]), all of the req calls are flagged as using undefined symbols

Noah Bogart13:07:33

short version: how do I make :lint-as work? it seems that :lint-as doesn’t check the :linters rules when determining how to lint as another macro

borkdude13:07:54

@nbtheduke Can you post an issue + repro about this?

Noah Bogart15:07:39

i’ll see what I can do about a repro, the project this is happening in is pretty big

borkdude15:07:55

I think the main issue is that unresolved-symbol doesn't look at lint-as first or so

borkdude15:07:09

but repro would be nice to have this confirmed.

👍 3
borkdude13:07:58

A workaround for now might be to duplicate the unresolved symbol config

vemv15:07:18

I gave a read to https://github.com/clj-kondo/clj-kondo/blob/master/doc/hooks.md#macroexpand I'm curious, is clj-kondo macroexpanding arbitrary macros now? (would be happy about that) Any limitations or nuances?

borkdude15:07:46

The limitations and nuances are hopefully documented in that readme

borkdude15:07:17

It doesn't directly execute them from source

borkdude15:07:27

but you can "copy" them over to the config dir and hook them up

borkdude15:07:37

and then most of the time they should work, or might require some modifications

vemv15:07:13

ok that was what I was asking, i.e. is everything macroexpanded or only when integrated with the hook feature

borkdude15:07:20

yes, only then

vemv15:07:59

would be out of the question to macroexpand everything? A few of us use clj-kondo in CI, sometimes with vanilla jvm clojure

borkdude15:07:04

executing all macros isn't possible since some of them do things at runtime other than a pure transformation

vemv15:07:42

let's say opt-in, for those of us willing to make the tradeoff

borkdude15:07:43

well, even then it might fail in some cases. I think the new feature should get some more exposure first before taking that next step

borkdude15:07:56

one could also think of some rewrite-clj script that automatically copies some macros to the config

vemv15:07:24

thanks for considering it, let's see how it goes over time

borkdude15:07:02

the new feature should be considered as an "easy" trade-off to the more reliable :analyze-call feature at the cost of less precise location info in lint warnings

👍 3
borkdude15:07:45

for people who don't want to take the time to deal with :analyze-call, or find it daunting

borkdude15:07:57

I'm sure some people will come up with clever hacks to copy their macros soon ;)

borkdude15:07:07

I think the ingredients are there to do so with rewrite-clj and rewrite-edn

borkdude15:07:19

both can run in bb, so you could have fast scripts that do so too

borkdude15:07:15

eventually clj-kondo may support it out of the box, but it may also be a little bit of a rabbit hole to have to support it perfectly, so let's see what happens next

borkdude21:07:48

@dpassen1 There is an open issue for this

👍 3
Derek21:07:02

of course there is

borkdude21:07:12

Feel free to take it on ;)

Derek21:07:53

I just might

borkdude21:07:13

I think it's a good "first issue" as it's relatively isolated and relatively easy to understand

borkdude21:07:44

and there are tests, so if you break something, you'll probably notice

Derek22:07:17

Put up a draft PR