Fork me on GitHub
#clj-kondo
<
2021-08-18
>
ericdallo15:08:02

How can I run clj-kondo in a lein alias to lint the depedencies of my project? 🧵

ericdallo15:08:15

I tried something like this:

"clj-kondo-deps"  ["run" "-m" "clj-kondo.main" "--copy-configs" "--dependencies" "--config" ".clj-kondo/config.edn" "--lint" ~#(clojure.string/join ":" (leiningen.core.classpath/get-classpath %))]
            "clj-kondo"       ["do" ["clj-kondo-deps"] ["run" "-m" "clj-kondo.main" "--config" ".clj-kondo/config.edn" "--lint" "src" "test"]]

borkdude15:08:34

this is documented in the README of clj-kondo

ericdallo15:08:37

then lein clj-kondo would first lint the classpath and then the project

borkdude15:08:59

you have to use --lint $(lein classpath)

ericdallo15:08:07

the docs only say running from cli, not from lein aliases

borkdude15:08:23

right, I'm not sure, haven't used it that way yet

borkdude15:08:49

I think that would have to run as a lein plugin then

ericdallo15:08:55

yeah, $(lein classpath) inside lein project.clj would fall into a infinte loop hehe

ericdallo15:08:07

yeah that's what I thought, is there any clj-kondo lein plugin?

borkdude15:08:16

don't think so

😿 3
borkdude15:08:20

haven't you made such a plugin for clojure-lsp?

ericdallo15:08:26

I tried ~#(clojure.string/join ":" (leiningen.core.classpath/get-classpath %)) that lein would eval that, but it returns a function not a string

borkdude15:08:46

try #=(....)

ericdallo15:08:58

oh, didn't know about that one, let me try

ericdallo15:08:29

doesn't seems to work 😕

borkdude15:08:59

but why not implement a proper plugin? why do you need this?

ericdallo15:08:31

a plugin would solve the issue

ericdallo15:08:10

because at nubank we have this lein clj-kondo alias for all services, but it's missing lint the classpath before to copy the configs and dependencies to cache

borkdude15:08:51

cool. we could host the plugin under the clj-kondo organization

borkdude15:08:00

and I'll give you the access so you can push there if you want

borkdude15:08:40

what should the name of the repo be, lein-plugin?

ericdallo15:08:57

I'd suggest lein-clj-kondo

ericdallo15:08:07

thanks, I'll work to have something similar to clojure-lsp lein plugin

ericdallo16:08:29

Do you think the plugin should call clj-kondo.core/run! or clj-kondo.main/main ? if the former, the api for the plugin would look something like:

lein clj-kondo "{:lint "src" ...}"
this would need almost none maintaince to the plugin as it'll be really simple just calling the kondo api, but a less friendly user UX the other one, would looks:
lein clj-kondo --lint src 
but I'm not sure how the lint classpath would work :thinking_face:

ericdallo16:08:32

actually, I'm not sure how we would solve the classpath issue in the plugin

ericdallo16:08:59

oh, actually it's easy, it's just call lein classpath ns

ericdallo16:08:49

we just need probably to parse a specific flag to know we should get the classpath

ericdallo16:08:03

so maybe use the clj-kondo.main/main seems the best approach

ericdallo16:08:29

just adding a interceptor layer to check if the arg to lint is a "$classpath" or something like that

borkdude16:08:31

do people normally configure lein plugins in EDN?

ericdallo16:08:56

I don't think so

ericdallo16:08:33

Just pushed a working version to master, LMK if you think we should change anything

ericdallo16:08:54

otherwsie we can release a initial version with make tag 0.1.0

ericdallo16:08:06

(we can change the release process as you want as well)

ericdallo16:08:42

also, the artifact is clj-kondo/lein-clj-kondo , not sure if that group-id is correct though

borkdude17:08:51

I would prefer it if you used babashka tasks instead of Make ;)

ericdallo17:08:11

haha I thought you would say that

ericdallo17:08:15

yeah, I can change it 🙂

ericdallo17:08:32

how do you think the release task would look?

borkdude17:08:43

I'll get back to you after dinner

👍 3
ericdallo17:08:56

Done! looks better indeed, babashka rocks

ericdallo17:08:59

LMK what you think

ericdallo18:08:37

yep, fixing ...

borkdude18:08:50

here is an example repo of clj-commons: https://github.com/clj-commons/infra it uses a bb script as well to push a tag

borkdude18:08:15

but I think you already have everything you need

borkdude18:08:20

so what's next?

ericdallo18:08:58

oh good to know

ericdallo18:08:10

if everything looks fine we can bb tag 0.1.0

ericdallo18:08:14

and then bb deploy

ericdallo18:08:30

the last one would need clojars credentials, so I think you need to do this

ericdallo18:08:03

BTW, can you confirm if you have a verified group of clj-kondo on clojars?

ericdallo18:08:58

since clj-kondo is a little bit old project, the group restriction was not need in the time for clojars

borkdude18:08:06

I have the group, but even if you have the group, you can't push any new projects to it

borkdude18:08:19

only existing ones

borkdude18:08:32

so I'll make a new one ok

ericdallo18:08:36

I just saw it:

borkdude18:08:38

with the com.github

ericdallo18:08:49

yeah, we need to update project.clj so

borkdude18:08:20

oh crap, this is linked to github accounts right

borkdude18:08:27

so we have to go through some process?

ericdallo18:08:31

yeah hahah you will need to open an PR

ericdallo18:08:54

we need to open that issue but first create the repo or the name of who is opening the issue

borkdude18:08:53

let's wait for them to respond

ericdallo18:08:33

Perfect, thank you!

borkdude18:08:26

So what is interesting about the clj-commons infra setup is that you can push a tag

borkdude18:08:30

and then the CI will deploy

borkdude18:08:39

so we need only one deploy token for whoever can push the tag

borkdude18:08:43

which lives in CI

borkdude18:08:48

perhaps we can set that up?

ericdallo18:08:06

yeah, I have that for clojure-lsp

ericdallo18:08:18

do you have a example of a project using the clj-commons infra ?

borkdude18:08:25

yeah lemme check

borkdude18:08:47

this doesn't use infra but it responds to the tag change: https://github.com/clj-commons/clj-yaml

ericdallo18:08:56

yeah, that could work

ericdallo18:08:26

but what function from infra we want to use to deploy to clojars?

borkdude18:08:57

we can just run lein deploy clojars

ericdallo18:08:17

oh, ok, and setup the clojars credentials using github secrets, right?

ericdallo18:08:25

(that's how I do for clojure-lsp)

borkdude18:08:32

yes, or circleci secrets

borkdude18:08:48

if your clojure-lsp setup works you can just re-use that as well

ericdallo18:08:10

👍 alright, I'll work to do the deploy on CI instead of manually

ericdallo19:08:50

Just pushed, it uses this action I use on clojure-lsp as well to deploy t oclojars: https://github.com/marketplace/actions/publish-to-clojars so it's a really simple action

ericdallo19:08:07

we just need to setup those 2 secrets on the clj-kondo org or on lein-clj-kondo repositoy

ericdallo19:08:18

CLOJARS_USERNAME
CLOJARS_PASSWORD

borkdude19:08:57

ok, I will do that, once I get the group

borkdude19:08:07

chicken and egg, I can't make a token without the group

ericdallo19:08:58

I can't access the public created repository: https://github.com/clj-kondo/clojars-verification-borkdude :thinking_face:

ericdallo19:08:07

Is that really public?

borkdude20:08:09

a sorry, made it public

👍 3
ericdallo13:08:03

The group was verified, LMK when the secrets on Github were configured properly so I (or you) can release the tag

borkdude13:08:15

yes, I'm seeing it.

borkdude13:08:47

I'm looking into how I can make a deploy token for this new group

borkdude13:08:58

I don't see the group in the list for making a deploy token, I'll ask toby