This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-12-23
Channels
- # adventofcode (21)
- # announcements (4)
- # babashka (35)
- # beginners (36)
- # calva (76)
- # cider (16)
- # clj-kondo (24)
- # clj-on-windows (12)
- # clojure (70)
- # clojure-europe (7)
- # clojure-nl (13)
- # clojure-spec (3)
- # clojure-uk (3)
- # clojurescript (34)
- # conjure (11)
- # cursive (22)
- # datomic (30)
- # deps-new (2)
- # emacs (36)
- # fulcro (28)
- # gratitude (4)
- # honeysql (16)
- # hugsql (8)
- # introduce-yourself (6)
- # jobs (1)
- # malli (4)
- # missionary (6)
- # off-topic (129)
- # other-languages (34)
- # polylith (3)
- # reagent (9)
- # reitit (27)
- # releases (13)
- # remote-jobs (1)
- # reveal (1)
- # shadow-cljs (2)
- # tools-build (3)
- # tools-deps (18)
- # web-security (7)
- # xtdb (4)
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.
Is this relevant? https://clojure-lsp.io/settings/#stub-generation
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.
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?
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
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.
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: https://github.com/fulcrologic/fulcro/blob/develop/src/main/com/fulcrologic/fulcro/dom.cljs#L17-L30
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 https://github.com/megalinter/megalinter/pull/1119 I've also created a https://github.com/megalinter/megalinter/pull/1126