clj-kondo

https://github.com/clj-kondo/clj-kondo
Helins 2021-05-18T05:26:10.003900Z

Hey! I wrote a macro that does templating like the syntax quote (with ~ and ~@). The idea is very similar to https://github.com/brandonbloom/backtick Kondo struggles with it since it lints the given form like any Clojure code. That would be easily solved if there was a "lint as syntax quote" option. Maybe is there already something resembling that?

borkdude 2021-05-18T12:50:16.004600Z

@adam678 Probably writing a hook for this is your best bet, or suppress warnings inside this macro

borkdude 2021-05-18T12:50:57.005100Z

I have one similar macro like this called $ which is part of babashka.process. clj-kondo has built-in support for that

borkdude 2021-05-18T12:51:09.005400Z

so perhaps you could look at its code

Helins 2021-05-18T13:03:05.007Z

Okay, thanks! Writing those hooks is always a fun puzzle (well, maybe not always)

borkdude 2021-05-18T13:04:01.007700Z

@adam678 In your case, just expanding the body from (your-macro ...) to

`(do ...)
should be sufficient?

borkdude 2021-05-18T13:04:37.008100Z

We could have some :lint-as support for this, but it seems pretty rare

Helins 2021-05-18T13:07:06.009600Z

I'm going to do some experiments now, I believe I should rather traverse the given form and extracts everything enclosed in (clojure.core/unquote ...) and (clojure.core/unquote-splicing ...)

Helins 2021-05-18T13:07:57.010300Z

What's encapsulated in those will always be valid Clojure, whereas everything outside is actually Convex Lisp in my case

Helins 2021-05-18T14:24:49.011300Z

Is there a way for interacting with QuoteNode ? Any node manipulation must happen via the hook api, right?

borkdude 2021-05-18T14:27:52.012700Z

hmm, good point, there is probably no way to generate a syntax-quote, but a normal quoted one can be generated using (list-node (list* (token-node 'quote) ...))

Helins 2021-05-18T14:39:53.014300Z

I think I can manage, with a little indirection. It's more about recognizing literal unquoting (combination between returning false on list-node? and guessing unquote and unquote-splicing from the sexpr).

Helins 2021-05-18T14:40:08.014700Z

Is there an obvious reason why you removed support for map nodes?

borkdude 2021-05-18T14:42:59.015100Z

yeah, the rewrite-clj around map-nodes and namespaced-map-nodes wasn't stable yet

👍 1