Fork me on GitHub
#clj-kondo
<
2021-01-05
>
levitanong09:01:40

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?

borkdude09:01:59

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

borkdude10:01:42

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

borkdude10:01:06

@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.

levitanong10:01:22

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 🙂

borkdude10:01:19

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

levitanong10:01:54

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

levitanong10:01:00

re: contrib, i'll do my best!

borkdude10:01:00

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.

levitanong10:01:29

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?

borkdude10:01:03

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

levitanong10:01:25

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

levitanong10:01:34

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

levitanong17:01:51

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 🤷 😂

levitanong17:01:28

it's a good learning experience though!

borkdude17:01:40

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

levitanong17:01:10

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

borkdude17:01:44

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

borkdude17:01:00

as long as it spits out the correct data

levitanong17:01:36

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!