rewrite-clj

https://github.com/clj-commons/rewrite-clj
ericdallo 2021-04-03T18:59:53.182Z

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

ericdallo 2021-04-03T19:00:46.182300Z

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

ericdallo 2021-04-03T19:01:23.182500Z

I'm saying that because clojure-lsp, clj-kondo etc would benefit of this without the need of add custom hooks manually 😅

lread 2021-04-03T19:31:02.182800Z

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.

ericdallo 2021-04-03T19:32:08.183Z

yes! with that users would just need to add something like:

:config-paths ["clojure-commons/rewrite-clj"]

ericdallo 2021-04-03T19:32:18.183200Z

@borkdude may know better how to achieve that 🙂

ericdallo 2021-04-03T19:32:28.183400Z

he helped me achieving that with state-flow lib

borkdude 2021-04-03T19:37:06.183600Z

does rewrite need any config for its users? it's only functions, no macros right?

lread 2021-04-03T19:38:41.183900Z

there’s a handful of macros. https://github.com/clj-commons/rewrite-clj/blob/main/.clj-kondo/config.edn

ericdallo 2021-04-03T19:39:49.184300Z

yeah, I get a lot of unresolved-var for some functions

lread 2021-04-03T19:40:52.184700Z

huh, that seems odd.

ericdallo 2021-04-03T19:41:08.184900Z

oh, actually I think this is another issue: https://github.com/clj-kondo/clj-kondo/issues/1143

lread 2021-04-03T19:41:31.185300Z

I mean I would get those when I used potemkin import-vars… before I wrote my clj-kondo hooks.

lread 2021-04-03T19:41:59.185500Z

but rewrite-clj doesn’t use potemkin import-vars anymore

👀 1
lread 2021-04-03T19:43:44.186Z

But if some project is using rewrite-clj v0, or rewrite-cljc, you might(?) see those.

ericdallo 2021-04-03T19:44:58.186200Z

so, the only ns I get those is from rewrite-clj.custom-zipper.core

lread 2021-04-03T19:45:08.186400Z

Hmmm…

ericdallo 2021-04-03T19:45:18.186600Z

that code is quite old, so not sure if I should use something newer

lread 2021-04-03T19:45:41.186800Z

Ah… maybe.

lread 2021-04-03T19:45:58.187Z

There is a macro to select zipper implementation.

lread 2021-04-03T19:46:37.187200Z

But… custom-zipper-core is an internal ns. You could use * variants instead. Like next* instead of next etc.

ericdallo 2021-04-03T19:47:47.187400Z

we actually use: insert-left, insert-right and append-child

lread 2021-04-03T19:47:56.187600Z

So instead of rewrite-clj.custom-zipper.core/append-child you’d use rewrite-clj.zip/append-child*

ericdallo 2021-04-03T19:48:08.187800Z

I see, good to know, let me try it

lread 2021-04-03T19:48:48.188Z

I think you’ll find you’ll have extreme success!

ericdallo 2021-04-03T19:49:48.188300Z

Yeah, I just saw in the code it just call the internal custom-zipper ns 🙂

ericdallo 2021-04-03T19:49:50.188500Z

nice!

lread 2021-04-03T19:50:58.188700Z

I’ve seen this often in code. Rewrite-clj v0 docs were not very clear on the * variants.

👍 1
lread 2021-04-03T19:52:00.189Z

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.

ericdallo 2021-04-03T19:52:32.189400Z

it makes sense, thanks for the support @lee!

lread 2021-04-03T19:53:13.189600Z

Anytime! I raised an issue about a https://github.com/clj-kondo/clj-kondo/issues/1197 which might help with this kind of thing.

👏 1
lread 2021-04-03T19:54:46.190100Z

So would exporting the rewrite-clj clj-kondo config be helpful to anyone? Maybe for the macros?

ericdallo 2021-04-03T19:55:42.190300Z

yes, if there are macros/hooks you use on rewrite-clj, they would be helpful exporting the config

ericdallo 2021-04-03T19:56:19.190500Z

actually if the macros are only on internal ns, that would be that necessary

lread 2021-04-03T19:56:26.190700Z

No hooks anymore, just macros. Ok, I’ll raise an issue as a reminder to actually do it!

ericdallo 2021-04-03T19:56:27.190900Z

it's your call 🙂

ericdallo 2021-04-03T19:58:23.191100Z

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/->}

lread 2021-04-03T19:58:45.191300Z

Aha! So it would help!

ericdallo 2021-04-03T19:58:57.191500Z

yeah, that's a good reason to add to clj-kondo export 🙂

ericdallo 2021-04-03T19:59:17.191700Z

then users would need only the :config-paths instead of all that lint-as config

lread 2021-04-03T19:59:23.191900Z

cool, thanks!

lread 2021-04-03T19:59:56.192100Z

I’ll make a point to remember to update user guide too.

ericdallo 2021-04-03T20:00:08.192300Z

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 😄

borkdude 2021-04-03T20:00:25.192500Z

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

lread 2021-04-03T20:00:28.192700Z

I’m sold!

❤️ 1
borkdude 2021-04-03T20:01:09.193100Z

(I'll talk about bb rewrite-clj to lread in person as to not conflate two issues here)

👍 2