clj-kondo

https://github.com/clj-kondo/clj-kondo
levitanong 2021-01-05T09:51:40.223900Z

Hallo! I'm playing around with the :hooks feature of clj-kondo, and I'd like to use clojure spec to use s/cat to easily parse the macro form, but SCI says it couldn't find clojure spec. Is there some extra step I need to take to get spec in there, or is it simply unsupported by SCI?

borkdude 2021-01-05T09:56:59.224300Z

clojure spec isn't currently supported in clj-kondo hooks

borkdude 2021-01-05T10:24:42.224900Z

Would adding a .gitignore file automatically in the .clj-kondo directory be a bad idea? To ignore the .cache: https://github.com/clj-kondo/clj-kondo/issues/1113

borkdude 2021-01-05T10:26:06.226300Z

@levitanong Note that spec is still alpha, so even if I would add spec, I would not be comfortable with adding spec1 or spec2 in this stage. Another issue is that hooks usually return transformed nodes. Spec would probably only be useful for generating warnings based on the sexprs, not transformation, but maybe it can be used in that way too, not sure.

levitanong 2021-01-05T10:45:22.226900Z

Ah, my intent is to make a hook for ghostwheel's >defn, which is basically just defn with something extra. Manually manipulating the form is quite a hassle since defn can take many forms, but s/conform can make it manageable with s/cat and stuff like s/? and s/*. But, it's not supported, so c'est la vie! I will manage 🙂

borkdude 2021-01-05T10:47:19.227600Z

Also feel welcome to contribute your hook back to the config repo

levitanong 2021-01-05T10:54:54.227800Z

Thanks for the tip! Another question: Where is hooks-api defined? I can't find it so far in the repository. 😮

levitanong 2021-01-05T10:55:00.228Z

re: contrib, i'll do my best!

borkdude 2021-01-05T10:57:00.228200Z

The API is documented here: https://github.com/clj-kondo/clj-kondo/blob/master/doc/hooks.md#api The code is here: https://github.com/clj-kondo/clj-kondo/blob/master/src/clj_kondo/impl/hooks.clj But note that anything that is not documented, should be considered implementation detail and might change or be removed.

levitanong 2021-01-05T10:58:29.228900Z

I was looking at that clj file, but it didn't match the require statement, so I assumed it was somewhere else 😮 Is some other process involved in exposing this file as a different namespace on execution?

borkdude 2021-01-05T10:59:03.229100Z

@levitanong Yes, the hooks are interpreted using sci: https://github.com/borkdude/sci

levitanong 2021-01-05T10:59:25.229500Z

Oh okay, I get it now! I see the sci/init call

levitanong 2021-01-05T10:59:34.229700Z

Thanks! I think this is enough for me to get going.

levitanong 2021-01-05T17:06:51.229900Z

I just realized there isn't much point in making a hook for ghostwheel because >defn is actually compatible with defn. so I can just use lint-as. I originally also wanted to use spec to use spec to immediately validate the form (i.e. making ghostwheel do its job statically) but that's not possible, so 🤷 😂

levitanong 2021-01-05T17:07:28.230100Z

it's a good learning experience though!

borkdude 2021-01-05T17:08:48.230300Z

Cool :)

borkdude 2021-01-05T17:09:17.230500Z

@levitanong You might be interested in this: https://github.com/clj-kondo/inspector

borkdude 2021-01-05T17:09:40.230900Z

It's a bit experimental, but if you want to play with it

levitanong 2021-01-05T17:17:10.231100Z

Going through the readme, pretty cool! Is it compatible with clojurescript though? tried it of the cuff, but i'm getting a required namespace not available error, even after adding "configs/inspector" to my :config-paths

borkdude 2021-01-05T17:18:44.231300Z

@levitanong hmm, no, it currently only works on the JVM, but I think a .cljs version could be made

borkdude 2021-01-05T17:19:00.231500Z

as long as it spits out the correct data

levitanong 2021-01-05T17:19:36.231700Z

ah, alas. I'm currently working on a cljs project right now. I do have a clj project that i'll work on over the weekend, so i'll definitely try inspector on that!