Fork me on GitHub
#rewrite-clj
<
2021-04-03
>
ericdallo18:04:53

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

ericdallo19:04:46

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

ericdallo19:04:23

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

lread19:04:02

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.

ericdallo19:04:08

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

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

ericdallo19:04:18

@U04V15CAJ may know better how to achieve that 🙂

ericdallo19:04:28

he helped me achieving that with state-flow lib

borkdude19:04:06

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

ericdallo19:04:49

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

lread19:04:52

huh, that seems odd.

lread19:04:31

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

lread19:04:59

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

👀 3
lread19:04:44

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

ericdallo19:04:58

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

ericdallo19:04:18

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

lread19:04:41

Ah… maybe.

lread19:04:58

There is a macro to select zipper implementation.

lread19:04:37

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

ericdallo19:04:47

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

lread19:04:56

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

ericdallo19:04:08

I see, good to know, let me try it

lread19:04:48

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

ericdallo19:04:48

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

lread19:04:58

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

👍 3
lread19:04:00

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.

ericdallo19:04:32

it makes sense, thanks for the support @lee!

lread19:04:13

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

👏 3
lread19:04:46

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

ericdallo19:04:42

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

ericdallo19:04:19

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

lread19:04:26

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

ericdallo19:04:27

it's your call 🙂

ericdallo19:04:23

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

lread19:04:45

Aha! So it would help!

ericdallo19:04:57

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

ericdallo19:04:17

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

lread19:04:23

cool, thanks!

lread19:04:56

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

ericdallo20:04:08

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 😄

borkdude20:04:25

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

lread20:04:28

I’m sold!

❤️ 3
borkdude20:04:09

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

👍 6