diff --git a/.gitignore b/.gitignore index 5deb08e..c07ec82 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ git .lein-failures .cache .lsp +.nrepl-port diff --git a/CHANGELOG.md b/CHANGELOG.md index 4941bd8..4654632 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ [rewrite-clj](https://github.com/clj-commons/rewrite-clj) with common operations to update EDN while preserving whitespace and comments. +## 0.4.6 + +- [#33](https://github.com/borkdude/rewrite-edn/issues/33): fix `assoc` on map starting with comment + ## 0.4.5 - Add `conj`: `(str (r/update (r/parse-string "{:a [1 2 3]}") :a r/conj 1)) ;;=> "{:a [1 2 3 1]}"` ([@zerg000000](https://github.com/zerg000000)) diff --git a/project.clj b/project.clj index abba127..0a669e9 100644 --- a/project.clj +++ b/project.clj @@ -1,4 +1,4 @@ -(defproject borkdude/rewrite-edn "0.4.5" +(defproject borkdude/rewrite-edn "0.4.6" :description "Rewrite EDN" :url "https://github.com/borkdude/rewrite-edn" :scm {:name "git" diff --git a/script/changelog.clj b/script/changelog.clj new file mode 100755 index 0000000..2a31109 --- /dev/null +++ b/script/changelog.clj @@ -0,0 +1,17 @@ +#!/usr/bin/env bb + +(ns changelog + (:require [clojure.string :as str])) + +(let [changelog (slurp "CHANGELOG.md") + replaced (str/replace changelog + #" #(\d+)" + (fn [[_ issue after]] + (format " [#%s](https://github.com/borkdude/rewrite-edn/issues/%s)%s" + issue issue (str after)))) + replaced (str/replace replaced + #"@([a-zA-Z0-9-_]+)([, \.)])" + (fn [[_ name after]] + (format "[@%s](https://github.com/%s)%s" + name name after)))] + (spit "CHANGELOG.md" replaced)) diff --git a/src/borkdude/rewrite_edn/impl.cljc b/src/borkdude/rewrite_edn/impl.cljc index a6da14c..ef0bbfb 100644 --- a/src/borkdude/rewrite_edn/impl.cljc +++ b/src/borkdude/rewrite_edn/impl.cljc @@ -53,10 +53,9 @@ zloc (if nil? (z/replace zloc (node/coerce {})) zloc) - children (:children (z/node zloc)) length (count-uncommented-children zloc) out-of-bounds? (and (= :vector tag) (>= k length)) - empty? (or nil? (zero? (count children)))] + empty? (or nil? (zero? length))] (cond empty? (-> zloc diff --git a/test/borkdude/rewrite_edn_test.cljc b/test/borkdude/rewrite_edn_test.cljc index ea01677..781d7cc 100644 --- a/test/borkdude/rewrite_edn_test.cljc +++ b/test/borkdude/rewrite_edn_test.cljc @@ -70,6 +70,13 @@ (is (= (str "{:a 2\n" " :b 3}") (-> "{}" + r/parse-string + (r/assoc :a 2) + (r/assoc :b 3) + str)))) + (testing "Assoc on map with comment" + (is (= "{;;a comment\n :a 2\n :b 3}" + (-> "{;;a comment\n}" r/parse-string (r/assoc :a 2) (r/assoc :b 3)