clj-kondo

https://github.com/clj-kondo/clj-kondo
adam 2020-06-22T00:22:18.483400Z

Can clj-kondo reorder my imports alphabetically?

seancorfield 2020-06-22T00:29:28.484600Z

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

seancorfield 2020-06-22T00:29:51.485100Z

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

adam 2020-06-22T00:34:23.487400Z

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.

lread 2020-06-22T00:44:28.488600Z

@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

seancorfield 2020-06-22T01:08:54.489500Z

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

seancorfield 2020-06-22T01:09:40.490300Z

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

seancorfield 2020-06-22T01:11:45.490700Z

https://github.com/technomancy/slamhound -- that's what I was thinking of @somedude314

seancorfield 2020-06-22T01:12:14.491100Z

(last updated nearly four years ago)

adam 2020-06-22T01:13:36.492100Z

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

borkdude 2020-06-22T06:57:23.494100Z

@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

borkdude 2020-06-22T09:39:46.496100Z

In emacs I use clojure-sort-ns for this

adam 2020-06-22T13:38:57.496300Z

Thanks will look into those

borkdude 2020-06-22T06:58:24.494900Z

At this time libraries don’t export config. Users have to add it manually

borkdude 2020-06-22T09:35:32.495500Z

@qythium I added some documentation for the API here now: https://github.com/borkdude/clj-kondo/blob/master/doc/config.md#api

👍 1
lread 2020-06-22T19:03:47.497800Z

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

lread 2020-06-22T19:13:21.499Z

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

borkdude 2020-06-22T19:14:04.499300Z

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

borkdude 2020-06-22T19:14:47.499800Z

Maybe someone can give me the IP of Github?

lread 2020-06-22T19:16:17.000200Z

Maybe you need to reboot computer/router/modem?

lread 2020-06-22T19:16:25.000500Z

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

borkdude 2020-06-22T19:18:51.000900Z

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

lread 2020-06-22T19:19:29.001500Z

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

borkdude 2020-06-22T19:23:27.002700Z

switching to 1.1.1.1 as dns server worked

borkdude 2020-06-22T19:27:59.003300Z

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

lread 2020-06-22T19:28:51.003700Z

yes, that’s right

lread 2020-06-22T19:29:31.004300Z

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

borkdude 2020-06-22T19:30:50.005Z

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

borkdude 2020-06-22T19:30:56.005200Z

or 1000, I don't know

borkdude 2020-06-22T19:31:57.006200Z

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

borkdude 2020-06-22T19:32:28.006800Z

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

borkdude 2020-06-22T19:33:26.007800Z

I'm happy you figured it out!

lread 2020-06-22T19:33:37.008Z

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.

borkdude 2020-06-22T19:34:14.009100Z

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

lread 2020-06-22T19:36:19.011200Z

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!

borkdude 2020-06-22T19:36:39.011400Z

😄

borkdude 2020-06-22T19:37:12.011800Z

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

borkdude 2020-06-22T19:38:21.012900Z

or isn't this thing a public API?

lread 2020-06-22T19:38:57.013600Z

It is an internal macro that exposes a public API.

lread 2020-06-22T19:39:40.014200Z

Soo… how does that fit in? :simple_smile:

lread 2020-06-22T19:40:16.014900Z

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

borkdude 2020-06-22T19:40:16.015Z

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

lread 2020-06-22T19:41:33.015400Z

Yeah, makes sense.

lread 2020-06-22T19:47:38.018800Z

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?

borkdude 2020-06-22T19:49:36.019100Z

Added your example here for now: https://github.com/borkdude/clj-kondo/blob/master/doc/config.md#examples

borkdude 2020-06-22T19:50:16.019700Z

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

lread 2020-06-22T19:50:43.020200Z

Good idea, hope it helps others.

borkdude 2020-06-22T19:50:53.020400Z

So no:

(defn foo [x])

(def f foo)

(f 1 2 )

borkdude 2020-06-22T19:51:10.020900Z

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

borkdude 2020-06-22T19:51:28.021200Z

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

borkdude 2020-06-22T19:52:08.021400Z

it's this issue: https://github.com/borkdude/clj-kondo/issues/412

borkdude 2020-06-22T19:52:12.021700Z

I'll bump it.

lread 2020-06-22T19:52:40.022Z

cool!

borkdude 2020-06-22T20:00:24.022400Z

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

lread 2020-06-22T20:00:57.022800Z

ah… sweet memories!

lread 2020-06-22T20:02:03.023500Z

clj-kondo was just a wee baby back then!