clj-kondo

https://github.com/clj-kondo/clj-kondo
2020-11-19T02:02:35.466200Z

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?

2020-11-19T02:03:59.466800Z

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

2020-11-19T02:19:02.466900Z

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

2020-11-19T02:22:18.467400Z

Hum, and they seem to contain different functions as well

2020-11-19T04:39:36.468100Z

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

2020-11-19T04:39:56.468600Z

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

2020-11-19T04:40:16.468900Z

My hook needs to rewrite things with a quoted symbol?

2020-11-19T04:40:45.469500Z

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

2020-11-19T04:57:13.470600Z

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

borkdude 2020-11-19T10:05:40.473600Z

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.

👍 1
2020-11-19T20:01:04.474900Z

Done: https://github.com/borkdude/clj-kondo/issues/1074

2020-11-19T04:58:53.471300Z

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

borkdude 2020-11-19T10:06:03.473800Z

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

2020-11-19T22:04:54.475700Z

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

borkdude 2020-11-19T22:06:07.475900Z

Thanks, will be fixed.

🎉 1
2020-11-19T06:03:13.472200Z

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

2020-11-19T06:04:20.472800Z

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

borkdude 2020-11-19T10:06:44.474Z

@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

2020-11-19T19:50:23.474600Z

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.

borkdude 2020-11-19T20:09:22.475200Z

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

2020-11-19T20:15:47.475400Z

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.

2020-11-19T07:14:56.473100Z

That didn't seem to work for alias

2020-11-19T07:15:29.473300Z

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

adambros 2020-11-19T23:03:04.476600Z

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?

borkdude 2020-11-19T23:04:11.477200Z

upgrade, it's already fixed

👍 1
adambros 2020-11-19T23:04:17.477400Z

ah found the issue, shoulda checked first