Fork me on GitHub
#clj-kondo
<
2023-10-11
>
cjohansen18:10:19

I have a ClojureScript library that defines a macro in src/portfolio/react.clj , and some cljs functions in src/portfolio/react.cljs. People typically use it like so: (require [portfolio.react :refer-macros [defscene]]) (code is here btw: https://github.com/cjohansen/portfolio/blob/main/src/portfolio/react.clj / https://github.com/cjohansen/portfolio/blob/main/src/portfolio/react.cljs). The macro has optional parts, but can look like this:

(d/defcomponent SideEffecty
  :key value
  ,,,
  [data]
  [:h1])
Is there any way I can provide some config, metadata or other in the library that will help clj-kondo understand this macro in projects that depend on the library? Ideally it'd understand both that SideEffecty is being defined, and that data is a binding.

borkdude19:10:24

Yep. On phone right now but take a look at lint-as + catch-all in the config.md docs

borkdude19:10:55

The other option for recognizing the binding requires a hook, see hooks.md

cjohansen21:10:32

Cool, thanks. Can I ship these with the library somehow? If it's covered in the docs I'll find it 😅

cjohansen20:10:34

Very cool 🙏 Thanks again, and sorry for not responding - I overstretched a little 😅

Sam Ritchie15:10:39

You can also remove the refer-macros requirement -

Sam Ritchie15:10:49

And then your users can use :refer or just the alias from require without treating the macro in a special way

cjohansen17:10:12

Wow, interesting. Am I understanding this right, that the cljs-part of the cljc-file will effectively be merged with the same-named cljs file?

Sam Ritchie17:10:28

@U9MKYDN4Q sorry my example here is slightly confusing — in this case I am using a single cljc file instead of separate clj and cljs files

Sam Ritchie17:10:40

so for your example you would have to add that form to your cljs file only