Fork me on GitHub
#clj-kondo
<
2020-06-22
>
adam00:06:18

Can clj-kondo reorder my imports alphabetically?

seancorfield00:06:28

@somedude314 A linter isn't a rewriter. I think there are some existing tools out there that will do certain types of rewriting.

seancorfield00:06:51

(but I don't like tools touching my code -- I just want them to tell me what needs fixing)

adam00:06:23

I am so used to gofmt and black, isort & autoflake combo for Python. Wish there was something similar for Clojure. For now I am using cljfmt but it seems to only handle indentation and is too afraid to arrange the code.

seancorfield01:06:54

@somedude314 There was a Leiningen plugin that used to reorder ns clauses. I don't remember the name of it, sorry.

seancorfield01:06:40

I get the impression most Clojurians prefer their tools to be kept simple and to avoid things that rewrite code in any substantial way...

seancorfield01:06:14

(last updated nearly four years ago)

adam01:06:36

This looks interesting - https://github.com/immoh/lein-nsorg. I will give them a try soon and report back. Thanks for the pointers.

borkdude06:06:23

@somedude314 I have an example of re-ordering imports using a babashka script using the parcera pod: https://github.com/babashka/pod-babashka-parcera#sort-requires

borkdude09:06:46

In emacs I use clojure-sort-ns for this

adam13:06:57

Thanks will look into those

lread19:06:47

Ok, cool! I wrote my first clj-kondo hook! I went a bit heavy on the comments on the hook, thinking they might be helpful to others as this is a new feature. https://github.com/lread/rewrite-cljc-playground/commit/09882e1244a8c12879ef8c1e6872724748e7914b

lread19:06:21

I’m sure @borkdude will let me know if some changes might make sense simple_smile

borkdude19:06:04

I'm getting an error about Github's IP... 😕

borkdude19:06:47

Maybe someone can give me the IP of Github?

lread19:06:17

Maybe you need to reboot computer/router/modem?

lread19:06:25

ping -c 2 
PING  (140.82.112.3): 56 data bytes
64 bytes from 140.82.112.3: icmp_seq=0 ttl=50 time=49.478 ms
64 bytes from 140.82.112.3: icmp_seq=1 ttl=50 time=40.860 ms

borkdude19:06:51

doesn't work for me, it will redirect the browser to http://github.com. I've never had this before

lread19:06:29

I have, a reboot of my modem and router (and maybe computer?) fixed it for me.

borkdude19:06:27

switching to 1.1.1.1 as dns server worked

borkdude19:06:59

@lee Cool! So if I understand correctly, you're generating a series of (def foo fully-qualified.bar)s in a do right?

lread19:06:51

yes, that’s right

lread19:06:31

I guess I could have looked at what you coded up to support potemkin import-vars… but did not think of it.

borkdude19:06:50

That's fine 🙂 One thing that might be of interest: have you measure performance by linting the calls to your modified import-vars? E.g. by pasting 10000 of them in a file

borkdude19:06:56

or 1000, I don't know

borkdude19:06:57

I think using (cons 'do (map ....)) is more performant than (conj (for ...) 'do) , but there's only one way to find out

borkdude19:06:28

the reason is that for generates a bunch of extra stuff, maybe it doesn't matter

borkdude19:06:26

I'm happy you figured it out!

lread19:06:37

for my little purposes it seems to run just speedily! but am happy to do perf tests if it would be useful to clj-kondo.

borkdude19:06:14

well, you are the one that's going to use the hook, so if you are satisfied, it's fine. 🙂

lread19:06:19

Ya, I’m good for now with performance. Thanks for yet another linting power! It did not take me terribly long to figure out. Some familiarity with rewrite-clj and a good amount print debugging helped!

borkdude19:06:12

Once this library is published, you can post your config to https://github.com/borkdude/clj-kondo/tree/master/libraries

borkdude19:06:21

or isn't this thing a public API?

lread19:06:57

It is an internal macro that exposes a public API.

lread19:06:40

Soo… how does that fit in? simple_smile

lread19:06:16

So folks won’t be using the internal macro but will be using the public API it exposes.

borkdude19:06:16

well, that's not something that's going to affect linting of end user programs then

lread19:06:33

Yeah, makes sense.

lread19:06:38

I’m a big foggy and rusty though… will clj-kondo be able to warn on incorrect calls to rewrite-cljc’s public API if rewrite-cljc exposes that API through internal import-vars trickery?

borkdude19:06:16

@lee Not right now, I think. Let me try.

lread19:06:43

Good idea, hope it helps others.

borkdude19:06:53

So no:

(defn foo [x])

(def f foo)

(f 1 2 )

borkdude19:06:10

but that could be fixed. If you expand to potemkin's macro, it does work

borkdude19:06:28

I'd rather fix it in clj-kondo though, much nicer

borkdude19:06:12

I'll bump it.

borkdude20:06:24

I remember that we discussed this macro roughly a year ago, I was in Leuven at Heart of Clojure then 🙂

lread20:06:57

ah… sweet memories!

lread20:06:03

clj-kondo was just a wee baby back then!