rewrite-clj 2021-03-21

FYI: when I click on ** on the docs, it points to nothing

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

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

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

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

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

Sorry for the false alarm

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,

yeah, it makes sense!

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

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 "{}")

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

For example:

(z/tag (z/edn {})) => :unknown

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

Another way to create an empty map node:

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

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

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

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

user=> (n/tag 32)
:unknown

I see, cool

thank you again ๐Ÿ™‚

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

๐Ÿ‘ 1

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

๐Ÿ‘‹ 1

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

gโ€™night!

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

Awesome, very exciting!

1
๐Ÿš€ 1

@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 :)

Oh my, I just know the assoc one, thank you @borkdude Is should tried that one facepalm

It has also update, update-in

oh, got it

@borkdude Is that suppose to work?

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

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

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

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

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

oh, you are right, my bad

so complete example:

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

feel free to add this to the docs

it worked like a charm ๐Ÿ™‚

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

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

I can manually add the \n like I was doing

feel free to create an issue + fix if necessary

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

I should have known that lib before implement it all manually facepalm

I was like facepalm when I started this lib, because I discovered there wasn't one yet ;P

haha yeah I imagined that

Is this supposed to work?

(-> (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:
(-> (z/of-string "{}")
    z/node
    (r/assoc-in [:lint-as 'foo] 'bar))

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

that should work

this test gives the same exception:

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

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

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

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

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

feel free to look if you can

ok, I will now

๐Ÿ™Œ 1

Fixed in 0.0.2

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

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

๐Ÿ‘ 1

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

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

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

thank you!!