Fork me on GitHub
#clj-kondo
<
2021-05-18
>
Adam Helins05:05:10

Hey! I wrote a macro that does templating like the syntax quote (with ~ and [email protected]). 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?

borkdude12:05:16

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

borkdude12:05:57

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

borkdude12:05:09

so perhaps you could look at its code

Adam Helins13:05:05

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

borkdude13:05:01

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

`(do ...)
should be sufficient?

borkdude13:05:37

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

Adam Helins13:05:06

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

Adam Helins13:05:57

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

Adam Helins14:05:49

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

borkdude14:05:52

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

Adam Helins14:05:53

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

Adam Helins14:05:08

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

borkdude14:05:59

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

👍 3