rewrite-clj

https://github.com/clj-commons/rewrite-clj
NoahTheDuke 2020-10-20T14:02:54.050700Z

thank you, i'm trying that out now

NoahTheDuke 2020-10-20T15:27:19.051100Z

that got me on the right path, thank you

NoahTheDuke 2020-10-20T15:28:14.051700Z

my next issue is trying to create a new map node and then insert values into it from the surrounding node

NoahTheDuke 2020-10-20T15:29:12.052800Z

i have maps that have a :choices key that is sometimes a list or vector, and I'd like to wrap it in a map. from :choices existing-list to something like :choices {:buttons existing-list}

NoahTheDuke 2020-10-20T15:30:26.053500Z

(n/map-node) seems to work to create the node, but then I can't use z/assoc to insert key value pairs

NoahTheDuke 2020-10-20T15:30:53.053700Z

throws an "rewrite_clj.node.seq.SeqNode cannot be cast to clojure.lang.IFn" error

NoahTheDuke 2020-10-20T15:31:06.053900Z

any suggestions?

borkdude 2020-10-20T18:12:43.054600Z

@nbtheduke Sometimes I find it easier to just use the raw nodes instead of zippers, so I grab the :children and manually rewrite them and assoc them back in

NoahTheDuke 2020-10-20T18:14:58.055Z

huh, okay. i'll see if i can figure out how to do that. thanks

borkdude 2020-10-20T18:17:18.055300Z

@nbtheduke This is the primary approach when writing clj-kondo hooks: https://github.com/borkdude/clj-kondo/blob/master/doc/hooks.md

borkdude 2020-10-20T18:21:16.055800Z

Thanks btw, I didn't know about z/assoc

NoahTheDuke 2020-10-20T18:24:58.057100Z

ha there isn't a lot of documentation, so i've just been poring over the generated docs and trying things out. my code looks wack, so this is all great info

borkdude 2020-10-20T18:29:57.057500Z

@nbtheduke if it helps, here's also a lib I made for rewriting config files: https://github.com/borkdude/rewrite-edn

borkdude 2020-10-20T18:30:14.058Z

it's still pretty young and maybe incomplete

borkdude 2020-10-20T18:30:32.058500Z

but it should make things easier than working directly with rewrite-clj if you only need to assoc or update-in etc

NoahTheDuke 2020-10-20T18:32:55.059400Z

nice! did you implement maintaining whitespace as well? your examples look like it

NoahTheDuke 2020-10-20T18:32:57.059600Z

that's very cool

borkdude 2020-10-20T18:33:07.059900Z

yeah, it uses rewrite-clj under the hood