Fork me on GitHub
#clj-kondo
<
2023-12-11
>
Alexander Kouznetsov20:12:51

Is it possible in a clj-kondo hook to instruct clj-kondo that a macro parameter is expected to have a certain type?

borkdude20:12:54

you can use a hook to check the type of the input and then emit a warning if it doesn't conform

borkdude20:12:27

also it is possible to declare types for your macro or function arguments using this: https://github.com/clj-kondo/clj-kondo/blob/master/doc/types.md

Alexander Kouznetsov20:12:22

> you can use a hook to check the type of the input and then emit a warning if it doesn’t conform Nice, but this wouldn’t work if the macro receives a variable or an expression. > also it is possible to declare types for your macro or function arguments using this This is cool, I’ll try this.

borkdude20:12:23

Macro arguments are never evaluated so whatever you pass as a form, that is the type

Alexander Kouznetsov20:12:18

Exactly, but I’ve seen clj-kondo being able to hint something like

(def x 5)
(format x)
Expected: string, received: positive integer. for the 2nd line while the macro would only see a symbol.

borkdude20:12:11

format is not a macro

Alexander Kouznetsov20:12:55

What if it was? I. e. is there no linting on macro arguments similar to how it is done for functions?

borkdude20:12:39

there is currently no difference in checking types for functions or macros

👍 1