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?
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
I think using {:node (parse-string ...)}
from the utils namespace does the trick
Hum, and they seem to contain different functions as well
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
So now, my last issue is, how do you create a QuoteNode? It doesn't seem that there is a util for that?
My hook needs to rewrite things with a quoted symbol?
If I just use token node, I get: "Unable to resolve symbol" which makes sense, since its supposed to be a quoted symbol
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
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.
Which I think is cause they are parsed differently, 'app
results in a QuoteNode, while (quote app)
result in a ListNode
for quoting i think this might work: https://github.com/sogaiu/libpython-clj/blob/dbb0e36a5211cfbfac9a34c4eb5d973f55d2c61c/resources/clj-kondo.exports/clj-python/libpython-clj/hooks/libpython_clj/require/import_python.clj#L38
That could work, nonetheless we should support this for alias as well
Switching to require worked. I still cut an issue for alias
Thanks, will be fixed.
but may be that's not going to help in your situation
for debugging, i've been copying what @lee did here: https://github.com/lread/rewrite-cljc-playground/blob/09882e1244a8c12879ef8c1e6872724748e7914b/.clj-kondo/hooks/rewrite_cljc/potemkin/import_vars_with_mods.clj#L60-L61 then invoke clj-kondo from the command line
@didibus 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
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.
We could expose a JVM version of the hooks API for testing as well.
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.
That didn't seem to work for alias
But if the require linter works with it... Hum maybe I could rewrite my hook to a require instead of an alias.
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?
upgrade, it's already fixed
ah found the issue, shoulda checked first