rewrite-clj

https://github.com/clj-commons/rewrite-clj
ericdallo 2021-03-21T00:38:35.070200Z

FYI: when I click on *<https://cljdoc.org/d/rewrite-clj/rewrite-clj/1.0.594-alpha/doc/design/merging-rewrite-clj-and-rewrite-cljs|Merging rewrite-clj and rewrite-cljs>* on the docs, it points to nothing

lread 2021-03-22T19:36:20.095700Z

I fixed the missing title bug over at cljdoc, so should be less confusing now.

ericdallo 2021-03-22T19:37:14.095900Z

Nice!

lread 2021-03-21T01:31:28.072100Z

Thanks, from the change log? Seems to work for me, but Iโ€™ll check for any broken links tomorrow.

lread 2021-03-21T01:36:46.073500Z

Thatโ€™s weird, for me it links to my design doc.

lread 2021-03-21T01:37:43.074600Z

might be confusing as cljdoc does not currently show doc titles for adoc files?

lread 2021-03-21T01:38:36.075800Z

when you say โ€œpoints to nothingโ€ do you mean 404 or something else?

ericdallo 2021-03-21T01:48:42.076Z

Oh sorry, I thought it was an anchor error, but it's correct ๐Ÿ˜…

ericdallo 2021-03-21T01:48:54.076200Z

Sorry for the false alarm

lread 2021-03-21T01:50:54.078200Z

Hey, I appreciate you sharing your confusion, Iโ€™m sure you wonโ€™t be the only one. Maybe Iโ€™ll go fix that missing doc title bug over at cljdoc,

ericdallo 2021-03-21T01:52:21.078400Z

yeah, it makes sense!

ericdallo 2021-03-21T01:53:48.079900Z

It could look a dumb question, but, how can I create a zipper from a empty map? I can create with: (z/of-string "{:foo 1}") that return a :map tag correctly, but no with (z/of-string "{}")

borkdude 2021-03-21T08:30:44.084300Z

@ericdallo if you need to update the :lint-as map in config.edn you can also use r/assoc-in from https://github.com/borkdude/rewrite-edn :)

ericdallo 2021-03-21T12:53:07.084700Z

Oh my, I just know the assoc one, thank you @borkdude Is should tried that one ๐Ÿคฆ

borkdude 2021-03-21T12:53:32.084900Z

It has also update, update-in

ericdallo 2021-03-21T12:57:27.085100Z

I can't find those on docs though https://cljdoc.org/d/rewrite-clj/rewrite-clj/1.0.594-alpha/api/rewrite-clj.zip

borkdude 2021-03-21T12:57:56.085400Z

https://github.com/borkdude/rewrite-edn rewrite-edn, not rewrite-clj

ericdallo 2021-03-21T12:58:03.085800Z

oh, got it

ericdallo 2021-03-21T13:49:27.086Z

@borkdude Is that suppose to work?

(-&gt; (z/of-string "{:foo {bar asd}}")
    (r/assoc-in [:foo 'bar] 'asd))

ericdallo 2021-03-21T13:49:53.086200Z

or r only accept its own nodes, not rewrite-clj ones?

ericdallo 2021-03-21T13:50:36.086400Z

oh, yeah, it needs to use its own parse-string

borkdude 2021-03-21T13:51:07.086700Z

not really, you need to pass it rewrite-clj nodes, not zippers

borkdude 2021-03-21T13:51:32.086900Z

so (r/assoc-in (z/node ...) [:foo 'baz] 'asd)

ericdallo 2021-03-21T13:51:34.087100Z

oh, you are right, my bad

borkdude 2021-03-21T13:52:07.087300Z

so complete example:

(z/replace zloc (r/assoc-in (z/node ...) [:foo 'baz] 'asd))

borkdude 2021-03-21T13:52:17.087500Z

feel free to add this to the docs

ericdallo 2021-03-21T13:52:40.087700Z

it worked like a charm ๐Ÿ™‚

ericdallo 2021-03-21T13:53:00.087900Z

your one line lib call replaced my 60+ lines ๐Ÿ˜†

borkdude 2021-03-21T13:53:12.088100Z

:)

ericdallo 2021-03-21T13:53:13.088300Z

I just realized that it don't add a newline on the end of the node

ericdallo 2021-03-21T13:53:41.088600Z

I can manually add the \n like I was doing

borkdude 2021-03-21T13:53:45.088800Z

should it?

borkdude 2021-03-21T13:54:00.089Z

feel free to create an issue + fix if necessary

ericdallo 2021-03-21T13:54:02.089200Z

Yeah, I don't know, it's just a FYI if you think it should haha

ericdallo 2021-03-21T13:54:14.089400Z

๐Ÿ™‚

ericdallo 2021-03-21T13:55:00.089600Z

I should have known that lib before implement it all manually ๐Ÿคฆ

borkdude 2021-03-21T13:56:39.089800Z

I was like ๐Ÿคฆ when I started this lib, because I discovered there wasn't one yet ;P

ericdallo 2021-03-21T13:59:08.090Z

haha yeah I imagined that

ericdallo 2021-03-21T14:01:26.090200Z

Is this supposed to work?

(-&gt; (z/of-string "{:a 1}")
    z/node
    (r/assoc-in [:lint-as 'foo] 'bar))
it gives a No implementation of method: :tag of protocol: #'rewrite-clj.node.protocols/Node found for class: nil but this works:
(-&gt; (z/of-string "{}")
    z/node
    (r/assoc-in [:lint-as 'foo] 'bar))

ericdallo 2021-03-21T14:06:26.090900Z

I could repro with a test on rewrite-edn ๐Ÿ™‚ I can try to fix it

borkdude 2021-03-21T14:19:45.091100Z

that should work

ericdallo 2021-03-21T14:23:57.091300Z

this test gives the same exception:

(is (= "{:a {:b 2} :d 3}"
         (str (r/assoc-in (r/parse-string "{:d 3}")
                          [:a :b] 2))))

borkdude 2021-03-21T14:24:49.091700Z

weird!

ericdallo 2021-03-21T14:25:36.091900Z

the issue seems to be this nil arg: https://github.com/borkdude/rewrite-edn/blob/master/src/borkdude/rewrite_edn/impl.cljc#L101

ericdallo 2021-03-21T14:29:15.092200Z

the same happens with update-in , so it seems to be a bug indeed as assoc-in use update-in

borkdude 2021-03-21T14:30:37.092500Z

confirmed. user=> (r/assoc-in (r/parse-string "{:a 1}") [:b :c] 1) Execution error (IllegalArgumentException) at rewrite-clj.node.protocols/eval230$fn$G (protocols.cljc:9). No implementation of method: :tag of protocol: #'rewrite-clj.node.protocols/Node found for class: nil

borkdude 2021-03-21T14:30:51.092700Z

shall I take a look, or are you looking into it already?

ericdallo 2021-03-21T14:31:12.092900Z

I'm looking, but I'm kind of lost ๐Ÿ˜†

ericdallo 2021-03-21T14:31:20.093100Z

feel free to look if you can

borkdude 2021-03-21T14:31:56.093300Z

ok, I will now

๐Ÿ™Œ 1
borkdude 2021-03-21T14:36:31.093600Z

found it

1
borkdude 2021-03-21T14:40:18.093900Z

Fixed in 0.0.2

ericdallo 2021-03-21T14:40:38.094100Z

uow, really fast! I'll give a try right now

borkdude 2021-03-21T14:41:05.094300Z

I think this lib also needs to support namespaced maps, I'll look into that now

๐Ÿ‘ 1
borkdude 2021-03-21T14:42:11.094600Z

this namespaced prefix stuff in clojure has made tooling more complex, not sure if it was worth it

ericdallo 2021-03-21T14:43:02.094800Z

Yeah ๐Ÿ˜• it'd be util and cool. but it doesn't seems a priority IMO

borkdude 2021-03-21T15:45:17.095200Z

I had a small stab at namespaced maps, but it's more work than I expected, so I will go back to fixing some clj-kondo issues. PR for the above thing is welcome

๐Ÿ‘ 1
ericdallo 2021-03-21T15:48:11.095500Z

thank you!!

ericdallo 2021-03-21T01:54:01.080Z

same result with z/edn , not sure I'm missing something

ericdallo 2021-03-21T01:55:08.080300Z

For example:

(z/tag (z/edn {})) =&gt; :unknown

ericdallo 2021-03-21T01:55:57.080500Z

Oh, (z/tag (z/of-string "{}")) it's returning :map now, for some reason I thought seeing returning unknown as well :thinking_face:

lread 2021-03-21T01:58:49.080700Z

Another way to create an empty map node:

user=&gt; (require '[rewrite-clj.node :as n])
nil
user=&gt; (-&gt; (n/map-node []) n/string)
"{}"

ericdallo 2021-03-21T02:00:00.080900Z

But I can't convert that to zip, right? My case is that I need to create a empty {} and assoc things with rewrite-clj later

lread 2021-03-21T02:01:05.081100Z

you can insert/replace/whatever that node into a zipper, ya.

lread 2021-03-21T02:02:13.081300Z

when you see :unkown for tag you are looking at something that is not a rewrite-clj node:

user=&gt; (n/tag 32)
:unknown

ericdallo 2021-03-21T02:02:53.081500Z

I see, cool

ericdallo 2021-03-21T02:02:56.081700Z

thank you again ๐Ÿ™‚

lread 2021-03-21T02:03:03.081900Z

A rewrite-clj zipper is just a tree of rewrite-clj nodes that also tracks location.

๐Ÿ‘ 1
lread 2021-03-21T02:03:30.082100Z

You are most welcome, gonna call it a day! Have a good night!

๐Ÿ‘‹ 1
ericdallo 2021-03-21T02:05:28.082900Z

Yes!

lread 2021-03-21T02:05:44.083100Z

And please feel free to ask any questions, itโ€™ll help me to improve the docs.

lread 2021-03-21T02:06:02.083300Z

gโ€™night!

ericdallo 2021-03-21T02:06:29.083500Z

Thank you! For now rewrite-clj is just working great! I'm heavily relying to update clj-kondo config from clojure-lsp side

lread 2021-03-21T02:07:02.083900Z

Awesome, very exciting!

1
๐Ÿš€ 1