Fork me on GitHub

Good morning. I'm wondering what's the best way to make clj-kondo work with macro-generated defs that come from static resources. Concrete example: we have a directory full of SVG icons, and each icon file gets turned into a var via a macro. Obviously when connected via the REPL, this works as expected and you also get completions. But clj-kondo rightfully complains as those vars don't appear in the source.


The custom macroexpansion is an obvious place to try, but then it's mostly duplicating the code plus you'd need access to the classpath to locate the directory which contains the files.


In this case I would generate a stub file using clj-easy stub or manually


Or just add this namespace to the excludes in the unresolved var linter


Oh that wouldn't work for cljs, hm.


Yeah, but you can apply a similar trick. Emit the list of files to a clj file in your kondo dir and then use that in the hook


Hm, I'd like to avoid the manual sync step. Because in the end I could just evaluate the macro and paste the results back in the original file.


That will be the most robust solution and will work for both kondo and cursive


BTW, The stub doesn't work, because the two namespaces are named the same (e.g. foo/icons.clj , foo/icons.cljs). The vars now live inside the foo/icons.clj while they're used from foo/icons.cljs. It seems like clj-kondo correctly looks at the CLJS file but other parts of the tooling is not.


Hm, putting the literal defs (via eval/replace) into the clj file actually works, but I think it shouldn't?


why shouldn't it?


The CLJS compiler isn't happy about that. If you have two namespaces with the same name, only macros make it automatically across, from CLJ->CLJS. So if from say nosco/login.cljs you require nosco.icons and you use nosco.icons/check , the check var has to be placed in nosco/icons.cljs, not nosco/icons.clj


Whereas clj-kondo doesn't complain about undeclared vars no matter where the var is.


then why don't you emit this to a .cljs file?


Oh I did now, just flagging this as something that surprised me on behalf of clj-kondo's behaviour. Interestingly, if I do the exact same via a stub it doesn't seem to work.


I will probably need to start with a clean project and troubleshoot.


cool yeah, clj-kondo might be a little bit erring on the side of false negatives here


one very simple solution is to use declare, in case the icons don't keep varying much it's easy to automate, and makes it work with every tool, example:


MegaLinter works great for my deps.edn file, although it uses an older version of clj-kondo and throwing a few errors about very new configs. I'm trying to encourage the I've also created a