Can clj-kondo reorder my imports alphabetically?
@somedude314 A linter isn't a rewriter. I think there are some existing tools out there that will do certain types of rewriting.
(but I don't like tools touching my code -- I just want them to tell me what needs fixing)
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.
@qythium, I dug a bit, here’s where the clj-kondo.hooks-api
is exposed https://github.com/borkdude/clj-kondo/blob/3531b80a3473177e0b5941c443f921d57f70f0c8/src/clj_kondo/impl/hooks.clj#L64
@somedude314 There was a Leiningen plugin that used to reorder ns
clauses. I don't remember the name of it, sorry.
I get the impression most Clojurians prefer their tools to be kept simple and to avoid things that rewrite code in any substantial way...
https://github.com/technomancy/slamhound -- that's what I was thinking of @somedude314
(last updated nearly four years ago)
This looks interesting - https://github.com/immoh/lein-nsorg. I will give them a try soon and report back. Thanks for the pointers.
@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
In emacs I use clojure-sort-ns
for this
Thanks will look into those
At this time libraries don’t export config. Users have to add it manually
@qythium I added some documentation for the API here now: https://github.com/borkdude/clj-kondo/blob/master/doc/config.md#api
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
I’m sure @borkdude will let me know if some changes might make sense :simple_smile:
I'm getting an error about Github's IP... 😕
Maybe someone can give me the IP of Github?
Maybe you need to reboot computer/router/modem?
ping -c 2 <http://github.com|github.com>
PING <http://github.com|github.com> (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
doesn't work for me, it will redirect the browser to http://github.com. I've never had this before
I have, a reboot of my modem and router (and maybe computer?) fixed it for me.
switching to 1.1.1.1 as dns server worked
@lee Cool! So if I understand correctly, you're generating a series of (def foo fully-qualified.bar)
s in a do right?
yes, that’s right
I guess I could have looked at what you coded up to support potemkin import-vars… but did not think of it.
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
or 1000, I don't know
I think using (cons 'do (map ....))
is more performant than (conj (for ...) 'do)
, but there's only one way to find out
the reason is that for
generates a bunch of extra stuff, maybe it doesn't matter
I'm happy you figured it out!
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.
well, you are the one that's going to use the hook, so if you are satisfied, it's fine. 🙂
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!
😄
Once this library is published, you can post your config to https://github.com/borkdude/clj-kondo/tree/master/libraries
or isn't this thing a public API?
It is an internal macro that exposes a public API.
Soo… how does that fit in? :simple_smile:
So folks won’t be using the internal macro but will be using the public API it exposes.
well, that's not something that's going to affect linting of end user programs then
Yeah, makes sense.
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?
Added your example here for now: https://github.com/borkdude/clj-kondo/blob/master/doc/config.md#examples
@lee Not right now, I think. Let me try.
Good idea, hope it helps others.
So no:
(defn foo [x])
(def f foo)
(f 1 2 )
but that could be fixed. If you expand to potemkin's macro, it does work
I'd rather fix it in clj-kondo though, much nicer
it's this issue: https://github.com/borkdude/clj-kondo/issues/412
I'll bump it.
cool!
I remember that we discussed this macro roughly a year ago, I was in Leuven at Heart of Clojure then 🙂
ah… sweet memories!
clj-kondo was just a wee baby back then!