rewrite-clj

https://github.com/clj-commons/rewrite-clj
2019-05-31T09:31:11.005800Z

@borkdude @lee i've put together the sample discussed before (https://clojurians.zulipchat.com/#narrow/stream/180378-slack-archive/topic/rewrite-clj/near/165811770): https://github.com/sogaiu/adorn -- the focus was on getting something working, so as far as functionality is concerned, there is as yet nothing beyond applying the inline def transformation, but there are sample wrappers for atom, emacs, and vscode. on a possibly related note, i noticed: https://github.com/borkdude/clj-kondo/issues/145#issuecomment-490905418 and wonder if there is a possible fit.

borkdude 2019-05-31T09:42:00.006700Z

@sogaiu interesting, curious to see how that plays out.

lread 2019-05-31T13:13:04.009300Z

@sogaiu, kudos to you for not only trying this idea out, but also presenting it so well!

2019-05-31T22:02:34.010400Z

thanks. just hoping some improvement to the situation can come about.

2019-05-31T22:04:47.012600Z

@lee i was trying to remove metadata and had some difficulties initially. it appears that (at least in some cases) even if one replaces a metadata node with a node for the contained form (w/o the metadata map), the metadata is retained -- presumably because the contained form has the metadata living on it.

2019-05-31T22:05:02.012900Z

will post some example code

2019-05-31T22:05:21.013200Z

given:

(require '[rewrite-clj.zip :as rz])

  (def comment-form-with-meta-idea-str
    (str "(comment\n"
         "\n"
         "  ^{:ael/expected 0 :ael/name \"simple subtraction\"}\n"
         "  (- 1 1)\n"
         ")\n"))

2019-05-31T22:06:01.013700Z

the following retains the metadata:

(-> (rz/of-string comment-form-with-meta-idea-str)
      (rz/prewalk (fn [zloc]
                    (when (= (rz/tag zloc) :meta)
                      (let [map-zloc (rz/down zloc)]
                        (contains? (rz/sexpr map-zloc)
                                   :ael/expected))))
                  (fn [zloc]
                    (-> zloc
                        rz/down
                        rz/right)))
      rz/string)

2019-05-31T22:06:35.014200Z

the following successfully removes the metadata:

(-> (rz/of-string comment-form-with-meta-idea-str)
      (rz/prewalk (fn [zloc]
                    (when (= (rz/tag zloc) :meta)
                      (let [map-zloc (rz/down zloc)]
                        (contains? (rz/sexpr map-zloc)
                                   :ael/expected))))
                  (fn [zloc]
                    (rz/edit zloc
                             (fn [expr]
                               (with-meta expr {})))))
      rz/string)

2019-05-31T22:09:19.015200Z

i was surprised, but do you think the current behavior makes sense / is inevitable?

lread 2019-05-31T22:12:51.016800Z

Thanks @sogaiu, I shall have a look sometime over the next few days.

2019-05-31T22:13:56.017Z

thanks!