Fork me on GitHub
#clj-kondo
<
2020-11-19
>
didibus02:11:35

Is there a way when I write my hook I can test it at the REPL? Like can I call api/something clojure-code-to-lint which will parse the clojure-code-to-lint and call my hook with the rewrite-clj node for it?

didibus02:11:02

I think using {:node (parse-string ...)} from the utils namespace does the trick

didibus02:11:59

Also, I'm only seeing a clj-kondo.impl.hooks in the Jar, but the doc says my hook needs to require clj-kondo.hooks-api

didibus02:11:18

Hum, and they seem to contain different functions as well

didibus04:11:36

Ok, so it seems in the Jar clj-kondo.impl.utils is the same as clj-kondo.hooks-api inside sci when acutally running through clj-kondo

didibus04:11:56

So now, my last issue is, how do you create a QuoteNode? It doesn't seem that there is a util for that?

didibus04:11:16

My hook needs to rewrite things with a quoted symbol?

didibus04:11:45

If I just use token node, I get: "Unable to resolve symbol" which makes sense, since its supposed to be a quoted symbol

didibus04:11:13

I tried to use list-node with quote but it doesn't help me, because this:

(do (alias (quote app) (quote app)))

::app/db
Doesn't lint, it seems the alias linter doesn't work if using (quote app) instead of 'app

borkdude10:11:40

We should support that in clj-kondo. Please post an issue, I will mark it as high priority and pick it up before next release.

👍 3
didibus04:11:53

Which I think is cause they are parsed differently, 'app results in a QuoteNode, while (quote app) result in a ListNode

didibus07:11:56

That didn't seem to work for alias

didibus07:11:29

But if the require linter works with it... Hum maybe I could rewrite my hook to a require instead of an alias.

borkdude10:11:03

That could work, nonetheless we should support this for alias as well

didibus22:11:54

Switching to require worked. I still cut an issue for alias

borkdude22:11:07

Thanks, will be fixed.

🎉 3
sogaiu06:11:13

but may be that's not going to help in your situation

borkdude10:11:44

@U0K064KQV Yes, prn/println is good for debugging. For running actual tests, I recommend just linting source with the hook and write tests based on the linter results

didibus19:11:23

I found I can just swap the require for the clj-kondo.impl.utils namespace at the REPL, and call my hook with parse-string wrapped in a {:node} map and it works. As long I make sure I don't use anything in utils that sci doesn't include in api.

borkdude20:11:22

We could expose a JVM version of the hooks API for testing as well.

didibus20:11:47

I think that be useful. It wasn't too hard for me to swap the namespace require back and forth, but still a bit annoying. Also, could be nice to have a parse-for-hook util or something. Which does: ({:node (parse-string string-form)}) or something similar. Though again, it wasn't very hard for me to just wrap parse-string in it.

adambrosio23:11:04

if i have an empty (or) i get this error at the ns decl Wrong number of args (0) passed to: clj-kondo.impl.types.utils/union-type is this known about and i just need to upgrade?

borkdude23:11:11

upgrade, it's already fixed

👍 3
adambrosio23:11:17

ah found the issue, shoulda checked first