Hey @lee have you considered adding clj-kondo hooks in the rewrite-clj lib via the https://github.com/clj-kondo/clj-kondo/blob/master/doc/config.md#exporting-and-importing-configuration? This way projects that use rewrite-clj would have the hook auto imported with just a :config-paths
configuration in its clj-kondo config edn
Example https://github.com/nubank/state-flow/tree/master/resources/clj-kondo.exports/nubank/state-flow
Not sure if you already did that or use rewrite-clj hooks manually, is just that I searched on the main branch and didn't find any existing hook
I'm saying that because clojure-lsp, clj-kondo etc would benefit of this without the need of add custom hooks manually 😅
I did have a need for https://github.com/lread/rewrite-cljc-playground/commit/09882e1244a8c12879ef8c1e6872724748e7914b when I was using a custom internal version of import-vars, but I’ve no longer any need for that. But, I guessing that you are only referring to exporting config. This is a clj-kondo feature that I was somehow not aware of 😲. I’ll read up.
yes! with that users would just need to add something like:
:config-paths ["clojure-commons/rewrite-clj"]
@borkdude may know better how to achieve that 🙂
he helped me achieving that with state-flow lib
does rewrite need any config for its users? it's only functions, no macros right?
there’s a handful of macros. https://github.com/clj-commons/rewrite-clj/blob/main/.clj-kondo/config.edn
yeah, I get a lot of unresolved-var for some functions
huh, that seems odd.
oh, actually I think this is another issue: https://github.com/clj-kondo/clj-kondo/issues/1143
I mean I would get those when I used potemkin import-vars… before I wrote my clj-kondo hooks.
but rewrite-clj doesn’t use potemkin import-vars anymore
But if some project is using rewrite-clj v0, or rewrite-cljc, you might(?) see those.
so, the only ns I get those is from rewrite-clj.custom-zipper.core
Hmmm…
that code is quite old, so not sure if I should use something newer
Ah… maybe.
There is a macro to select zipper implementation.
But… custom-zipper-core is an internal ns. You could use *
variants instead. Like next*
instead of next
etc.
we actually use: insert-left
, insert-right
and append-child
So instead of rewrite-clj.custom-zipper.core/append-child
you’d use rewrite-clj.zip/append-child*
I see, good to know, let me try it
I think you’ll find you’ll have extreme success!
Yeah, I just saw in the code it just call the internal custom-zipper ns 🙂
nice!
I’ve seen this often in code. Rewrite-clj v0 docs were not very clear on the *
variants.
But if you are using anything https://cljdoc.org/d/rewrite-clj/rewrite-clj/1.0.605-alpha/doc/user-guide#_rewrite_clj_apis, lemme know. Often-times code is unnecessarily using internals.
it makes sense, thanks for the support @lee!
Anytime! I raised an issue about a https://github.com/clj-kondo/clj-kondo/issues/1197 which might help with this kind of thing.
So would exporting the rewrite-clj clj-kondo config be helpful to anyone? Maybe for the macros?
yes, if there are macros/hooks you use on rewrite-clj, they would be helpful exporting the config
actually if the macros are only on internal ns, that would be that necessary
No hooks anymore, just macros. Ok, I’ll raise an issue as a reminder to actually do it!
it's your call 🙂
oh, yeah, I forgot about the lint-as macros clojure-lsp has configured for rewrite-clj:
:lint-as {rewrite-clj.zip/edit-> clojure.core/->
rewrite-clj.zip/edit->> clojure.core/->>
rewrite-clj.zip/subedit-> clojure.core/->
rewrite-clj.zip/subedit->> clojure.core/->>
rewrite-clj.zip.subedit/edit-> clojure.core/->
rewrite-clj.zip.subedit/subedit-> clojure.core/->}
Aha! So it would help!
yeah, that's a good reason to add to clj-kondo export 🙂
then users would need only the :config-paths instead of all that lint-as config
cool, thanks!
I’ll make a point to remember to update user guide too.
this is a really good change IMO as if rewrite-clj create new macros in the future, they would automatically be included on next releases and users would not need to change their :lint-as
config 😄
aha. if rewrite-clj has macros (which I didn't know about) I would have expected some tests to fail (if those macros are used in those tests) since I assumed I was only hooking up normal functions so far
I’m sold!
(I'll talk about bb rewrite-clj to lread in person as to not conflate two issues here)